-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MongoDbSample project that removes the ASW SDK
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>true</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<Import Project="../../src/build/Chisel.props" /> | ||
<Import Project="../../src/build/Chisel.targets" /> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="MongoDB.Driver" Version="2.24.0" /> | ||
<PackageReference Include="Testcontainers.MongoDb" Version="3.7.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ChiselPackages Include="AWSSDK.SecurityToken" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using DotNet.Testcontainers.Configurations; | ||
using Microsoft.Extensions.Logging; | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
using Testcontainers.MongoDb; | ||
|
||
TestcontainersSettings.Logger = new DockerLogger(); | ||
await using var mongoContainer = new MongoDbBuilder().Build(); | ||
try | ||
{ | ||
await mongoContainer.StartAsync(); | ||
var mongoSettings = MongoClientSettings.FromConnectionString(mongoContainer.GetConnectionString()); | ||
if (args.Contains("--aws")) | ||
{ | ||
mongoSettings.Credential = new MongoCredential("MONGODB-AWS", new MongoExternalIdentity("username"), new PasswordEvidence("password")); | ||
} | ||
var mongoClient = new MongoClient(mongoSettings); | ||
var database = mongoClient.GetDatabase("admin"); | ||
var buildInfo = await database.RunCommandAsync(new BsonDocumentCommand<BsonDocument>(new BsonDocument { ["buildInfo"] = true })); | ||
Console.WriteLine($"✅ {buildInfo}"); | ||
return 0; | ||
} | ||
catch (Exception exception) | ||
{ | ||
Console.Error.WriteLine($"❌ {exception}"); | ||
return 1; | ||
} | ||
|
||
internal class DockerLogger : ILogger | ||
{ | ||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) => Console.WriteLine($"🐳 {formatter(state, exception)}"); | ||
public bool IsEnabled(LogLevel logLevel) => true; | ||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null; | ||
} |