summaryrefslogtreecommitdiff
path: root/src/internal/WixBuildTools.TestSupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport')
-rw-r--r--src/internal/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj2
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkipTestException.cs15
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactAttribute.cs13
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactDiscoverer.cs23
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactMessageBus.cs40
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactTestCase.cs40
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryAttribute.cs12
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryDiscoverer.cs41
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryTestCase.cs41
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/SucceededException.cs (renamed from src/internal/WixBuildTools.TestSupport/SucceededException.cs)0
-rw-r--r--src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs (renamed from src/internal/WixBuildTools.TestSupport/WixAssert.cs)11
11 files changed, 237 insertions, 1 deletions
diff --git a/src/internal/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj b/src/internal/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj
index d614476f..8a5237d1 100644
--- a/src/internal/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj
+++ b/src/internal/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj
@@ -21,6 +21,6 @@
21 </ItemGroup> 21 </ItemGroup>
22 22
23 <ItemGroup> 23 <ItemGroup>
24 <PackageReference Include="xunit.assert" /> 24 <PackageReference Include="xunit" />
25 </ItemGroup> 25 </ItemGroup>
26</Project> 26</Project>
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkipTestException.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkipTestException.cs
new file mode 100644
index 00000000..bd7d23f9
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkipTestException.cs
@@ -0,0 +1,15 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using System;
6
7 public class SkipTestException : Exception
8 {
9 public SkipTestException(string reason)
10 : base(reason)
11 {
12
13 }
14 }
15}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactAttribute.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactAttribute.cs
new file mode 100644
index 00000000..4974d489
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactAttribute.cs
@@ -0,0 +1,13 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using Xunit;
6 using Xunit.Sdk;
7
8 // https://github.com/xunit/samples.xunit/blob/5dc1d35a63c3394a8678ac466b882576a70f56f6/DynamicSkipExample
9 [XunitTestCaseDiscoverer("WixBuildTools.TestSupport.XunitExtensions.SkippableFactDiscoverer", "WixBuildTools.TestSupport")]
10 public class SkippableFactAttribute : FactAttribute
11 {
12 }
13}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactDiscoverer.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactDiscoverer.cs
new file mode 100644
index 00000000..b692c912
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactDiscoverer.cs
@@ -0,0 +1,23 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using System.Collections.Generic;
6 using Xunit.Abstractions;
7 using Xunit.Sdk;
8
9 public class SkippableFactDiscoverer : IXunitTestCaseDiscoverer
10 {
11 private IMessageSink DiagnosticMessageSink { get; }
12
13 public SkippableFactDiscoverer(IMessageSink diagnosticMessageSink)
14 {
15 this.DiagnosticMessageSink = diagnosticMessageSink;
16 }
17
18 public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
19 {
20 yield return new SkippableFactTestCase(this.DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);
21 }
22 }
23}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactMessageBus.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactMessageBus.cs
new file mode 100644
index 00000000..6d01889e
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactMessageBus.cs
@@ -0,0 +1,40 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using System.Linq;
6 using Xunit.Abstractions;
7 using Xunit.Sdk;
8
9 public class SkippableFactMessageBus : IMessageBus
10 {
11 private IMessageBus InnerBus { get; }
12
13 public SkippableFactMessageBus(IMessageBus innerBus)
14 {
15 this.InnerBus = innerBus;
16 }
17
18 public int DynamicallySkippedTestCount { get; private set; }
19
20 public void Dispose()
21 {
22 }
23
24 public bool QueueMessage(IMessageSinkMessage message)
25 {
26 if (message is ITestFailed testFailed)
27 {
28 var exceptionType = testFailed.ExceptionTypes.FirstOrDefault();
29 if (exceptionType == typeof(SkipTestException).FullName)
30 {
31 ++this.DynamicallySkippedTestCount;
32 return this.InnerBus.QueueMessage(new TestSkipped(testFailed.Test, testFailed.Messages.FirstOrDefault()));
33 }
34 }
35
36 // Nothing we care about, send it on its way
37 return this.InnerBus.QueueMessage(message);
38 }
39 }
40}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactTestCase.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactTestCase.cs
new file mode 100644
index 00000000..f13fec83
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableFactTestCase.cs
@@ -0,0 +1,40 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using System;
6 using System.ComponentModel;
7 using System.Threading;
8 using System.Threading.Tasks;
9 using Xunit.Abstractions;
10 using Xunit.Sdk;
11
12 public class SkippableFactTestCase : XunitTestCase
13 {
14 [EditorBrowsable(EditorBrowsableState.Never)]
15 [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
16 public SkippableFactTestCase() { }
17
18 public SkippableFactTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod, object[] testMethodArguments = null)
19 : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments)
20 {
21 }
22
23 public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink,
24 IMessageBus messageBus,
25 object[] constructorArguments,
26 ExceptionAggregator aggregator,
27 CancellationTokenSource cancellationTokenSource)
28 {
29 var skipMessageBus = new SkippableFactMessageBus(messageBus);
30 var result = await base.RunAsync(diagnosticMessageSink, skipMessageBus, constructorArguments, aggregator, cancellationTokenSource);
31 if (skipMessageBus.DynamicallySkippedTestCount > 0)
32 {
33 result.Failed -= skipMessageBus.DynamicallySkippedTestCount;
34 result.Skipped += skipMessageBus.DynamicallySkippedTestCount;
35 }
36
37 return result;
38 }
39 }
40}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryAttribute.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryAttribute.cs
new file mode 100644
index 00000000..e026bb59
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryAttribute.cs
@@ -0,0 +1,12 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using Xunit;
6 using Xunit.Sdk;
7
8 [XunitTestCaseDiscoverer("WixBuildTools.TestSupport.XunitExtensions.SkippableFactDiscoverer", "WixBuildTools.TestSupport")]
9 public class SkippableTheoryAttribute : TheoryAttribute
10 {
11 }
12}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryDiscoverer.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryDiscoverer.cs
new file mode 100644
index 00000000..cf4e2b43
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryDiscoverer.cs
@@ -0,0 +1,41 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using System.Collections.Generic;
6 using Xunit.Abstractions;
7 using Xunit.Sdk;
8
9 public class SkippableTheoryDiscoverer : IXunitTestCaseDiscoverer
10 {
11 private IMessageSink DiagnosticMessageSink { get; }
12 private TheoryDiscoverer TheoryDiscoverer { get; }
13
14 public SkippableTheoryDiscoverer(IMessageSink diagnosticMessageSink)
15 {
16 this.DiagnosticMessageSink = diagnosticMessageSink;
17
18 this.TheoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink);
19 }
20
21 public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
22 {
23 var defaultMethodDisplay = discoveryOptions.MethodDisplayOrDefault();
24 var defaultMethodDisplayOptions = discoveryOptions.MethodDisplayOptionsOrDefault();
25
26 // Unlike fact discovery, the underlying algorithm for theories is complex, so we let the theory discoverer
27 // do its work, and do a little on-the-fly conversion into our own test cases.
28 foreach (var testCase in this.TheoryDiscoverer.Discover(discoveryOptions, testMethod, factAttribute))
29 {
30 if (testCase is XunitTheoryTestCase)
31 {
32 yield return new SkippableTheoryTestCase(this.DiagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testCase.TestMethod);
33 }
34 else
35 {
36 yield return new SkippableFactTestCase(this.DiagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testCase.TestMethod, testCase.TestMethodArguments);
37 }
38 }
39 }
40 }
41}
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryTestCase.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryTestCase.cs
new file mode 100644
index 00000000..3299fe7e
--- /dev/null
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SkippableTheoryTestCase.cs
@@ -0,0 +1,41 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixBuildTools.TestSupport.XunitExtensions
4{
5 using System;
6 using System.ComponentModel;
7 using System.Threading;
8 using System.Threading.Tasks;
9 using Xunit.Abstractions;
10 using Xunit.Sdk;
11
12 public class SkippableTheoryTestCase : XunitTheoryTestCase
13 {
14 [EditorBrowsable(EditorBrowsableState.Never)]
15 [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
16 public SkippableTheoryTestCase() { }
17
18 public SkippableTheoryTestCase(IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, ITestMethod testMethod)
19 : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod)
20 {
21 }
22
23 public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink,
24 IMessageBus messageBus,
25 object[] constructorArguments,
26 ExceptionAggregator aggregator,
27 CancellationTokenSource cancellationTokenSource)
28 {
29 // Duplicated code from SkippableFactTestCase. I'm sure we could find a way to de-dup with some thought.
30 var skipMessageBus = new SkippableFactMessageBus(messageBus);
31 var result = await base.RunAsync(diagnosticMessageSink, skipMessageBus, constructorArguments, aggregator, cancellationTokenSource);
32 if (skipMessageBus.DynamicallySkippedTestCount > 0)
33 {
34 result.Failed -= skipMessageBus.DynamicallySkippedTestCount;
35 result.Skipped += skipMessageBus.DynamicallySkippedTestCount;
36 }
37
38 return result;
39 }
40 }
41}
diff --git a/src/internal/WixBuildTools.TestSupport/SucceededException.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SucceededException.cs
index 704fba28..704fba28 100644
--- a/src/internal/WixBuildTools.TestSupport/SucceededException.cs
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SucceededException.cs
diff --git a/src/internal/WixBuildTools.TestSupport/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs
index 1db842c3..10156547 100644
--- a/src/internal/WixBuildTools.TestSupport/WixAssert.cs
+++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs
@@ -6,6 +6,7 @@ namespace WixBuildTools.TestSupport
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Linq; 7 using System.Linq;
8 using System.Xml.Linq; 8 using System.Xml.Linq;
9 using WixBuildTools.TestSupport.XunitExtensions;
9 using Xunit; 10 using Xunit;
10 11
11 public class WixAssert : Assert 12 public class WixAssert : Assert
@@ -41,6 +42,16 @@ namespace WixBuildTools.TestSupport
41 CompareXml(expectedDoc, actualDoc); 42 CompareXml(expectedDoc, actualDoc);
42 } 43 }
43 44
45 /// <summary>
46 /// Dynamically skips the test.
47 /// Requires that the test was marked with a fact attribute derived from <see cref="WixBuildTools.TestSupport.XunitExtensions.SkippableFactAttribute" />
48 /// or <see cref="WixBuildTools.TestSupport.XunitExtensions.SkippableTheoryAttribute" />
49 /// </summary>
50 public static void Skip(string message)
51 {
52 throw new SkipTestException(message);
53 }
54
44 public static void Succeeded(int hr, string format, params object[] formatArgs) 55 public static void Succeeded(int hr, string format, params object[] formatArgs)
45 { 56 {
46 if (0 > hr) 57 if (0 > hr)