-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathIdentityProcessorVerificationDelegationTest.cs
63 lines (57 loc) · 2.92 KB
/
IdentityProcessorVerificationDelegationTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Xunit;
using Xunit.Abstractions;
namespace Reactive.Streams.TCK.Tests
{
/// <summary>
/// The <see cref="IdentityProcessorVerification{T}"/> must also run all tests from
/// <see cref="PublisherVerification{T}"/> and <see cref="SubscriberWhiteboxVerification{T}"/>.
///
/// Since in .Net this can be only achieved by delegating, we need to make sure we delegate to each of the tests,
/// so that if in the future we add more tests to these verifications we're sure to not forget to add the delegating methods.
/// </summary>
public class IdentityProcessorVerificationDelegationTest
{
[SkippableFact]
public void ShouldIncludeAllTestsFromPublisherVerification()
{
var processeroTests = GetTestNames(typeof(IdentityProcessorVerification<>)).ToList();
var publisherTests = GetTestNames(typeof(PublisherVerification<>)).ToList();
AssertSuiteDelegatedAllTests(typeof(IdentityProcessorVerification<>), processeroTests,
typeof(PublisherVerification<>), publisherTests);
}
[SkippableFact]
public void ShouldIncludeAllTestsFromSubscriberVerification()
{
var processeroTests = GetTestNames(typeof(IdentityProcessorVerification<>)).ToList();
var subscriberTests = GetTestNames(typeof(SubscriberWhiteboxVerification<>)).ToList();
AssertSuiteDelegatedAllTests(typeof(IdentityProcessorVerification<>), processeroTests,
typeof(SubscriberWhiteboxVerification<>), subscriberTests);
}
private static void AssertSuiteDelegatedAllTests(Type delegatingFrom, IList<string> allTests, Type targetClass,
IList<string> delegatedToTests)
{
foreach (var targetTest in delegatedToTests)
{
var message = new StringBuilder();
message.AppendLine($"Test '{targetTest}' in '{targetClass}' has not been properly delegated to in aggregate '{delegatingFrom}'!");
message.AppendLine($"You must delegate to this test from {delegatingFrom}, like this:");
message.AppendLine("[SkippableFact]");
message.AppendLine($"public void {targetTest} () => delegate{targetClass.Name}.{targetTest}();");
Assert.True(TestsInclude(allTests, targetTest), message.ToString());
}
}
private static bool TestsInclude(IList<string> processorTests, string targetTest)
=> processorTests.Contains(targetTest);
private static IEnumerable<string> GetTestNames(Type type)
=> type.GetMethods()
.Where(m =>
m.GetCustomAttribute<FactAttribute>() != null ||
m.GetCustomAttribute<SkippableFactAttribute>() != null)
.Select(m => m.Name);
}
}