Skip to content

Commit

Permalink
Add MongoDbSample project that removes the ASW SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 6, 2024
1 parent ebdecac commit 9ca2342
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Chisel.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Meta", "Meta", "{13D33453-8FDA-4FBC-863A-24383232D951}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{13D33453-8FDA-4FBC-863A-24383232D951}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
NuGet.config = NuGet.config
Expand All @@ -18,6 +18,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chisel", "src\Chisel.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chisel.Tests", "tests\Chisel.Tests.csproj", "{EC3CCB92-1AA1-4C33-B296-D7111EEF84E4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{0CC84E67-19D2-480B-B36A-6BB15A9109E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDbSample", "samples\MongoDbSample\MongoDbSample.csproj", "{845EDA2A-5207-4C6D-ABE9-9635F4630D90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -32,5 +36,12 @@ Global
{EC3CCB92-1AA1-4C33-B296-D7111EEF84E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC3CCB92-1AA1-4C33-B296-D7111EEF84E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC3CCB92-1AA1-4C33-B296-D7111EEF84E4}.Release|Any CPU.Build.0 = Release|Any CPU
{845EDA2A-5207-4C6D-ABE9-9635F4630D90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{845EDA2A-5207-4C6D-ABE9-9635F4630D90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{845EDA2A-5207-4C6D-ABE9-9635F4630D90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{845EDA2A-5207-4C6D-ABE9-9635F4630D90}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{845EDA2A-5207-4C6D-ABE9-9635F4630D90} = {0CC84E67-19D2-480B-B36A-6BB15A9109E7}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions samples/MongoDbSample/MongoDbSample.csproj
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>
34 changes: 34 additions & 0 deletions samples/MongoDbSample/Program.cs
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;
}

0 comments on commit 9ca2342

Please sign in to comment.