add Tests
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>30642924-75c6-46ac-833f-59fd44f6c3a0</ProjectGuid>
|
||||
<ProjectGuid>{21E0B36F-4829-4044-A7D4-8C27F1D16FB2}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ReadSharp.Tests</RootNamespace>
|
||||
@@ -35,7 +35,25 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Threading.Tasks">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.165\lib\net45\Microsoft.Threading.Tasks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Threading.Tasks.Extensions">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.165\lib\net45\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Extensions">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Primitives">
|
||||
<HintPath>..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="xunit">
|
||||
<HintPath>..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
@@ -50,8 +68,18 @@
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="UnitTest1.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestsBase.cs" />
|
||||
<Compile Include="ReadTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ReadSharp\ReadSharp.csproj">
|
||||
<Project>{06219cad-e85e-48e2-a216-2539805a9ee8}</Project>
|
||||
<Name>ReadSharp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
@@ -73,6 +101,11 @@
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
using ReadSharp.Models;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace ReadSharp.Tests
|
||||
{
|
||||
public class ReadTests : TestsBase
|
||||
{
|
||||
private Reader reader;
|
||||
|
||||
|
||||
public ReadTests()
|
||||
: base()
|
||||
{
|
||||
reader = new Reader();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ReadArticleTest()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("http://frontendplay.com/story/4/http-caching-demystified-part-2-implementation"));
|
||||
|
||||
Assert.DoesNotContain("<!DOCTYPE html>", result.Content);
|
||||
Assert.Contains("<h1>", result.Content);
|
||||
Assert.True(result.Content.Length > 15000);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ReadArticleWithContainerNoHeadlineTest()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("http://frontendplay.com/story/4/http-caching-demystified-part-2-implementation"), false, true);
|
||||
|
||||
Assert.Contains("<!DOCTYPE html>", result.Content);
|
||||
Assert.DoesNotContain("<h1>", result.Content);
|
||||
Assert.True(result.Content.Length > 15000);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ReadArticleWithImagesTest()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("https://hacks.mozilla.org/2013/12/application-layout-with-css3-flexible-box-module/"));
|
||||
Assert.True(result.Images.Count >= 3);
|
||||
Assert.True(result.Images[0].Uri.ToString().StartsWith("https://hacks.mozilla.org"));
|
||||
Assert.True(result.Images[1].Uri.ToString().EndsWith(".gif"));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ReadArticleWithNoImagesTest()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("http://getpocket.com/hits/awards/2013/"));
|
||||
Assert.True(result.Images == null || result.Images.Count < 1);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ReadArticleWithInvalidUriTest()
|
||||
{
|
||||
await ThrowsAsync<Exception>(async () =>
|
||||
{
|
||||
await reader.Read(new Uri("http://frontendplayyyyy.com"));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task IsBodyOnlyProperlyResolved()
|
||||
{
|
||||
Article result = await reader.Read(new Uri("http://calebjacob.com/tooltipster/"));
|
||||
|
||||
Assert.True(result.Content.Substring(0, 4) == "<div");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace ReadSharp.Tests
|
||||
{
|
||||
public class TestsBase : IDisposable
|
||||
{
|
||||
// setup
|
||||
public TestsBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// teardown
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// async throws
|
||||
public static async Task ThrowsAsync<TException>(Func<Task> func)
|
||||
{
|
||||
var expected = typeof(TException);
|
||||
Type actual = null;
|
||||
try
|
||||
{
|
||||
await func();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
actual = e.GetType();
|
||||
}
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl" version="1.1.6" targetFramework="net45" />
|
||||
<package id="Microsoft.Bcl.Async" version="1.0.165" targetFramework="net45" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net45" />
|
||||
<package id="Microsoft.Net.Http" version="2.2.18" targetFramework="net45" />
|
||||
<package id="xunit" version="1.9.2" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user