From 42c06aab789bfe4bcef82c2d3a0bec0b5356efcf Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 4 Jun 2019 11:30:19 -0500 Subject: [PATCH] Account for XUnit serialization in passed tests --- .../TestUtilities/Threading/WpfFactDiscoverer.cs | 10 +++------- .../TestUtilities/Threading/WpfTestCase.cs | 9 ++------- .../TestUtilities/Threading/WpfTestCaseRunner.cs | 5 +---- .../TestUtilities/Threading/WpfTestRunner.cs | 10 +++++++--- .../TestUtilities/Threading/WpfTheoryTestCase.cs | 9 ++------- .../TestUtilities/Threading/WpfTheoryTestCaseRunner.cs | 5 +---- 6 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs b/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs index 6d6d2ff178b..d2ebf0b7285 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs @@ -9,38 +9,34 @@ namespace Roslyn.Test.Utilities public class WpfFactDiscoverer : FactDiscoverer { private readonly IMessageSink _diagnosticMessageSink; - private readonly IDictionary _passedTests; public WpfFactDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink) { _diagnosticMessageSink = diagnosticMessageSink; - _passedTests = TestInfo.GetPassedTestsInfo(); } protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) - => new WpfTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, _passedTests); + => new WpfTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod); } public class WpfTheoryDiscoverer : TheoryDiscoverer { private readonly IMessageSink _diagnosticMessageSink; - private readonly IDictionary _passedTests; public WpfTheoryDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnosticMessageSink) { _diagnosticMessageSink = diagnosticMessageSink; - _passedTests = TestInfo.GetPassedTestsInfo(); } protected override IEnumerable CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow) { - var testCase = new WpfTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, _passedTests, dataRow); + var testCase = new WpfTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, dataRow); return new[] { testCase }; } protected override IEnumerable CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { - var testCase = new WpfTheoryTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, _passedTests); + var testCase = new WpfTheoryTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod); return new[] { testCase }; } } diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfTestCase.cs b/src/EditorFeatures/TestUtilities/Threading/WpfTestCase.cs index bd19eebb191..ded0bd6ef9e 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfTestCase.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfTestCase.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. 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.ComponentModel; using System.Threading; using System.Threading.Tasks; @@ -12,24 +11,20 @@ namespace Roslyn.Test.Utilities { public sealed class WpfTestCase : XunitTestCase { - private readonly IDictionary _passedTests; - [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] public WpfTestCase() { - _passedTests = new Dictionary(); } - public WpfTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, IDictionary passedTests, object[] testMethodArguments = null) + public WpfTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, object[] testMethodArguments = null) : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) { - _passedTests = passedTests; } public override Task RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { - var runner = new WpfTestCaseRunner(WpfTestSharedData.Instance, this, DisplayName, SkipReason, constructorArguments, TestMethodArguments, messageBus, aggregator, _passedTests, cancellationTokenSource); + var runner = new WpfTestCaseRunner(WpfTestSharedData.Instance, this, DisplayName, SkipReason, constructorArguments, TestMethodArguments, messageBus, aggregator, cancellationTokenSource); return runner.RunAsync(); } } diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfTestCaseRunner.cs b/src/EditorFeatures/TestUtilities/Threading/WpfTestCaseRunner.cs index ff7524feab3..259382bca80 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfTestCaseRunner.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfTestCaseRunner.cs @@ -12,7 +12,6 @@ namespace Roslyn.Test.Utilities public sealed class WpfTestCaseRunner : XunitTestCaseRunner { public WpfTestSharedData SharedData { get; } - public readonly IDictionary _passedTests; public WpfTestCaseRunner( WpfTestSharedData sharedData, @@ -23,17 +22,15 @@ public sealed class WpfTestCaseRunner : XunitTestCaseRunner object[] testMethodArguments, IMessageBus messageBus, ExceptionAggregator aggregator, - IDictionary passedTests, CancellationTokenSource cancellationTokenSource) : base(testCase, displayName, skipReason, constructorArguments, testMethodArguments, messageBus, aggregator, cancellationTokenSource) { SharedData = sharedData; - _passedTests = passedTests; } protected override XunitTestRunner CreateTestRunner(ITest test, IMessageBus messageBus, Type testClass, object[] constructorArguments, MethodInfo testMethod, object[] testMethodArguments, string skipReason, IReadOnlyList beforeAfterAttributes, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { - var runner = new WpfTestRunner(SharedData, test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, _passedTests, cancellationTokenSource); + var runner = new WpfTestRunner(SharedData, test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, cancellationTokenSource); return runner; } } diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfTestRunner.cs b/src/EditorFeatures/TestUtilities/Threading/WpfTestRunner.cs index bebab220048..95e4d04b32c 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfTestRunner.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfTestRunner.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Diagnostics; using System.Reflection; using System.Threading; @@ -25,10 +26,15 @@ namespace Roslyn.Test.Utilities /// public sealed class WpfTestRunner : XunitTestRunner { + private static readonly ImmutableDictionary _passedTests; private static string s_wpfFactRequirementReason; public WpfTestSharedData SharedData { get; } - public readonly IDictionary _passedTests; + + static WpfTestRunner() + { + _passedTests = TestInfo.GetPassedTestsInfo(); + } public WpfTestRunner( WpfTestSharedData sharedData, @@ -41,12 +47,10 @@ public sealed class WpfTestRunner : XunitTestRunner string skipReason, IReadOnlyList beforeAfterAttributes, ExceptionAggregator aggregator, - IDictionary passedTests, CancellationTokenSource cancellationTokenSource) : base(test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, cancellationTokenSource) { SharedData = sharedData; - _passedTests = passedTests; } protected override Task InvokeTestMethodAsync(ExceptionAggregator aggregator) diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCase.cs b/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCase.cs index 3221811202c..7006d89d104 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCase.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCase.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. 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.ComponentModel; using System.Threading; using System.Threading.Tasks; @@ -12,24 +11,20 @@ namespace Roslyn.Test.Utilities { public class WpfTheoryTestCase : XunitTheoryTestCase { - public readonly IDictionary _passedTests; - [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] public WpfTheoryTestCase() { - _passedTests = new Dictionary(); } - public WpfTheoryTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, IDictionary passedTests) + public WpfTheoryTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod) : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod) { - _passedTests = passedTests; } public override Task RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { - var runner = new WpfTheoryTestCaseRunner(WpfTestSharedData.Instance, this, DisplayName, SkipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, _passedTests, cancellationTokenSource); + var runner = new WpfTheoryTestCaseRunner(WpfTestSharedData.Instance, this, DisplayName, SkipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource); return runner.RunAsync(); } } diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCaseRunner.cs b/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCaseRunner.cs index 90bb9f14cc1..8a14f67abf7 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCaseRunner.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfTheoryTestCaseRunner.cs @@ -12,7 +12,6 @@ namespace Roslyn.Test.Utilities public class WpfTheoryTestCaseRunner : XunitTheoryTestCaseRunner { public WpfTestSharedData SharedData { get; } - public readonly IDictionary _passedTests; public WpfTheoryTestCaseRunner( WpfTestSharedData sharedData, @@ -23,17 +22,15 @@ public class WpfTheoryTestCaseRunner : XunitTheoryTestCaseRunner IMessageSink diagnosticMessageSink, IMessageBus messageBus, ExceptionAggregator aggregator, - IDictionary passedTests, CancellationTokenSource cancellationTokenSource) : base(testCase, displayName, skipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource) { SharedData = sharedData; - _passedTests = passedTests; } protected override XunitTestRunner CreateTestRunner(ITest test, IMessageBus messageBus, Type testClass, object[] constructorArguments, MethodInfo testMethod, object[] testMethodArguments, string skipReason, IReadOnlyList beforeAfterAttributes, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { - var runner = new WpfTestRunner(SharedData, test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, _passedTests, cancellationTokenSource); + var runner = new WpfTestRunner(SharedData, test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, cancellationTokenSource); return runner; } } -- GitLab