Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Added scraping Unit Test for #20
Browse files Browse the repository at this point in the history
  • Loading branch information
cdemi committed Oct 13, 2018
1 parent 89813e0 commit 769e6f2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NewsletterCurator.HTMLScraper\NewsletterCurator.HTMLScraper.csproj" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions NewsletterCurator.HTMLScraper.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NewsletterCurator.HTMLScraper.Tests
{
[TestClass]
public class UnitTests
{
private readonly HttpClient httpClient;

public UnitTests()
{
httpClient = new HttpClient(new HttpClientHandler
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.None
});
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36");
httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
httpClient.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.9");


}

[TestMethod]
public async Task ScrapeCdemiBlog()
{
var scraperService = new HTMLScraperService(httpClient);
var urlMetaData = await scraperService.Scrape("https://blog.cdemi.io/whats-coming-in-c-8-0-nullable-reference-types/?src=NewsletterCuratorTest");

Assert.AreEqual(urlMetaData.CanonicalURL, "https://blog.cdemi.io/whats-coming-in-c-8-0-nullable-reference-types/");
Assert.AreEqual(urlMetaData.Images.Count, 2);
Assert.AreEqual(urlMetaData.Summary, "One of the features being discussed for introduction in C# 8.0 is Nullable Reference Types. A proficient C# Developer might say \"What?! Aren't all reference types nullable?\" ");
Assert.AreEqual(urlMetaData.Title, "What's Coming in C# 8.0? Nullable Reference Types");
}
}
}
6 changes: 6 additions & 0 deletions NewsletterCurator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsletterCurator.Data.SqlS
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsletterCurator.HTMLScraper", "NewsletterCurator.HTMLScraper\NewsletterCurator.HTMLScraper.csproj", "{F3D9D261-91B4-4B2B-B62E-CA696F141F4B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsletterCurator.HTMLScraper.Tests", "NewsletterCurator.HTMLScraper.Tests\NewsletterCurator.HTMLScraper.Tests.csproj", "{31F35EE2-DB0B-4301-B000-AE1D09C6BF55}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,6 +44,10 @@ Global
{F3D9D261-91B4-4B2B-B62E-CA696F141F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3D9D261-91B4-4B2B-B62E-CA696F141F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3D9D261-91B4-4B2B-B62E-CA696F141F4B}.Release|Any CPU.Build.0 = Release|Any CPU
{31F35EE2-DB0B-4301-B000-AE1D09C6BF55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31F35EE2-DB0B-4301-B000-AE1D09C6BF55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31F35EE2-DB0B-4301-B000-AE1D09C6BF55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31F35EE2-DB0B-4301-B000-AE1D09C6BF55}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 7 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ variables:

steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: dotnet build
displayName: dotnet build
- script: dotnet test NewsletterCurator.HTMLScraper.Tests --configuration $(buildConfiguration) --logger trx
displayName: dotnet test
- script: dotnet publish --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)
displayName: dotnet publish
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
- task: PublishBuildArtifacts@1
displayName: Publishing Artifacts

0 comments on commit 769e6f2

Please sign in to comment.