-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConnectorMongoDbOptionTest.cs
More file actions
47 lines (41 loc) · 2.09 KB
/
Copy pathConnectorMongoDbOptionTest.cs
File metadata and controls
47 lines (41 loc) · 2.09 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
using System.Collections.Generic;
using Steeltoe.NetCoreTool.Template.WebApi.Test.Models;
using Xunit.Abstractions;
namespace Steeltoe.NetCoreTool.Template.WebApi.Test
{
public class ConnectorMongoDbOptionTest(ITestOutputHelper logger)
: ProjectOptionTest("connector-mongodb", "Add a connector for MongoDB databases.", logger)
{
protected override void AssertPackageReferencesHook(ProjectOptions options, List<(string, string)> packages)
{
packages.Add(("MongoDB.Driver", "3.6.*"));
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.MongoDb" : "Steeltoe.Connectors.MongoDb";
}
private static string GetSetupComment(SteeltoeVersion steeltoeVersion)
{
return steeltoeVersion == SteeltoeVersion.Steeltoe32
? "// TODO: Add your connection string at configuration key: MongoDb:Client:ConnectionString"
: "// TODO: Add your connection string at configuration key: Steeltoe:Client:MongoDb:Default:ConnectionString";
}
private static string GetSetupCodeFragment(SteeltoeVersion steeltoeVersion)
{
return steeltoeVersion == SteeltoeVersion.Steeltoe32
? "builder.Services.AddMongoClient(builder.Configuration);"
: "builder.AddMongoDb();";
}
}
}