Skip to content

Add XUnit infrastructure to handle unsupported statements and test runner crashes #152

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

Merged
merged 2 commits into from
Oct 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Shared\**\*.cs" />
<Compile Include="..\Shared\**\*.cs">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="xunit.core" />
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.Jet.FunctionalTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
[assembly: TestCaseOrderer("EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit." + nameof(AscendingTestCaseOrderer), "EntityFrameworkCore.Jet.FunctionalTests")]

#endif

[assembly: TestFramework("EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit." + nameof(JetXunitTestFramework), "EntityFrameworkCore.Jet.FunctionalTests")]

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions test/EFCore.Jet.Tests/EFCore.Jet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
<Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Shared\**\*.cs" />
</ItemGroup>

<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities;

[Flags]
public enum AccessProviderTypeVariation
{
None = 0,
X86 = 1 << 0,
X64 = 1 << 1,
Odbc = 1 << 2,
OleDb = 1 << 3,
All = -1,
}
43 changes: 43 additions & 0 deletions test/Shared/TestUtilities/Attributes/TestRunnerCrashAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;

namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities;

/// <summary>
/// Marks a test method or class that is known to crash the test runner.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class TestRunnerCrashAttribute : Attribute, ITestCondition
{
public const string DefaultSkipReason = "The test is known to crash the test runner.";

protected AccessProviderTypeVariation[] AccessProviderTypeVariations { get; }

public TestRunnerCrashAttribute(params AccessProviderTypeVariation[] accessProviderTypeVariations)
{
AccessProviderTypeVariations = accessProviderTypeVariations.Length > 0
? accessProviderTypeVariations
: new[] { AccessProviderTypeVariation.All };
}

public virtual ValueTask<bool> IsMetAsync()
{
// Implement and enable if we want to filter tests by specific runtime scenarios.
var currentVariation = AccessProviderTypeVariation.All; // AppConfig.AccessProviderTypeVariation;
var isMet = AccessProviderTypeVariations.Any(v => v.HasFlag(currentVariation));

if (!isMet && string.IsNullOrEmpty(Skip))
{
Skip = DefaultSkipReason;
}

return new ValueTask<bool>(isMet);
}

public virtual string SkipReason
=> Skip;

public virtual string Skip { get; set; }
}
15 changes: 15 additions & 0 deletions test/Shared/TestUtilities/Xunit/AscendingTestCaseOrderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;

// ReSharper disable once CheckNamespace
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit;

public class AscendingTestCaseOrderer : ITestCaseOrderer
{
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
where TTestCase : ITestCase
=> testCases.OrderBy(c => c.DisplayName, StringComparer.OrdinalIgnoreCase);
}
14 changes: 14 additions & 0 deletions test/Shared/TestUtilities/Xunit/AscendingTestCollectionOrderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

// ReSharper disable once CheckNamespace
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit;

public class AscendingTestCollectionOrderer : ITestCollectionOrderer
{
public IEnumerable<ITestCollection> OrderTestCollections(IEnumerable<ITestCollection> testCollections)
=> testCollections.OrderBy(c => c.DisplayName, StringComparer.OrdinalIgnoreCase);
}
40 changes: 40 additions & 0 deletions test/Shared/TestUtilities/Xunit/ExceptionTestCaseOrderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore.Internal;
using Xunit.Abstractions;
using Xunit.Sdk;

// ReSharper disable once CheckNamespace
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit;

public class ExceptionTestCaseOrderer : ITestCaseOrderer
{
private readonly string[] _testCaseOrder =
{
"Select_GetValueOrDefault_on_DateTime",
"Select_byte_constant",
"Select_DTO_with_member_init_distinct_in_subquery_translated_to_server",
"Select_Except_reference_projection",
"Select_Union",
"Select_DTO_with_member_init_distinct_in_subquery_translated_to_server_2",
"Select_bool_closure",
};

public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
where TTestCase : ITestCase
{
var orderedTestCases = testCases.OrderBy(c => Array.IndexOf(_testCaseOrder, c.TestMethod.Method.Name)).ToList();

var builder = new StringBuilder()
.AppendLine("Test Case Order:")
.AppendLine(string.Join(Environment.NewLine, orderedTestCases.Select(c => c.TestMethod.Method.Name)));

Debug.WriteLine(builder);
Console.WriteLine(builder);

return orderedTestCases;
}
}
23 changes: 23 additions & 0 deletions test/Shared/TestUtilities/Xunit/JetConditionalFactDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit;

public class JetConditionalFactDiscoverer : ConditionalFactDiscoverer
{
public JetConditionalFactDiscoverer(IMessageSink messageSink)
: base(messageSink)
{
}

protected override IXunitTestCase CreateTestCase(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo factAttribute)
=> new JetConditionalFactTestCase(
DiagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod);
}
47 changes: 47 additions & 0 deletions test/Shared/TestUtilities/Xunit/JetConditionalFactTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit;

/// <remarks>
/// We cannot inherit from ConditionalFactTestCase, because it's sealed.
/// </remarks>
public sealed class JetConditionalFactTestCase : XunitTestCase
{
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public JetConditionalFactTestCase()
{
}

public JetConditionalFactTestCase(
IMessageSink diagnosticMessageSink,
TestMethodDisplay defaultMethodDisplay,
TestMethodDisplayOptions defaultMethodDisplayOptions,
ITestMethod testMethod,
object[] testMethodArguments = null)
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments)
{
}

public override async Task<RunSummary> RunAsync(
IMessageSink diagnosticMessageSink,
IMessageBus messageBus,
object[] constructorArguments,
ExceptionAggregator aggregator,
CancellationTokenSource cancellationTokenSource)
=> await XunitTestCaseExtensions.TrySkipAsync(this, messageBus)
? new RunSummary { Total = 1, Skipped = 1 }
: await new JetXunitTestCaseRunner(
this,
DisplayName,
SkipReason,
constructorArguments,
TestMethodArguments,
messageBus,
aggregator,
cancellationTokenSource).RunAsync();
}
40 changes: 40 additions & 0 deletions test/Shared/TestUtilities/Xunit/JetConditionalTheoryDiscoverer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit;

public class JetConditionalTheoryDiscoverer : ConditionalTheoryDiscoverer
{
public JetConditionalTheoryDiscoverer(IMessageSink messageSink)
: base(messageSink)
{
}

protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo theoryAttribute)
{
yield return new JetConditionalTheoryTestCase(
DiagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod);
}

protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow(
ITestFrameworkDiscoveryOptions discoveryOptions,
ITestMethod testMethod,
IAttributeInfo theoryAttribute,
object[] dataRow)
{
yield return new JetConditionalFactTestCase(
DiagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod,
dataRow);
}
}
Loading