forked from mauroservienti/NServiceBus.IntegrationTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericHostSnippets.cs
70 lines (59 loc) · 2.06 KB
/
GenericHostSnippets.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
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NServiceBus.IntegrationTesting;
using NUnit.Framework;
namespace GenericHostSnippets
{
public class When_sending_AMessage
{
[Test]
public async Task AReplyMessage_is_received_and_ASaga_is_started()
{
// begin-snippet: with-generic-host-endpoint
_ = await Scenario.Define<IntegrationScenarioContext>()
.WithGenericHostEndpoint("endpoint-name", configPreview => Program.CreateHostBuilder(new string[0], configPreview).Build())
// end-snippet
.Done(ctx=>false)
.Run();
}
}
class Program
{
// begin-snippet: basic-generic-host-endpoint
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
var builder = Host.CreateDefaultBuilder(args);
builder.UseConsoleLifetime();
builder.UseNServiceBus(ctx =>
{
var config = new EndpointConfiguration("endpoint-name");
config.UseTransport(new LearningTransport());
return config;
});
return builder;
}
// end-snippet
// begin-snippet: basic-generic-host-endpoint-with-config-previewer
public static IHostBuilder CreateHostBuilder(string[] args, Action<EndpointConfiguration> configPreview)
{
var builder = Host.CreateDefaultBuilder(args);
builder.UseConsoleLifetime();
builder.UseNServiceBus(ctx =>
{
var config = new EndpointConfiguration("endpoint-name");
config.UseTransport(new LearningTransport());
configPreview?.Invoke(config);
return config;
});
return builder;
}
// end-snippet
}
}