Merge branch 'release/3.0' => 'master' (dotnet/extensions#2242)
\n\nCommit migrated from 94422985a1
This commit is contained in:
commit
d3ea1cca49
|
|
@ -8,7 +8,7 @@ using Xunit.Sdk;
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||||
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalFactDiscoverer), "Microsoft.AspNetCore.Testing")]
|
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing." + nameof(ConditionalFactDiscoverer), "Microsoft.AspNetCore.Testing")]
|
||||||
public class ConditionalFactAttribute : FactAttribute
|
public class ConditionalFactAttribute : FactAttribute
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ using Xunit.Sdk;
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||||
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalTheoryDiscoverer), "Microsoft.AspNetCore.Testing")]
|
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing." + nameof(ConditionalTheoryDiscoverer), "Microsoft.AspNetCore.Testing")]
|
||||||
public class ConditionalTheoryAttribute : TheoryAttribute
|
public class ConditionalTheoryAttribute : TheoryAttribute
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
using Xunit.Sdk;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Testing
|
||||||
|
{
|
||||||
|
public class AlphabeticalOrderer : ITestCaseOrderer
|
||||||
|
{
|
||||||
|
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
|
||||||
|
where TTestCase : ITestCase
|
||||||
|
{
|
||||||
|
var result = testCases.ToList();
|
||||||
|
result.Sort((x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.TestMethod.Method.Name, y.TestMethod.Method.Name));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
|
[TestCaseOrderer("Microsoft.AspNetCore.Testing.AlphabeticalOrderer", "Microsoft.AspNetCore.Testing.Tests")]
|
||||||
public class ConditionalFactTest : IClassFixture<ConditionalFactTest.ConditionalFactAsserter>
|
public class ConditionalFactTest : IClassFixture<ConditionalFactTest.ConditionalFactAsserter>
|
||||||
{
|
{
|
||||||
public ConditionalFactTest(ConditionalFactAsserter collector)
|
public ConditionalFactTest(ConditionalFactAsserter collector)
|
||||||
|
|
@ -47,13 +47,19 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
#error Target frameworks need to be updated.
|
#error Target frameworks need to be updated.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Test is named this way to be the lowest test in the alphabet, it relies on test ordering
|
||||||
|
[Fact]
|
||||||
|
public void ZzzzzzzEnsureThisIsTheLastTest()
|
||||||
|
{
|
||||||
|
Assert.True(Asserter.TestRan);
|
||||||
|
}
|
||||||
|
|
||||||
public class ConditionalFactAsserter : IDisposable
|
public class ConditionalFactAsserter : IDisposable
|
||||||
{
|
{
|
||||||
public bool TestRan { get; set; }
|
public bool TestRan { get; set; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Assert.True(TestRan, "If this assertion fails, a conditional fact wasn't discovered.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Testing
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
|
[TestCaseOrderer("Microsoft.AspNetCore.Testing.AlphabeticalOrderer", "Microsoft.AspNetCore.Testing.Tests")]
|
||||||
public class ConditionalTheoryTest : IClassFixture<ConditionalTheoryTest.ConditionalTheoryAsserter>
|
public class ConditionalTheoryTest : IClassFixture<ConditionalTheoryTest.ConditionalTheoryAsserter>
|
||||||
{
|
{
|
||||||
public ConditionalTheoryTest(ConditionalTheoryAsserter asserter)
|
public ConditionalTheoryTest(ConditionalTheoryAsserter asserter)
|
||||||
|
|
@ -101,6 +101,13 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
#error Target frameworks need to be updated.
|
#error Target frameworks need to be updated.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Test is named this way to be the lowest test in the alphabet, it relies on test ordering
|
||||||
|
[Fact]
|
||||||
|
public void ZzzzzzzEnsureThisIsTheLastTest()
|
||||||
|
{
|
||||||
|
Assert.True(Asserter.TestRan);
|
||||||
|
}
|
||||||
|
|
||||||
public static TheoryData<Func<int, int>> GetActionTestData
|
public static TheoryData<Func<int, int>> GetActionTestData
|
||||||
=> new TheoryData<Func<int, int>>
|
=> new TheoryData<Func<int, int>>
|
||||||
{
|
{
|
||||||
|
|
@ -113,7 +120,6 @@ namespace Microsoft.AspNetCore.Testing
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Assert.True(TestRan, "If this assertion fails, a conditional theory wasn't discovered.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue