Skip to content

Commit

Permalink
Migrate to xunit.v3 (#17250)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored Jan 21, 2025
1 parent b25a311 commit 472378b
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 50 deletions.
11 changes: 3 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>

<PropertyGroup>
<!-- Special case - this property is used by a DotNetCliToolReference -->
<DotNetXunitVersion>2.3.0</DotNetXunitVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="AngleSharp" Version="1.2.0" />
<PackageVersion Include="AWSSDK.S3" Version="3.7.411.5" />
Expand Down Expand Up @@ -70,9 +65,9 @@
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.analyzers" Version="1.17.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit.v3" Version="1.0.0" />
<PackageVersion Include="xunit.analyzers" Version="1.18.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="YesSql" Version="5.2.0" />
<PackageVersion Include="YesSql.Abstractions" Version="5.2.0" />
<PackageVersion Include="YesSql.Core" Version="5.2.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Reflection;
using Xunit;
using Xunit.Abstractions;

namespace OrchardCore.Modules.Manifest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

namespace OrchardCore.Modules.Manifest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Reflection;
using Xunit;
using Xunit.Abstractions;

namespace OrchardCore.Modules.Manifest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using OrchardCore.DisplayManagement.Manifest;
using Xunit;
using Xunit.Abstractions;

namespace OrchardCore.Modules.Manifest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//namespace OrchardCore.Modules.Manifest
//{
// using Xunit;
// using Xunit.Abstractions;

// /// <inheritdoc/>
// public class ModuleMarkerAttributeTests : ModuleAttributeTests<ModuleMarkerAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using OrchardCore.Modules.Manifest;
using Xunit;
using Xunit.Abstractions;

namespace OrchardCore.DisplayManagement.Manifest;
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
<RootNamespace>OrchardCore</RootNamespace>
<OutputType>Exe</OutputType>
<!-- Remove the underscores from member name -->
<NoWarn>$(NoWarn);CA1707;EnableGenerateDocumentationFile</NoWarn>
</PropertyGroup>
Expand All @@ -18,10 +19,9 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.analyzers" />
<PackageReference Include="xunit.runner.visualstudio" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(DotNetXunitVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions test/OrchardCore.Benchmarks/OrchardCore.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
<RootNamespace>OrchardCore.Benchmark</RootNamespace>
<IsPackable>false</IsPackable>
<GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint>
<IsTestProject>false</IsTestProject>
<TestProject>false</TestProject>
<OutputType>Exe</OutputType>
<!-- Remove the underscores from member name -->
<NoWarn>$(NoWarn);CA1707;EnableGenerateDocumentationFile</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion test/OrchardCore.Tests/Apis/GraphQL/Blog/BlogPostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public async Task ShouldNotBeAbleToExecuteAnyQueriesWithoutPermission()

await context.InitializeAsync();

var response = await context.GraphQLClient.Client.GetAsync("api/graphql");
var response = await context.GraphQLClient.Client.GetAsync("api/graphql", TestContext.Current.CancellationToken);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ContentItemsFieldTypeTests : IAsyncLifetime
protected string _prefix;
protected string _tempFilename;

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
var connectionStringTemplate = @"Data Source={0};Cache=Shared";

Expand Down Expand Up @@ -61,7 +61,7 @@ public async Task InitializeAsync()
await CreateTablesAsync(_prefixedStore);
}

public Task DisposeAsync()
public ValueTask DisposeAsync()
{
_store.Dispose();
_store = null;
Expand Down Expand Up @@ -95,7 +95,7 @@ public Task DisposeAsync()
}
}

return Task.CompletedTask;
return ValueTask.CompletedTask;
}

private static async Task CreateTablesAsync(IStore store)
Expand Down
10 changes: 5 additions & 5 deletions test/OrchardCore.Tests/Apis/Lucene/LuceneQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task BoostingTitleShouldHaveTitlesContainingOrchardAppearFirst()

var query = JConvert.SerializeObject(dynamicQuery);

var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}");
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}", TestContext.Current.CancellationToken);
var queryResults = await content.Content.ReadAsAsync<LuceneQueryResults>();

// Test
Expand Down Expand Up @@ -70,7 +70,7 @@ public async Task BoostingBodyShouldHaveTitlesNotContainingOrchardAppearFirst()
};

var query = JConvert.SerializeObject(dynamicQuery);
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}");
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}", TestContext.Current.CancellationToken);
var queryResults = await content.Content.ReadAsAsync<LuceneQueryResults>();

// Test
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task SimpleQueryWildcardHasResults()

var query = JConvert.SerializeObject(dynamicQuery);

var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}");
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}", TestContext.Current.CancellationToken);
var queryResults = await content.Content.ReadAsAsync<LuceneQueryResults>();

// Test
Expand Down Expand Up @@ -158,7 +158,7 @@ public async Task TwoWildcardQueriesWithBoostHasResults()
}
}
""";
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}");
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={query}", TestContext.Current.CancellationToken);
var queryResults = await content.Content.ReadAsAsync<LuceneQueryResults>();
var contentItems = queryResults.Items.Select(x => JObject.FromObject(x).Deserialize<ContentItem>());

Expand All @@ -183,7 +183,7 @@ public async Task LuceneQueryTemplateWithSpecialCharactersShouldNotThrowError()
var index = "ArticleIndex";
var queryTemplate = "\r\r\n{% assign testVariable = \"48yvsghn194eft8axztaves25h\" %}\n\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n { \"term\" : { \"Content.ContentItem.ContentType\" : \"Article\" } },\n { \"term\": { \"Content.ContentItem.Published\" : \"true\" } },\n ]\n }\n }\n}";

var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={queryTemplate}");
var content = await context.Client.GetAsync($"api/lucene/content?indexName={index}&query={queryTemplate}", TestContext.Current.CancellationToken);
var queryResults = await content.Content.ReadAsAsync<LuceneQueryResults>();

// Assert
Expand Down
27 changes: 25 additions & 2 deletions test/OrchardCore.Tests/CIFact.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
using Xunit.v3;
using SystemEnvironment = System.Environment;

#nullable enable

namespace OrchardCore.Tests;

public class CIFactAttribute : FactAttribute
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CIFactAttribute : Attribute, IFactAttribute
{
public override string Skip
/// <inheritdoc/>
public string? DisplayName { get; set; }

/// <inheritdoc/>
public bool Explicit { get; set; }

/// <inheritdoc/>
public string? Skip
{
get
{
Expand All @@ -19,4 +30,16 @@ public override string Skip
return null!;
}
}

/// <inheritdoc/>
public Type? SkipType { get; set; }

/// <inheritdoc/>
public string? SkipUnless { get; set; }

/// <inheritdoc/>
public string? SkipWhen { get; set; }

/// <inheritdoc/>
public int Timeout { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public async Task UsersShouldBeAbleToCreateApplicationIfAllowed()
{
var mockOpenIdScopeManager = new Mock<IOpenIdScopeManager>();
var mockData = Array.Empty<object>();
#pragma warning disable xUnit1051 // Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
mockOpenIdScopeManager.Setup(m => m.ListAsync(null, null, default)).Returns(mockData.ToAsyncEnumerable());
#pragma warning restore xUnit1051 // Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
var controller = new ApplicationController(
Mock.Of<IShapeFactory>(),
Mock.Of<IOptions<PagerOptions>>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OrchardCore.Tests.Modules.OrchardCore.Resources;
public class SubResourceIntegrityTests
{
[CIFact]
public async Task SavedSubResourceIntegritiesShouldMatchCurrentResources()
public static async Task SavedSubResourceIntegritiesShouldMatchCurrentResources()
{
// Arrange
var resourceOptions = Options.Create(new ResourceOptions());
Expand Down
4 changes: 2 additions & 2 deletions test/OrchardCore.Tests/OrchardCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
<!-- Remove the underscores from member name -->
<OutputType>Exe</OutputType>
<NoWarn>$(NoWarn);CA1707;EnableGenerateDocumentationFile</NoWarn>
</PropertyGroup>

Expand Down Expand Up @@ -69,10 +70,9 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.analyzers" />
<PackageReference Include="xunit.runner.visualstudio" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(DotNetXunitVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 472378b

Please sign in to comment.