Skip to content

Commit 2d95dd1

Browse files
committed
Add tests
1 parent 269c095 commit 2d95dd1

4 files changed

Lines changed: 120 additions & 3 deletions

File tree

Nullforce.Api.Derpibooru.JsonModels.sln

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nullforce.Api.Derpibooru.Js
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{2EAAEB07-0805-456A-BBEF-68E1AEA4E2C7}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullforce.Api.Derpibooru.JsonModel.Tests", "tests\Nullforce.Api.Derpibooru.JsonModel.Tests\Nullforce.Api.Derpibooru.JsonModel.Tests.csproj", "{04539D26-C3CE-4310-8B7A-B86F837DBD52}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -19,8 +21,6 @@ Global
1921
Release|x86 = Release|x86
2022
EndGlobalSection
2123
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22-
{2EAAEB07-0805-456A-BBEF-68E1AEA4E2C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23-
{2EAAEB07-0805-456A-BBEF-68E1AEA4E2C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
2424
{E589723A-CA82-4B48-9049-3135C3859F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2525
{E589723A-CA82-4B48-9049-3135C3859F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
2626
{E589723A-CA82-4B48-9049-3135C3859F91}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -33,6 +33,18 @@ Global
3333
{E589723A-CA82-4B48-9049-3135C3859F91}.Release|x64.Build.0 = Release|Any CPU
3434
{E589723A-CA82-4B48-9049-3135C3859F91}.Release|x86.ActiveCfg = Release|Any CPU
3535
{E589723A-CA82-4B48-9049-3135C3859F91}.Release|x86.Build.0 = Release|Any CPU
36+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Debug|x64.ActiveCfg = Debug|Any CPU
39+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Debug|x64.Build.0 = Debug|Any CPU
40+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Debug|x86.ActiveCfg = Debug|Any CPU
41+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Debug|x86.Build.0 = Debug|Any CPU
42+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Release|x64.ActiveCfg = Release|Any CPU
45+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Release|x64.Build.0 = Release|Any CPU
46+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Release|x86.ActiveCfg = Release|Any CPU
47+
{04539D26-C3CE-4310-8B7A-B86F837DBD52}.Release|x86.Build.0 = Release|Any CPU
3648
EndGlobalSection
3749
GlobalSection(SolutionProperties) = preSolution
3850
HideSolutionNode = FALSE

build/Build.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,31 @@ class Build : NukeBuild
6363
DotNetBuild(s => s
6464
.SetProjectFile(Solution)
6565
.SetConfiguration(Configuration)
66-
.SetOutputDirectory(OutputDirectory)
6766
.SetProperty("PackageVersion", GitVersion.NuGetVersionV2)
6867
.SetInformationalVersion(GitVersion.InformationalVersion)
6968
.EnableNoRestore());
7069
});
7170

71+
Target Test => _ => _
72+
.DependsOn(Compile)
73+
.Executes(() =>
74+
{
75+
var testProjects = GlobFiles(TestsDirectory, "**/*.csproj");
76+
77+
foreach (var testProject in testProjects)
78+
{
79+
DotNetTest(s => s
80+
.SetProjectFile(testProject)
81+
.SetConfiguration(Configuration)
82+
.EnableNoBuild()
83+
);
84+
}
85+
});
86+
7287
Target Publish => _ => _
88+
.DependsOn(Clean)
7389
.DependsOn(Compile)
90+
.DependsOn(Test)
7491
.Executes(() =>
7592
{
7693
if (!IsLocalBuild && string.IsNullOrEmpty(NugetApiKey))
@@ -79,6 +96,14 @@ class Build : NukeBuild
7996
return;
8097
}
8198

99+
DotNetPack(s => s
100+
.SetConfiguration(Configuration)
101+
.SetOutputDirectory(OutputDirectory)
102+
.SetProperty("PackageVersion", GitVersion.NuGetVersionV2)
103+
.SetInformationalVersion(GitVersion.InformationalVersion)
104+
.EnableNoBuild()
105+
);
106+
82107
var nugetPackage = GlobFiles(OutputDirectory, "*.nupkg").First();
83108

84109
DotNetNuGetPush(s => s
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using FluentAssertions;
4+
using Flurl;
5+
using Flurl.Http;
6+
using Nullforce.Api.Derpibooru.JsonModels;
7+
using Xunit;
8+
9+
namespace Nullforce.Api.Derpibooru.JsonModel.Tests
10+
{
11+
public class UnitTest1
12+
{
13+
[Fact]
14+
public void ImagesRoot_GetJson_SuccessWithoutExceptions()
15+
{
16+
var uri = "https://derpibooru.org/images.json";
17+
ImagesRootJson imagesResult = null;
18+
19+
Func<Task> act = async () =>
20+
{
21+
imagesResult = await uri.GetJsonAsync<ImagesRootJson>();
22+
};
23+
24+
act.Should().NotThrow();
25+
imagesResult.Should().NotBeNull();
26+
}
27+
28+
[Fact]
29+
public void ListsRoot_GetJson_SuccessWithoutExceptions()
30+
{
31+
var uri = "https://derpibooru.org/lists.json";
32+
ListsRootJson listsResult = null;
33+
34+
Func<Task> act = async () =>
35+
{
36+
listsResult = await uri.GetJsonAsync<ListsRootJson>();
37+
};
38+
39+
act.Should().NotThrow();
40+
listsResult.Should().NotBeNull();
41+
}
42+
43+
[Fact]
44+
public void SearchRoot_GetJson_SuccessWithoutExceptions()
45+
{
46+
var uri = "https://derpibooru.org/search.json";
47+
uri = uri.SetQueryParam("q", "fluttershy");
48+
SearchRootJson searchResult = null;
49+
50+
Func<Task> act = async () =>
51+
{
52+
searchResult = await uri.GetJsonAsync<SearchRootJson>();
53+
};
54+
55+
act.Should().NotThrow();
56+
searchResult.Should().NotBeNull();
57+
}
58+
}
59+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="FluentAssertions" Version="5.6.0" />
11+
<PackageReference Include="Flurl.Http" Version="2.4.2" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
13+
<PackageReference Include="xunit" Version="2.4.0" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\src\Nullforce.Api.Derpibooru.JsonModels.csproj" />
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)