Skip to content

Commit ea27fe4

Browse files
authored
test: migrate xunit to v3 (#88)
1 parent 7c4ce2a commit ea27fe4

File tree

89 files changed

+881
-402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+881
-402
lines changed

Directory.Build.props

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
<Project>
2-
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
4-
<ImplicitUsings>enable</ImplicitUsings>
5-
<Nullable>enable</Nullable>
6-
</PropertyGroup>
7-
8-
<PropertyGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
9-
<IsPackable>false</IsPackable>
10-
</PropertyGroup>
11-
12-
<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
13-
<Using Include="Xunit"/>
14-
<Using Include="Shouldly"/>
15-
</ItemGroup>
16-
17-
<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
18-
<PackageReference Include="NSubstitute" />
19-
<PackageReference Include="Shouldly" />
20-
<PackageReference Include="coverlet.collector">
21-
<PrivateAssets>all</PrivateAssets>
22-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23-
</PackageReference>
24-
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
25-
<PackageReference Include="xunit" />
26-
<PackageReference Include="xunit.runner.visualstudio">
27-
<PrivateAssets>all</PrivateAssets>
28-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
29-
</PackageReference>
30-
</ItemGroup>
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
<PropertyGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
11+
<Using Include="Xunit" />
12+
<Using Include="Shouldly" />
13+
</ItemGroup>
14+
<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
15+
<PackageReference Include="NSubstitute" />
16+
<PackageReference Include="Shouldly" />
17+
<PackageReference Include="coverlet.collector">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" />
22+
<PackageReference Include="xunit.v3" />
23+
<PackageReference Include="xunit.runner.visualstudio">
24+
<PrivateAssets>all</PrivateAssets>
25+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
26+
</PackageReference>
27+
</ItemGroup>
3128
</Project>

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<PackageVersion Include="Shouldly" Version="4.3.0"/>
4040
<PackageVersion Include="coverlet.collector" Version="6.0.4"/>
4141
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
42-
<PackageVersion Include="xunit" Version="2.9.3"/>
43-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2">
42+
<PackageVersion Include="xunit.v3" Version="2.0.2" />
43+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0">
4444
<PrivateAssets>all</PrivateAssets>
4545
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4646
</PackageVersion>

test/Adapters/Driven/Analysis.Instance.Docker.Tests/CalculationInstanceDockerAdapterTest.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using ScriptBee.Domain.Model.Instance;
88
using ScriptBee.Domain.Model.Project;
99
using ScriptBee.Tests.Common;
10-
using Xunit.Abstractions;
1110

1211
namespace ScriptBee.Analysis.Instance.Docker.Tests;
1312

@@ -53,12 +52,17 @@ public async Task Allocate_ShouldCreateAndStartContainerAndReturnUrlWithNetworkI
5352
var instanceId = new InstanceId(Guid.NewGuid());
5453
var image = new AnalysisInstanceImage(DockerFixture.TestImageName);
5554

56-
var containerUrl = await _calculationInstanceDockerAdapter.Allocate(instanceId, image);
55+
var containerUrl = await _calculationInstanceDockerAdapter.Allocate(
56+
instanceId,
57+
image,
58+
TestContext.Current.CancellationToken
59+
);
5760

5861
containerUrl.ShouldStartWith("http://");
5962
containerUrl.ShouldContain($":{_testPort}");
6063
var containers = await _dockerFixture.DockerClient.Containers.ListContainersAsync(
61-
new ContainersListParameters { All = true }
64+
new ContainersListParameters { All = true },
65+
TestContext.Current.CancellationToken
6266
);
6367
var ourContainer = containers.FirstOrDefault(c =>
6468
c.Names.Contains($"/scriptbee-calculation-{instanceId}")
@@ -80,7 +84,11 @@ public async Task Allocate_ShouldUseConfiguredNetworkAndContainerName()
8084
var instanceId = new InstanceId(Guid.NewGuid());
8185
var image = new AnalysisInstanceImage(DockerFixture.TestImageName);
8286

83-
await _calculationInstanceDockerAdapter.Allocate(instanceId, image);
87+
await _calculationInstanceDockerAdapter.Allocate(
88+
instanceId,
89+
image,
90+
TestContext.Current.CancellationToken
91+
);
8492

8593
var containers = await _dockerFixture.DockerClient.Containers.ListContainersAsync(
8694
new ContainersListParameters
@@ -96,7 +104,8 @@ public async Task Allocate_ShouldUseConfiguredNetworkAndContainerName()
96104
}
97105
},
98106
},
99-
}
107+
},
108+
TestContext.Current.CancellationToken
100109
);
101110
containers.ShouldHaveSingleItem();
102111
containers.First().Names.ShouldContain($"/scriptbee-calculation-{instanceId}");
@@ -113,7 +122,8 @@ public async Task Deallocate_ShouldStopAndRemoveExistingContainer()
113122

114123
var instanceUrl = await _calculationInstanceDockerAdapter.Allocate(
115124
instanceId,
116-
instanceImage
125+
instanceImage,
126+
TestContext.Current.CancellationToken
117127
);
118128
instanceUrl.ShouldStartWith("http://");
119129
var instanceInfo = new InstanceInfo(
@@ -138,7 +148,8 @@ public async Task Deallocate_ShouldStopAndRemoveExistingContainer()
138148
new Dictionary<string, bool> { { containerName, true } }
139149
},
140150
},
141-
}
151+
},
152+
TestContext.Current.CancellationToken
142153
);
143154
containers.ShouldBeEmpty();
144155
}

test/Adapters/Driven/Analysis.Instance.Docker.Tests/DockerFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public class DockerFixture : IAsyncLifetime
1111

1212
public readonly DockerClient DockerClient = new DockerClientConfiguration().CreateClient();
1313

14-
public async Task InitializeAsync()
14+
public async ValueTask InitializeAsync()
1515
{
1616
await EnsureNetworkExists();
1717

1818
await PullTestImageIfNotExists();
1919
}
2020

21-
public async Task DisposeAsync()
21+
public async ValueTask DisposeAsync()
2222
{
2323
var containers = await DockerClient.Containers.ListContainersAsync(
2424
new ContainersListParameters

test/Adapters/Driven/Persistence.File.Tests/CreateFileAdapterTest.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ public async Task CreateFileSuccessfully()
4040
.GetPathToUserFolder(pathToFileInSrcFolder)
4141
.Returns("path/to/user/folder/file.txt");
4242

43-
var result = await _createFileAdapter.Create(projectId, pathToFileTxt, "content");
43+
var result = await _createFileAdapter.Create(
44+
projectId,
45+
pathToFileTxt,
46+
"content",
47+
TestContext.Current.CancellationToken
48+
);
4449

4550
result.AsT0.ShouldBe(
4651
new CreateFileResult("file.txt", pathToFileTxt, "path/to/user/folder/file.txt")
4752
);
48-
(await System.IO.File.ReadAllTextAsync(pathToFileInSrcFolder)).ShouldBe("content");
53+
(
54+
await System.IO.File.ReadAllTextAsync(
55+
pathToFileInSrcFolder,
56+
TestContext.Current.CancellationToken
57+
)
58+
).ShouldBe("content");
4959
}
5060

5161
[Fact]
@@ -57,9 +67,18 @@ public async Task CreateFileAlreadyExists()
5767
_configFoldersService
5868
.GetPathToSrcFolder(projectId, pathToFileTxt)
5969
.Returns(pathToFileInSrcFolder);
60-
await System.IO.File.WriteAllTextAsync(pathToFileInSrcFolder, "test");
70+
await System.IO.File.WriteAllTextAsync(
71+
pathToFileInSrcFolder,
72+
"test",
73+
TestContext.Current.CancellationToken
74+
);
6175

62-
var result = await _createFileAdapter.Create(projectId, pathToFileTxt, "content");
76+
var result = await _createFileAdapter.Create(
77+
projectId,
78+
pathToFileTxt,
79+
"content",
80+
TestContext.Current.CancellationToken
81+
);
6382

6483
result.AsT1.ShouldBe(new FileAlreadyExistsError(pathToFileTxt));
6584
}

test/Adapters/Driven/Persistence.File.Tests/FilePathAttribute.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/Adapters/Driven/Persistence.File.Tests/LoadFileAdapterTest.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ public async Task GetContentSuccessfully()
3636
_configFoldersService
3737
.GetPathToSrcFolder(projectId, pathToFileTxt)
3838
.Returns(pathToFileInSrcFolder);
39-
await System.IO.File.WriteAllTextAsync(pathToFileInSrcFolder, "content");
39+
await System.IO.File.WriteAllTextAsync(
40+
pathToFileInSrcFolder,
41+
"content",
42+
TestContext.Current.CancellationToken
43+
);
4044

41-
var result = await _loadFileAdapter.GetScriptContent(projectId, pathToFileTxt);
45+
var result = await _loadFileAdapter.GetScriptContent(
46+
projectId,
47+
pathToFileTxt,
48+
TestContext.Current.CancellationToken
49+
);
4250

4351
result.AsT0.ShouldBe("content");
4452
}
@@ -53,7 +61,11 @@ public async Task GivenFileDoesNotExists_GetContent_ThenFileDoesNotExistsErrorIs
5361
.GetPathToSrcFolder(projectId, pathToFileTxt)
5462
.Returns(pathToFileInSrcFolder);
5563

56-
var result = await _loadFileAdapter.GetScriptContent(projectId, pathToFileTxt);
64+
var result = await _loadFileAdapter.GetScriptContent(
65+
projectId,
66+
pathToFileTxt,
67+
TestContext.Current.CancellationToken
68+
);
5769

5870
result.AsT1.ShouldBe(new FileDoesNotExistsError(pathToFileTxt));
5971
}

0 commit comments

Comments
 (0)