-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathDiscoverySpec.cs
83 lines (74 loc) · 3.55 KB
/
DiscoverySpec.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//-----------------------------------------------------------------------
// <copyright file="DiscoverySpec.cs" company="Akka.NET Project">
// Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Akka.Remote.TestKit;
using Akka.TestKit;
using Xunit;
using FluentAssertions;
namespace Akka.MultiNodeTestRunner.Shared.Tests.MultiNodeTestRunnerDiscovery
{
public class DiscoverySpec
{
[Fact(DisplayName = "Abstract classes are not discoverable")]
public void No_abstract_classes()
{
var discoveredSpecs = DiscoverSpecs();
Assert.False(discoveredSpecs.ContainsKey(KeyFromSpecName(nameof(DiscoveryCases.NoAbstractClassesSpec))));
}
[Fact(DisplayName = "Deeply inherited classes are discoverable")]
public void Deeply_inherited_are_ok()
{
var discoveredSpecs = DiscoverSpecs();
Assert.Equal("DeeplyInheritedChildRole", discoveredSpecs[KeyFromSpecName(nameof(DiscoveryCases.DeeplyInheritedChildSpec))].First().Role);
}
[Fact(DisplayName = "Child test class with default constructors are ok")]
public void Child_class_with_default_constructor_are_ok()
{
Action testDelegate = () =>
{
var testCase = typeof(DiscoveryCases.DefaultConstructorOnDerivedClassSpec);
var constuctor = Discovery.FindConfigConstructor(testCase);
constuctor.Should().NotBeNull();
};
testDelegate.Should().NotThrow();
}
[Fact(DisplayName = "One test case per RoleName per Spec declaration with MultiNodeFact")]
public void Discovered_count_equals_number_of_roles_mult_specs()
{
var discoveredSpecs = DiscoverSpecs();
Assert.Equal(5, discoveredSpecs[KeyFromSpecName(nameof(DiscoveryCases.FloodyChildSpec1))].Count);
Assert.Equal(5, discoveredSpecs[KeyFromSpecName(nameof(DiscoveryCases.FloodyChildSpec2))].Count);
Assert.Equal(5, discoveredSpecs[KeyFromSpecName(nameof(DiscoveryCases.FloodyChildSpec3))].Count);
}
[Fact(DisplayName = "Only the MultiNodeConfig.Roles property is used to compute the number of Roles in MultiNodeFact")]
public void Only_MultiNodeConfig_role_count_used()
{
var discoveredSpecs = DiscoverSpecs();
Assert.Equal(10, discoveredSpecs[KeyFromSpecName(nameof(DiscoveryCases.NoReflectionSpec))].Select(c => c.Role).Count());
}
private static Dictionary<string, List<NodeTest>> DiscoverSpecs()
{
Environment.SetEnvironmentVariable(MultiNodeFactAttribute.MultiNodeTestEnvironmentName, "1");
using (var controller = new XunitFrontController(AppDomainSupport.IfAvailable, new System.Uri(typeof(DiscoveryCases).GetTypeInfo().Assembly.CodeBase).LocalPath))
{
using (var discovery = new Discovery())
{
controller.Find(false, discovery, TestFrameworkOptions.ForDiscovery());
discovery.Finished.WaitOne();
return discovery.Tests;
}
}
}
private string KeyFromSpecName(string specName)
{
return typeof(DiscoveryCases).FullName + "+" + specName;
}
}
}