Skip to content

Commit 44ec0bb

Browse files
committed
Add unit test project
1 parent 365c9a2 commit 44ec0bb

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using DotNetSampleApp.Controllers;
3+
using DotNetSampleApp.Models;
4+
using DotNetSampleApp.Services;
5+
using Fauna;
6+
using Microsoft.AspNetCore.Mvc;
7+
using NUnit.Framework;
8+
9+
namespace DotNetSampleApp.Tests.Controllers;
10+
11+
[TestFixture]
12+
[TestOf(typeof(Customers))]
13+
public class CustomersTest
14+
{
15+
[AllowNull]
16+
private Client _fauna;
17+
18+
[AllowNull]
19+
private Customers _cust;
20+
21+
[OneTimeSetUp]
22+
public void Setup()
23+
{
24+
_fauna = new Client(new Configuration("secret")
25+
{
26+
Endpoint = new Uri("http://localhost:8443"),
27+
});
28+
_cust = new Customers(_fauna);
29+
30+
SeedService.Init(_fauna);
31+
}
32+
33+
[Test]
34+
public async Task GetExistingCustomerTest()
35+
{
36+
var res = await _cust.GetCustomer("999");
37+
switch (res)
38+
{
39+
case OkObjectResult r:
40+
Assert.That(r.StatusCode, Is.EqualTo(200));
41+
var customer = r.Value! as Customer;
42+
Assert.That(customer?.Id, Is.EqualTo("999"));
43+
break;
44+
default:
45+
Assert.Fail($"Unexpected result when getting existing customer: {res}");
46+
break;
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
13+
<PackageReference Include="NUnit" Version="4.2.2" />
14+
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\DotNetSampleApp\DotNetSampleApp.csproj" />
19+
</ItemGroup>
20+
21+
</Project>

SampleApp.sln

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetSampleApp", "DotNetSampleApp\DotNetSampleApp.csproj", "{9EB6EE06-4E63-4511-852E-48AA0A9EFB21}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetSampleApp.Tests", "DotNetSampleApp.Tests\DotNetSampleApp.Tests.csproj", "{9589AB7B-32EE-4079-BE5C-04F40D34E18A}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU

0 commit comments

Comments
 (0)