Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to xUnit 3 #1831

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
<PackageVersion Include="System.Reactive" Version="6.0.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="Testcontainers" Version="4.1.0" />
<PackageVersion Include="Verify.Xunit" Version="28.6.0" />
<PackageVersion Include="Verify.XunitV3" Version="28.6.0" />
<PackageVersion Include="Verify.MicrosoftLogging" Version="4.0.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="XunitContext" Version="3.3.2" />
<PackageVersion Include="xunit.v3" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.1'">
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="3.1.4" />
Expand Down
5 changes: 4 additions & 1 deletion test/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
[assembly: CollectionBehavior(DisableTestParallelization = true)]
using ExRam.Gremlinq.Tests.Infrastructure;

[assembly: CollectionBehavior(DisableTestParallelization = true)]
[assembly: TestFramework(typeof(GremlinqTestFramework))]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Core.AspNet\ExRam.Gremlinq.Core.AspNet.csproj" />
<ProjectReference Include="..\Tests.Infrastructure\ExRam.Gremlinq.Tests.Infrastructure.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion test/Core.Tests/Assumptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public async Task SemaphoreSlim_WaitAsync_fails_upon_cancellation()
var cts = new CancellationTokenSource();

var waitTask = semaphore.WaitAsync(cts.Token);
await Task.Delay(100);
await Task.Delay(100, TestContext.Current.CancellationToken);

waitTask.IsCompleted
.Should()
Expand Down
10 changes: 5 additions & 5 deletions test/Core.Tests/GremlinQueryExecutorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Invalid()
GremlinQueryExecutor.Invalid
.Execute<object>(GremlinQueryExecutionContext.Create(_query))
.Awaiting(ex => ex
.ToArrayAsync())
.ToArrayAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<InvalidOperationException>();
}
Expand All @@ -34,7 +34,7 @@ public async Task Empty()
{
var results = await GremlinQueryExecutor.Empty
.Execute<object>(GremlinQueryExecutionContext.Create(_query))
.ToArrayAsync();
.ToArrayAsync(TestContext.Current.CancellationToken);

results
.Should()
Expand All @@ -55,7 +55,7 @@ public async Task RetryWithExponentialBackoff()
await Verify(baseExecutor
.RetryWithExponentialBackoff((_, ex) => true)
.Execute<object>(GremlinQueryExecutionContext.Create(_query))
.ToArrayAsync());
.ToArrayAsync(TestContext.Current.CancellationToken));
}

[Fact]
Expand All @@ -79,7 +79,7 @@ await baseExecutor
})
.Execute<object>(GremlinQueryExecutionContext.Create(_query))
.Awaiting(x => x
.ToArrayAsync())
.ToArrayAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<GremlinQueryExecutionException>()
.WithInnerException<GremlinQueryExecutionException, ArrayTypeMismatchException>();
Expand Down Expand Up @@ -114,7 +114,7 @@ async IAsyncEnumerable<int> Core()
.Be(0);

yield return 42;
await Task.Delay(TimeSpan.FromMilliseconds(random.Next(5)));
await Task.Delay(TimeSpan.FromMilliseconds(random.Next(5)), TestContext.Current.CancellationToken);

Interlocked.CompareExchange(ref state, 0, 1)
.Should()
Expand Down
4 changes: 1 addition & 3 deletions test/Core.Tests/Serialization/OuterProjectionTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Runtime.CompilerServices;
using ExRam.Gremlinq.Tests.Infrastructure;

using Xunit.Abstractions;

namespace ExRam.Gremlinq.Core.Tests
{
public class OuterProjectionTest : QueryExecutionTest, IClassFixture<GremlinqFixture>
Expand All @@ -16,7 +14,7 @@ public ProjectionVerifier([CallerFilePath] string sourceFile = "") : base(source
public override Task Verify<TElement>(IGremlinQueryBase<TElement> query) => InnerVerify(query.ToTraversal().Projection.ToTraversal(query.AsAdmin().Environment).Steps.ToArray());
}

public OuterProjectionTest(GremlinqFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new ProjectionVerifier())
public OuterProjectionTest(GremlinqFixture fixture) : base(fixture, new ProjectionVerifier())
{
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<TargetFrameworks Condition="'$(Configuration)' == 'Release'">net6.0;net7.0;net8.0;$(TargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="$(ProjectName.EndsWith('Tests'))">
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" Link="AssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="xunit" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="Verify.XunitV3" />
<PackageReference Include="NSubstitute" />
</ItemGroup>

Expand Down
20 changes: 10 additions & 10 deletions test/Providers.Core.Tests/PoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Pool_creates_subClient()
await poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.MoveNextAsync();

baseFactory
Expand All @@ -55,13 +55,13 @@ public async Task Pool_creates_only_one_subClient_when_not_overlapping()
await poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.MoveNextAsync();

await poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.MoveNextAsync();

baseFactory
Expand Down Expand Up @@ -93,14 +93,14 @@ public async Task Pool_creates_second_client_when_overlapping()
poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.MoveNextAsync()
.AsTask();

poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.MoveNextAsync()
.AsTask();

Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task Pool_creates_not_more_clients_than_there_are_slots()
poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.MoveNextAsync()
.AsTask();
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public async Task Exception_is_forwarded()
await poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.Awaiting(__ => __
.MoveNextAsync())
.Should()
Expand Down Expand Up @@ -202,7 +202,7 @@ public async Task Client_is_recreated()
poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.Awaiting(__ => __
.MoveNextAsync())
.Should()
Expand Down Expand Up @@ -239,7 +239,7 @@ public async Task Retry_once_upon_ObjectDisposedException()

var result = await System.Linq.AsyncEnumerable
.ToArrayAsync(poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create()));
.SubmitAsync<int>(RequestMessage.Build("op").Create()), TestContext.Current.CancellationToken);

baseFactory
.Received(2)
Expand Down Expand Up @@ -275,7 +275,7 @@ public async Task Retry_only_once_upon_ObjectDisposedException()
poolClient
.SubmitAsync<int>(RequestMessage.Build("op").Create())
.AsAsyncEnumerable()
.GetAsyncEnumerator()
.GetAsyncEnumerator(TestContext.Current.CancellationToken)
.Awaiting(__ => __
.MoveNextAsync())
.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task No_password_bubbles_up()
{
await _g
.Inject(42)
.ToArrayAsync()
.ToArrayAsync(TestContext.Current.CancellationToken)
.Awaiting(_ => _)
.Should()
.ThrowAsync<GremlinQueryExecutionException>()
Expand Down
32 changes: 16 additions & 16 deletions test/Providers.GremlinServer.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IntegrationTests(GremlinServerContainerFixture fixture) : base(
[Fact]
public async Task FirstAsync() => (await _g
.Inject(42)
.FirstAsync())
.FirstAsync(TestContext.Current.CancellationToken))
.Should()
.Be(42);

Expand All @@ -37,29 +37,29 @@ public async Task FirstAsync_empty() => await _g
.Inject(42)
.None()
.Awaiting(_ => _
.FirstAsync())
.FirstAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<InvalidOperationException>();

[Fact]
public async Task FirstOrDefaultAsync() => (await _g
.Inject(42)
.FirstOrDefaultAsync())
.FirstOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.Be(42);

[Fact]
public async Task FirstOrDefaultAsync_empty() => (await _g
.Inject(42)
.None()
.FirstOrDefaultAsync())
.FirstOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.Be(0);

[Fact]
public async Task SingleAsync() => (await _g
.Inject(42)
.SingleAsync())
.SingleAsync(TestContext.Current.CancellationToken))
.Should()
.Be(42);

Expand All @@ -68,45 +68,45 @@ public async Task SingleAsync_empty() => await _g
.Inject(42)
.None()
.Awaiting(_ => _
.SingleAsync())
.SingleAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<InvalidOperationException>();

[Fact]
public async Task SingleAsync_two_elements() => await _g
.Inject(42, 43)
.Awaiting(_ => _
.SingleAsync())
.SingleAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<InvalidOperationException>();

[Fact]
public async Task SingleOrDefaultAsync() => (await _g
.Inject(42)
.SingleOrDefaultAsync())
.SingleOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.Be(42);

[Fact]
public async Task SingleOrDefaultAsync_empty() => (await _g
.Inject(42)
.None()
.SingleOrDefaultAsync())
.SingleOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.Be(0);

[Fact]
public async Task SingleOrDefaultAsync_two_elements() => await _g
.Inject(42, 43)
.Awaiting(_ => _
.SingleOrDefaultAsync())
.SingleOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<InvalidOperationException>();

[Fact]
public async Task LastAsync() => (await _g
.Inject(42, 43)
.LastAsync())
.LastAsync(TestContext.Current.CancellationToken))
.Should()
.Be(43);

Expand All @@ -115,22 +115,22 @@ public async Task LastAsync_empty() => await _g
.Inject(42)
.None()
.Awaiting(_ => _
.LastAsync())
.LastAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<InvalidOperationException>();

[Fact]
public async Task LastOrDefaultAsync() => (await _g
.Inject(42, 43)
.LastOrDefaultAsync())
.LastOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.Be(43);

[Fact]
public async Task LastOrDefaultAsync_empty() => (await _g
.Inject(42)
.None()
.LastOrDefaultAsync())
.LastOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.Be(0);

Expand Down Expand Up @@ -217,7 +217,7 @@ public Task TimeSpan_from_malformed_string() => _g
.Inject("abc")
.Cast<TimeSpan>()
.Awaiting(_ => _
.FirstOrDefaultAsync())
.FirstOrDefaultAsync(TestContext.Current.CancellationToken))
.Should()
.ThrowAsync<GremlinQueryExecutionException>();

Expand All @@ -242,7 +242,7 @@ public async Task Deserialization_of_typed_results_is_only_called_once()
}))))
.Inject(42)
.Cast<BinaryData>()
.FirstAsync();
.FirstAsync(TestContext.Current.CancellationToken);

result?
.ToArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Wrong_password_bubbles_up()
{
await _g
.Inject(42)
.ToArrayAsync()
.ToArrayAsync(TestContext.Current.CancellationToken)
.Awaiting(_ => _)
.Should()
.ThrowAsync<GremlinQueryExecutionException>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public GremlinServerIntegrationTests() : base(new ExecutingVerifier())
public Task Inject_sum() => Verify(_g
.Inject(1, 2, 3)
.Sum()
.FirstAsync());
.FirstAsync(TestContext.Current.CancellationToken));
}
}
2 changes: 2 additions & 0 deletions test/Templates.Tests/ExRam.Gremlinq.Templates.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<ItemGroup>
<PackageReference Include="Boxed.DotnetNewTest" />
<PackageReference Include="System.Text.Json" />

<ProjectReference Include="..\Tests.Infrastructure\ExRam.Gremlinq.Tests.Infrastructure.csproj" />
</ItemGroup>

</Project>
Loading
Loading