Skip to content

Commit

Permalink
Added Postgres Embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed May 6, 2024
1 parent ffb3e70 commit 0366d44
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 8 deletions.
Expand Up @@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MysticMind.PostgresEmbed" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Expand Up @@ -79,8 +79,12 @@ public async Task AppendingEvents_ForSequenceOfEvents_ShouldSucceed()
new ShoppingCartCanceled(shoppingCartId, DateTime.UtcNow)
};

const string connectionString =
"PORT = 5432; HOST = localhost; TIMEOUT = 15; POOLING = True; DATABASE = 'postgres'; PASSWORD = 'Password12!'; USER ID = 'postgres'";
await using var server = new MysticMind.PostgresEmbed.PgServer("15.3.0");

await server.StartAsync();
// using Npgsql to connect the server
var connectionString =
$"Server=localhost;Port={server.PgPort};User Id=postgres;Password=test;Database=postgres";

using var documentStore = DocumentStore.For(options =>
{
Expand Down
Expand Up @@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MysticMind.PostgresEmbed" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
@@ -1,17 +1,26 @@
using Marten;
using MysticMind.PostgresEmbed;

namespace IntroductionToEventSourcing.GettingStateFromEvents.Tools;

public abstract class MartenTest: IDisposable
{
private readonly DocumentStore documentStore;
protected readonly IDocumentSession DocumentSession;
protected readonly PgServer PgServer;

protected MartenTest()
{
PgServer = new PgServer("15.3.0");

PgServer.Start();
// using Npgsql to connect the server
var connectionString =
$"Server=localhost;Port={PgServer.PgPort};User Id=postgres;Password=test;Database=postgres";


var options = new StoreOptions();
options.Connection(
"PORT = 5432; HOST = localhost; TIMEOUT = 15; POOLING = True; DATABASE = 'postgres'; PASSWORD = 'Password12!'; USER ID = 'postgres'");
options.Connection(connectionString);
options.UseNewtonsoftForSerialization(nonPublicMembersStorage: NonPublicMembersStorage.All);
options.DatabaseSchemaName = options.Events.DatabaseSchemaName = "IntroductionToEventSourcing";

Expand All @@ -32,5 +41,6 @@ public virtual void Dispose()
{
DocumentSession.Dispose();
documentStore.Dispose();
PgServer.Dispose();
}
}
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Marten.CommandLine" Version="7.10.1" />
<PackageReference Include="MysticMind.PostgresEmbed" Version="4.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Marten.AspNetCore" Version="7.10.1" />
<PackageReference Include="Marten" Version="7.10.1" />
Expand Down
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Marten.CommandLine" Version="7.10.1" />
<PackageReference Include="MysticMind.PostgresEmbed" Version="4.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Marten.AspNetCore" Version="7.10.1" />
<PackageReference Include="Marten" Version="7.10.1" />
Expand Down
Expand Up @@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MysticMind.PostgresEmbed" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Expand Up @@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MysticMind.PostgresEmbed" Version="4.0.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
Expand Up @@ -4,6 +4,7 @@
using Xunit;

namespace IntroductionToEventSourcing.AppendingEvents;

using static ShoppingCartEvent;

// EVENTS
Expand Down Expand Up @@ -35,7 +36,7 @@ DateTime CanceledAt
): ShoppingCartEvent;

// This won't allow external inheritance
private ShoppingCartEvent(){}
private ShoppingCartEvent() { }
}

// VALUE OBJECTS
Expand Down Expand Up @@ -88,10 +89,13 @@ public async Task AppendingEvents_ForSequenceOfEvents_ShouldSucceed()
new ShoppingCartCanceled(shoppingCartId, DateTime.UtcNow)
};

const string connectionString =
"PORT = 5432; HOST = localhost; TIMEOUT = 15; POOLING = True; DATABASE = 'postgres'; PASSWORD = 'Password12!'; USER ID = 'postgres'";
await using var server = new MysticMind.PostgresEmbed.PgServer("15.3.0");

await server.StartAsync();
// using Npgsql to connect the server
var connectionString = $"Server=localhost;Port={server.PgPort};User Id=postgres;Password=test;Database=postgres";

using var documentStore = DocumentStore.For(options =>
await using var documentStore = DocumentStore.For(options =>
{
options.Connection(connectionString);
options.DatabaseSchemaName = options.Events.DatabaseSchemaName = "IntroductionToEventSourcing";
Expand Down

0 comments on commit 0366d44

Please sign in to comment.