Skip to content

Commit 95e5cd4

Browse files
committed
Added AutoFixture xunit sample
1 parent 6d1d46f commit 95e5cd4

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

Diff for: AutoFixtureXUnit/AutoFixtureXUnit.csproj

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="AutoFixture" Version="4.17.0" />
13+
<PackageReference Include="AutoFixture.Xunit2" Version="4.17.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
15+
<PackageReference Include="xunit" Version="2.4.1" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="3.1.2">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
</Project>

Diff for: AutoFixtureXUnit/AutoFixtureXUnit.sln

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoFixtureXUnit", "AutoFixtureXUnit.csproj", "{1657D714-BBF6-466C-83D1-9040C130634F}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{1657D714-BBF6-466C-83D1-9040C130634F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{1657D714-BBF6-466C-83D1-9040C130634F}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{1657D714-BBF6-466C-83D1-9040C130634F}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{1657D714-BBF6-466C-83D1-9040C130634F}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

Diff for: AutoFixtureXUnit/UnitTests.cs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Diagnostics;
2+
using AutoFixture.Xunit2;
3+
4+
namespace AutoFixtureXUnit;
5+
6+
public class UnitTest1
7+
{
8+
[Theory]
9+
[AutoData]
10+
public void TestOne(string name)
11+
{
12+
var sut = new MyFooService();
13+
14+
var result = sut.MyCall(name);
15+
16+
Assert.NotNull(result);
17+
}
18+
19+
[Theory]
20+
[InlineAutoData]
21+
[InlineAutoData(31)]
22+
[InlineAutoData(31, "Steven")]
23+
public void TestTwo(int age, string name)
24+
{
25+
var sut = new MyFooService();
26+
27+
var result = sut.MyCall(name, age);
28+
29+
Assert.NotNull(result);
30+
}
31+
32+
[Theory]
33+
[InlineAutoData]
34+
public void TestThree(string name, MyFooService sut)
35+
{
36+
var result = sut.MyCall(name);
37+
38+
Assert.NotNull(result);
39+
}
40+
41+
}
42+
43+
public class MyFooService
44+
{
45+
public string MyCall(string name) => name;
46+
public string MyCall(string name, int age) => name + age;
47+
}

Diff for: AutoFixtureXUnit/Usings.cs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Xunit;

Diff for: WebAppFactory/WebAppFactory.Tests/FeatureOneTests.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net.Http.Json;
2+
using Microsoft.AspNetCore.Hosting;
23
using Microsoft.AspNetCore.Mvc.Testing;
34
using Xunit;
45

@@ -10,6 +11,10 @@ public class FeatureOneTests : IClassFixture<WebApplicationFactory<Program>>
1011

1112
public FeatureOneTests(WebApplicationFactory<Program> factory)
1213
{
14+
factory.WithWebHostBuilder(builder =>
15+
{
16+
builder.UseEnvironment("Development");
17+
});
1318
client = factory.CreateClient();
1419
}
1520

0 commit comments

Comments
 (0)