Skip to content

Commit f7e189d

Browse files
authored
Tunit (#432)
1 parent 5b72b5a commit f7e189d

File tree

102 files changed

+2854
-2781
lines changed

Some content is hidden

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

102 files changed

+2854
-2781
lines changed

contributing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ partial class PolyfillTests
386386
var memory = new Memory<char>(result);
387387
using var reader = new StreamReader(stream);
388388
var read = await reader.ReadAsync(memory);
389-
Assert.AreEqual(5, read);
390-
Assert.IsTrue("value".SequenceEqual(result));
389+
await Assert.That(read).IsEqualTo(5);
390+
await Assert.That("value".SequenceEqual(result)).IsTrue();
391391
}
392392

393393
[Test]
@@ -396,7 +396,7 @@ partial class PolyfillTests
396396
using var stream = new MemoryStream("value"u8.ToArray());
397397
using var reader = new StreamReader(stream);
398398
var read = await reader.ReadToEndAsync(Cancel.None);
399-
Assert.AreEqual("value", read);
399+
await Assert.That(read).IsEqualTo("value");
400400
}
401401

402402
[Test]
@@ -405,7 +405,7 @@ partial class PolyfillTests
405405
using var stream = new MemoryStream("line1\nline2"u8.ToArray());
406406
using var reader = new StreamReader(stream);
407407
var read = await reader.ReadLineAsync(Cancel.None);
408-
Assert.AreEqual("line1", read);
408+
await Assert.That(read).IsEqualTo("line1");
409409
}
410410
}
411411
```

readme.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ Reference: [Module Initializers](https://learn.microsoft.com/en-us/dotnet/csharp
9696
static bool InitCalled;
9797

9898
[Test]
99-
public void ModuleInitTest() =>
100-
Assert.True(InitCalled);
99+
public async Task ModuleInitTest() =>
100+
await Assert.That(InitCalled).IsTrue();
101101

102102
[ModuleInitializer]
103103
public static void ModuleInit() =>
104104
InitCalled = true;
105105
```
106-
<sup><a href='/src/Tests/ModuleInitSample.cs#L4-L16' title='Snippet source file'>snippet source</a> | <a href='#snippet-ModuleInitializerAttribute' title='Start of snippet'>anchor</a></sup>
106+
<sup><a href='/src/Tests/ModuleInitSample.cs#L3-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-ModuleInitializerAttribute' title='Start of snippet'>anchor</a></sup>
107107
<!-- endSnippet -->
108108

109109

@@ -225,25 +225,24 @@ If consuming in a project that targets net461 or net462, a reference to System.V
225225
<!-- snippet: IndexRange -->
226226
<a id='snippet-IndexRange'></a>
227227
```cs
228-
[TestFixture]
229228
class IndexRangeSample
230229
{
231230
[Test]
232-
public void Range()
231+
public async Task Range()
233232
{
234233
var substring = "value"[2..];
235-
Assert.AreEqual("lue", substring);
234+
await Assert.That(substring).IsEqualTo("lue");
236235
}
237236

238237
[Test]
239-
public void Index()
238+
public async Task Index()
240239
{
241240
var ch = "value"[^2];
242-
Assert.AreEqual('u', ch);
241+
await Assert.That(ch).IsEqualTo('u');
243242
}
244243

245244
[Test]
246-
public void ArrayIndex()
245+
public async Task ArrayIndex()
247246
{
248247
var array = new[]
249248
{
@@ -253,11 +252,11 @@ class IndexRangeSample
253252

254253
var value = array[^2];
255254

256-
Assert.AreEqual("value1", value);
255+
await Assert.That(value).IsEqualTo("value1");
257256
}
258257
}
259258
```
260-
<sup><a href='/src/Tests/IndexRangeSample.cs#L1-L35' title='Snippet source file'>snippet source</a> | <a href='#snippet-IndexRange' title='Start of snippet'>anchor</a></sup>
259+
<sup><a href='/src/Tests/IndexRangeSample.cs#L1-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-IndexRange' title='Start of snippet'>anchor</a></sup>
261260
<!-- endSnippet -->
262261

263262

@@ -278,15 +277,15 @@ class IndexRangeSample
278277
<!-- snippet: OverloadResolutionPriority -->
279278
<a id='snippet-OverloadResolutionPriority'></a>
280279
```cs
281-
[TestFixture]
282280
public class OverloadResolutionPriorityAttributeTests
283281
{
284282
[Test]
285-
public void Run()
283+
public Task Run()
286284
{
287285
int[] arr = [1, 2, 3];
288286
//Prints "Span" because resolution priority is higher
289287
Method(arr);
288+
return Task.CompletedTask;
290289
}
291290

292291
[OverloadResolutionPriority(2)]
@@ -1487,7 +1486,7 @@ class NullabilityTarget
14871486
<a id='snippet-NullabilityUsage'></a>
14881487
```cs
14891488
[Test]
1490-
public void Test()
1489+
public async Task Test()
14911490
{
14921491
var type = typeof(NullabilityTarget);
14931492
var arrayField = type.GetField("ArrayField")!;
@@ -1497,14 +1496,14 @@ public void Test()
14971496

14981497
var arrayInfo = context.Create(arrayField);
14991498

1500-
Assert.AreEqual(NullabilityState.NotNull, arrayInfo.ReadState);
1501-
Assert.AreEqual(NullabilityState.Nullable, arrayInfo.ElementType!.ReadState);
1499+
await Assert.That(arrayInfo.ReadState).IsEqualTo(NullabilityState.NotNull);
1500+
await Assert.That(arrayInfo.ElementType!.ReadState).IsEqualTo(NullabilityState.Nullable);
15021501

15031502
var genericInfo = context.Create(genericField);
15041503

1505-
Assert.AreEqual(NullabilityState.NotNull, genericInfo.ReadState);
1506-
Assert.AreEqual(NullabilityState.NotNull, genericInfo.GenericTypeArguments[0].ReadState);
1507-
Assert.AreEqual(NullabilityState.Nullable, genericInfo.GenericTypeArguments[1].ReadState);
1504+
await Assert.That(genericInfo.ReadState).IsEqualTo(NullabilityState.NotNull);
1505+
await Assert.That(genericInfo.GenericTypeArguments[0].ReadState).IsEqualTo(NullabilityState.NotNull);
1506+
await Assert.That(genericInfo.GenericTypeArguments[1].ReadState).IsEqualTo(NullabilityState.Nullable);
15081507
}
15091508
```
15101509
<sup><a href='/src/Tests/NullabilitySamples.cs#L6-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-NullabilityUsage' title='Start of snippet'>anchor</a></sup>

src/ApiBuilderTests/ApiBuilderTests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
34
<TargetFramework>net10.0</TargetFramework>
45
</PropertyGroup>
56
<ItemGroup>
67
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
7-
<PackageReference Include="NUnit" />
8-
<PackageReference Include="NUnit3TestAdapter" />
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
8+
<PackageReference Include="TUnit" />
109
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
1110
<PackageReference Include="ProjectFiles" />
1211
</ItemGroup>

src/ApiBuilderTests/BuildApiTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using ProjectFilesGenerator;
22

3-
[TestFixture]
43
public class BuildApiTest
54
{
65
static string polyfillDir = Path.Combine(ProjectFiles.SolutionDirectory, "Polyfill");
76

87
[Test]
9-
public void RunWithRoslyn()
8+
public Task RunWithRoslyn()
109
{
1110
var md = Path.Combine(ProjectFiles.SolutionDirectory, "..", "api_list.include.md");
1211
File.Delete(md);
@@ -29,6 +28,7 @@ public void RunWithRoslyn()
2928
var countMd = Path.Combine(ProjectFiles.SolutionDirectory, "..", "apiCount.include.md");
3029
File.Delete(countMd);
3130
File.WriteAllText(countMd, $"**API count: {count}**");
31+
return Task.CompletedTask;
3232
}
3333

3434
static int WriteExtensions(StreamWriter writer, int count)

src/ApiBuilderTests/GlobalUsings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
global using NUnit.Framework;
1+
global using TUnit.Core;
2+
global using TUnit.Assertions;
3+
global using TUnit.Assertions.Extensions;
24
global using System;
35
global using System.Diagnostics.CodeAnalysis;
46
global using Microsoft.CodeAnalysis;

src/ConsumeOnlyTasks/ConsumeOnlyTasks.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="System.Threading.Tasks.Extensions" />
9-
</ItemGroup>
10-
<ItemGroup>
119
<Compile Include="..\Consume\*.cs" />
1210
</ItemGroup>
1311
<Import Project="$(SolutionDir)\TestIncludes.targets" />

src/Directory.Packages.props

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
<ItemGroup>
77
<PackageVersion Include="MarkdownSnippets.MsBuild" Version="28.0.0-beta.8" />
88
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" Pinned="true" />
9-
<!-- keep at 17.14.1 -->
10-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" Pinned="true" />
11-
<PackageVersion Include="NUnit" Version="3.14.0" Pinned="true" />
12-
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" Pinned="true" />
9+
<PackageVersion Include="TUnit" Version="1.5.53" />
1310
<PackageVersion Include="ProjectDefaults" Version="1.0.163" />
1411
<PackageVersion Include="Microsoft.Bcl.Memory" Version="10.0.1" />
1512
<PackageVersion Include="ProjectFiles" Version="0.2.0" />

src/EmbeddedTests/EmbeddedTests.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<NoWarn>$(NoWarn);PolyfillTargetsForNuget</NoWarn>
4+
<OutputType>Exe</OutputType>
45
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net472;net48</TargetFrameworks>
56
<TargetFrameworks>$(TargetFrameworks);netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
67
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
78
</PropertyGroup>
89
<ItemGroup>
910
<Compile Include="..\Tests\*.cs" />
11+
<PackageReference Include="TUnit" />
1012
<PackageReference Include="ProjectFiles" />
11-
<PackageReference Include="NUnit" />
12-
<PackageReference Include="NUnit3TestAdapter" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1413
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
1514
<PackageReference Include="System.Memory" Condition="$(TargetFramework) != '.NETStandard' or $(TargetFrameworkIdentifier) == '.NETFramework' or $(TargetFramework.StartsWith('netcoreapp'))" />
1615
<PackageReference Include="System.ValueTuple" Condition="$(TargetFramework.StartsWith('net46'))" />
1716
<PackageReference Include="System.Net.Http" Condition="$(TargetFramework.StartsWith('net4'))" />
1817
<PackageReference Include="System.Threading.Tasks.Extensions" Condition="$(TargetFramework) == 'netstandard2.0' or $(TargetFramework) == 'netcoreapp2.0' or $(TargetFrameworkIdentifier) == '.NETFramework'" />
1918
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Condition="$(TargetFramework.StartsWith('net4'))" />
2019
<PackageReference Include="System.IO.Compression" Condition="$(TargetFrameworkIdentifier) == '.NETFramework'" />
21-
</ItemGroup>
22-
<ItemGroup>
2320
<ProjectReference Include="..\ConsumeEmbeddedLib\ConsumeEmbeddedLib.csproj" />
2421
</ItemGroup>
2522
<Import Project="$(SolutionDir)\TestIncludes.targets" />

src/NoExtrasTests/GlobalUsings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
global using NUnit.Framework;
1+
global using TUnit.Core;
2+
global using TUnit.Assertions;
3+
global using TUnit.Assertions.Extensions;

src/NoExtrasTests/NoExtrasTests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
34
<NoWarn>$(NoWarn);PolyfillTargetsForNuget</NoWarn>
45
<TargetFramework>net10.0</TargetFramework>
56
<PolyEnsure>false</PolyEnsure>
@@ -10,9 +11,7 @@
1011
<RootNamespace>NoExtras</RootNamespace>
1112
</PropertyGroup>
1213
<ItemGroup>
13-
<PackageReference Include="NUnit" />
14-
<PackageReference Include="NUnit3TestAdapter" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
14+
<PackageReference Include="TUnit" />
1615
<PackageReference Include="ProjectDefaults" PrivateAssets="all" />
1716
</ItemGroup>
1817
<Import Project="$(SolutionDir)\TestIncludes.targets" />

0 commit comments

Comments
 (0)