-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConnectorRabbitMqOptionTest.cs
More file actions
53 lines (46 loc) · 2.28 KB
/
Copy pathConnectorRabbitMqOptionTest.cs
File metadata and controls
53 lines (46 loc) · 2.28 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
using System.Collections.Generic;
using Steeltoe.NetCoreTool.Template.WebApi.Test.Models;
using Xunit.Abstractions;
namespace Steeltoe.NetCoreTool.Template.WebApi.Test
{
public class ConnectorRabbitMqOptionTest(ITestOutputHelper logger)
: ProjectOptionTest("connector-rabbitmq", "Add a connector for RabbitMQ message brokers.", logger)
{
protected override void AssertPackageReferencesHook(ProjectOptions options, List<(string, string)> packages)
{
var rabbitMqVersion = options.SteeltoeVersion switch
{
SteeltoeVersion.Steeltoe32 => "5.2.*",
_ => "7.2.*"
};
packages.Add(("RabbitMQ.Client", rabbitMqVersion));
packages.Add((GetPackageName(options.SteeltoeVersion), "$(SteeltoeVersion)"));
}
private static string GetPackageName(SteeltoeVersion steeltoeVersion)
{
return steeltoeVersion == SteeltoeVersion.Steeltoe32 ? "Steeltoe.Connector.ConnectorCore" : "Steeltoe.Connectors";
}
protected override void AssertProgramSnippetsHook(ProjectOptions options, List<string> snippets)
{
snippets.Add($"using {GetNamespaceImport(options.SteeltoeVersion)};");
snippets.Add(GetSetupComment(options.SteeltoeVersion));
snippets.Add(GetSetupCodeFragment(options.SteeltoeVersion));
}
private static string GetNamespaceImport(SteeltoeVersion steeltoeVersion)
{
return steeltoeVersion == SteeltoeVersion.Steeltoe32 ? "Steeltoe.Connector.RabbitMQ" : "Steeltoe.Connectors.RabbitMQ";
}
private static string GetSetupComment(SteeltoeVersion steeltoeVersion)
{
return steeltoeVersion == SteeltoeVersion.Steeltoe32
? "// TODO: Add your connection string at configuration key: RabbitMq:Client:Url"
: "// TODO: Add your connection string at configuration key: Steeltoe:Client:RabbitMQ:Default:ConnectionString";
}
private static string GetSetupCodeFragment(SteeltoeVersion steeltoeVersion)
{
return steeltoeVersion == SteeltoeVersion.Steeltoe32
? "builder.Services.AddRabbitMQConnection(builder.Configuration);"
: "builder.AddRabbitMQ();";
}
}
}