-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathNServiceBusAcceptanceTest.cs
More file actions
59 lines (47 loc) · 2.01 KB
/
NServiceBusAcceptanceTest.cs
File metadata and controls
59 lines (47 loc) · 2.01 KB
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
namespace ServiceControl.AcceptanceTesting
{
using System;
using System.Linq;
using System.Threading;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTesting.Customization;
using NServiceBus.Logging;
using NUnit.Framework;
using NUnit.Framework.Internal;
/// <summary>
/// Base class for all the NSB test that sets up our conventions
/// </summary>
[TestFixture]
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public abstract partial class NServiceBusAcceptanceTest
{
[SetUp]
public void SetUp()
{
LogManager.Use<DefaultFactory>(); // Ensures that every test the log manager is 'reset' as log manager can otherwise point to disposed resources. For example, when a test uses NServiceBus hosting
Conventions.EndpointNamingConvention = t =>
{
var classAndEndpoint = t.FullName.Split('.').Last();
var testName = classAndEndpoint.Split('+').First();
testName = testName.Replace("When_", "");
var endpointBuilder = classAndEndpoint.Split('+').Last();
testName = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(testName);
testName = testName.Replace("_", "");
return testName + "." + endpointBuilder;
};
}
[TearDown]
public void TearDown()
{
if (!TestExecutionContext.CurrentContext.TryGetRunDescriptor(out var runDescriptor))
{
return;
}
var scenarioContext = runDescriptor.ScenarioContext;
TestContext.Out.WriteLine($@"Test settings:
{string.Join(Environment.NewLine, runDescriptor.Settings.Select(setting => $" {setting.Key}: {setting.Value}"))}");
TestContext.Out.WriteLine($@"Context:
{string.Join(Environment.NewLine, scenarioContext.GetType().GetProperties().Select(p => $"{p.Name} = {p.GetValue(scenarioContext, null)}"))}");
}
}
}