Skip to content

Commit

Permalink
Merge pull request #893 from Cysharp/feature/xunit.v3
Browse files Browse the repository at this point in the history
Migrate to xUnit v3
  • Loading branch information
mayuki authored Jan 8, 2025
2 parents 930a53a + acc1ca4 commit aedf3e5
Show file tree
Hide file tree
Showing 52 changed files with 356 additions and 360 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
<!-- for tests -->
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
<PackageVersion Include="FluentAssertions" Version="6.7.0" />
<PackageVersion Include="FluentAssertions" Version="8.0.0-rc.2" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="NSubstitute" Version="5.0.0" />
<PackageVersion Include="Testcontainers" Version="2.3.0" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="xunit.v3" Version="1.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
</ItemGroup>
<!-- for samples/perf -->
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task ResponseHeadersAsync_Ctor_ResponseContext()
public async Task ResponseHeadersAsync_Never_Ctor_ResponseContext()
{
var result = new UnaryResult(Task.FromResult<IResponseContext<Nil>>(new DummyResponseContext<Nil>(new TaskCompletionSource<Nil>())));
await Assert.ThrowsAsync<TimeoutException>(async () => await result.ResponseHeadersAsync.WaitAsync(TimeSpan.FromMilliseconds(250)));
await Assert.ThrowsAsync<TimeoutException>(async () => await result.ResponseHeadersAsync.WaitAsync(TimeSpan.FromMilliseconds(250), TestContext.Current.CancellationToken));
}

[Fact]
Expand All @@ -90,14 +90,14 @@ public async Task ResponseAsync_Ctor_ResponseContext()
public async Task ResponseAsync_Never_Ctor_Task()
{
var result = new UnaryResult(new TaskCompletionSource<Nil>().Task);
await Assert.ThrowsAsync<TimeoutException>(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250)));
await Assert.ThrowsAsync<TimeoutException>(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250), TestContext.Current.CancellationToken));
}

[Fact]
public async Task ResponseAsync_Never_Ctor_ResponseContext()
{
var result = new UnaryResult(Task.FromResult<IResponseContext<Nil>>(new DummyResponseContext<Nil>(new TaskCompletionSource<Nil>())));
await Assert.ThrowsAsync<TimeoutException>(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250)));
await Assert.ThrowsAsync<TimeoutException>(async () => await result.ResponseAsync.WaitAsync(TimeSpan.FromMilliseconds(250), TestContext.Current.CancellationToken));
}

static class DummyResponseContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ namespace MyNamespace
public class MyClass { }
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "MyClass", SymbolFilter.Type).OfType<INamedTypeSymbol>().ToArray();
var symbols = compilation.GetSymbolsWithName(x => x == "MyClass", SymbolFilter.Type, TestContext.Current.CancellationToken).OfType<INamedTypeSymbol>().ToArray();

// Act
var typeInfo = MagicOnionTypeInfo.CreateFromSymbol(symbols[0]);
Expand All @@ -279,7 +279,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down Expand Up @@ -307,7 +307,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down Expand Up @@ -337,7 +337,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down Expand Up @@ -365,7 +365,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down Expand Up @@ -393,7 +393,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand All @@ -419,7 +419,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand All @@ -443,7 +443,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand All @@ -467,7 +467,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand All @@ -493,7 +493,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand All @@ -517,7 +517,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down Expand Up @@ -547,7 +547,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down Expand Up @@ -577,7 +577,7 @@ public class MyClass
}
}
");
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member)
var symbols = compilation.GetSymbolsWithName(x => x == "FieldA", SymbolFilter.Member, TestContext.Current.CancellationToken)
.OfType<IFieldSymbol>()
.ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using MessagePack;
using Microsoft.CodeAnalysis;
using System.Collections.Immutable;
using Xunit.Abstractions;

namespace MagicOnion.Client.SourceGenerator.Tests.Collector;

Expand Down Expand Up @@ -38,7 +37,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -78,7 +77,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().BeEmpty();
Expand Down Expand Up @@ -110,7 +109,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].RequestType.Should().Be(MagicOnionTypeInfo.CreateFromType<Nil>());
serviceCollection.Services[0].Methods[0].ResponseType.Should().Be(MagicOnionTypeInfo.CreateFromType<Nil>());
serviceCollection.Services[0].Methods[0].MethodReturnType.Should().Be(MagicOnionTypeInfo.CreateFromType<UnaryResult>());
Expand Down Expand Up @@ -142,7 +141,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].RequestType.Should().Be(MagicOnionTypeInfo.CreateFromType<Tuple<bool, long>[]>());
serviceCollection.Services[0].Methods[0].ResponseType.Should().Be(MagicOnionTypeInfo.CreateFromType<Tuple<int, string>[]>());
serviceCollection.Services[0].Methods[0].MethodReturnType.Should().Be(MagicOnionTypeInfo.CreateFromType<UnaryResult<Tuple<int, string>[]>>());
Expand Down Expand Up @@ -174,7 +173,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].RequestType.Should().Be(MagicOnionTypeInfo.CreateFromType<Tuple<bool?, long?>>());
serviceCollection.Services[0].Methods[0].ResponseType.Should().Be(MagicOnionTypeInfo.CreateFromType<int?>());
serviceCollection.Services[0].Methods[0].MethodReturnType.Should().Be(MagicOnionTypeInfo.CreateFromType<UnaryResult<int?>>());
Expand Down Expand Up @@ -206,7 +205,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -248,7 +247,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -289,7 +288,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -331,7 +330,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -374,7 +373,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Services[0].Methods[0].Parameters[0].Type.Should().Be(MagicOnionTypeInfo.CreateFromType<string>());
serviceCollection.Services[0].Methods[0].Parameters[0].HasExplicitDefaultValue.Should().BeTrue();
serviceCollection.Services[0].Methods[0].Parameters[0].DefaultValue.Should().Be("\"Hello\"");
Expand Down Expand Up @@ -418,7 +417,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -571,7 +570,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -611,7 +610,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -652,7 +651,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -725,7 +724,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down Expand Up @@ -794,7 +793,7 @@ public interface IMyService : IService<IMyService>
var (serviceCollection, diagnostics) = MethodCollector.Collect(interfaceSymbols, referenceSymbols, CancellationToken.None);

// Assert
compilation.GetDiagnostics().Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
compilation.GetDiagnostics(TestContext.Current.CancellationToken).Should().NotContain(x => x.Severity == DiagnosticSeverity.Error);
serviceCollection.Should().NotBeNull();
serviceCollection.Hubs.Should().BeEmpty();
serviceCollection.Services.Should().HaveCount(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using MagicOnion.Client.SourceGenerator.CodeAnalysis;
using Xunit.Abstractions;

namespace MagicOnion.Client.SourceGenerator.Tests.Collector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="FluentAssertions" />
<PackageReference Include="MemoryPack" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading

0 comments on commit aedf3e5

Please sign in to comment.