Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic files structure of EventStoreDB Application Logic and Opt…
…imistic Concurrency tests based on the Marten versions Removed also obsolete EventStoreDB business logic tests
- Loading branch information
1 parent
919c733
commit 91f1a7a
Showing
162 changed files
with
7,791 additions
and
3,697 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...cing/09-ApplicationLogic.EventStoreDB.Tests/09-ApplicationLogic.EventStoreDB.Tests.csproj
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>ApplicationLogic.Marten.Tests</RootNamespace> | ||
<AssemblyName>ApplicationLogic.Marten.Tests</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="NSubstitute" Version="5.1.0" /> | ||
<PackageReference Include="xunit" Version="2.7.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.4" /> | ||
<PackageReference Include="Ogooreck" Version="0.8.0" /> | ||
<PackageReference Include="Bogus" Version="35.5.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\08-ApplicationLogic.Marten\08-ApplicationLogic.Marten.csproj" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\..\Tests.Build.props" /> | ||
|
||
</Project> |
18 changes: 18 additions & 0 deletions
18
Workshops/IntroductionToEventSourcing/09-ApplicationLogic.EventStoreDB.Tests/Settings.cs
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,18 @@ | ||
using Oakton; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
[assembly: TestFramework("ApplicationLogic.Marten.Tests.AssemblyFixture", "ApplicationLogic.Marten.Tests")] | ||
[assembly: CollectionBehavior(DisableTestParallelization = true)] | ||
|
||
namespace ApplicationLogic.Marten.Tests; | ||
|
||
public sealed class AssemblyFixture : XunitTestFramework | ||
{ | ||
public AssemblyFixture(IMessageSink messageSink) | ||
:base(messageSink) | ||
{ | ||
OaktonEnvironment.AutoStartHost = true; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
...09-ApplicationLogic.EventStoreDB.Tests/ShoppingCarts/AddProductItemToShoppingCartTests.cs
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,118 @@ | ||
using ApplicationLogic.Marten.Immutable.ShoppingCarts; | ||
using Bogus; | ||
using Ogooreck.API; | ||
using Xunit; | ||
using static Ogooreck.API.ApiSpecification; | ||
using static ApplicationLogic.Marten.Tests.ShoppingCarts.Scenarios; | ||
using static ApplicationLogic.Marten.Tests.ShoppingCarts.Fixtures; | ||
|
||
namespace ApplicationLogic.Marten.Tests.ShoppingCarts; | ||
|
||
public class AddProductItemToShoppingCartTests(ApiSpecification<Program> api): | ||
IClassFixture<ApiSpecification<Program>> | ||
{ | ||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantAddProductItemToNotExistingShoppingCart(string apiPrefix) => | ||
api.Given() | ||
.When( | ||
POST, | ||
URI(ShoppingCartProductItemsUrl(apiPrefix, ClientId, NotExistingShoppingCartId)), | ||
BODY(new AddProductRequest(ProductItem)) | ||
) | ||
.Then(NOT_FOUND); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task AddsProductItemToEmptyShoppingCart(string apiPrefix) => | ||
api.Given(OpenedShoppingCart(apiPrefix, ClientId)) | ||
.When( | ||
POST, | ||
URI(ctx => ShoppingCartProductItemsUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())), | ||
BODY(new AddProductRequest(ProductItem)) | ||
) | ||
.Then(NO_CONTENT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task AddsProductItemToNonEmptyShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem) | ||
) | ||
.When( | ||
POST, | ||
URI(ctx => ShoppingCartProductItemsUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())), | ||
BODY(new AddProductRequest(ProductItem)) | ||
) | ||
.Then(NO_CONTENT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantAddProductItemToConfirmedShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenConfirmed(apiPrefix, ClientId) | ||
) | ||
.When( | ||
POST, | ||
URI(ctx => ShoppingCartProductItemsUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())), | ||
BODY(new AddProductRequest(ProductItem)) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantAddProductItemToCanceledShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenCanceled(apiPrefix, ClientId) | ||
) | ||
.When( | ||
POST, | ||
URI(ctx => ShoppingCartProductItemsUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())), | ||
BODY(new AddProductRequest(ProductItem)) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task ReturnsNonEmptyShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem) | ||
) | ||
.When(GET, URI(ctx => ShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>()))) | ||
.Then(OK); | ||
|
||
private static readonly Faker Faker = new(); | ||
private readonly Guid NotExistingShoppingCartId = Guid.NewGuid(); | ||
private readonly Guid ClientId = Guid.NewGuid(); | ||
private readonly ProductItemRequest ProductItem = new(Guid.NewGuid(), Faker.Random.Number(1, 500)); | ||
} |
100 changes: 100 additions & 0 deletions
100
...tSourcing/09-ApplicationLogic.EventStoreDB.Tests/ShoppingCarts/CancelShoppingCartTests.cs
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,100 @@ | ||
using ApplicationLogic.Marten.Immutable.ShoppingCarts; | ||
using Bogus; | ||
using Ogooreck.API; | ||
using Xunit; | ||
using static Ogooreck.API.ApiSpecification; | ||
using static ApplicationLogic.Marten.Tests.ShoppingCarts.Scenarios; | ||
using static ApplicationLogic.Marten.Tests.ShoppingCarts.Fixtures; | ||
|
||
namespace ApplicationLogic.Marten.Tests.ShoppingCarts; | ||
|
||
public class CancelShoppingCartTests(ApiSpecification<Program> api): | ||
IClassFixture<ApiSpecification<Program>> | ||
{ | ||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantCancelNotExistingShoppingCart(string apiPrefix) => | ||
api.Given() | ||
.When( | ||
DELETE, | ||
URI(ShoppingCartUrl(apiPrefix, ClientId, NotExistingShoppingCartId)) | ||
) | ||
.Then(NOT_FOUND); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CancelsNonEmptyShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem) | ||
) | ||
.When( | ||
DELETE, | ||
URI(ctx => ShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(NO_CONTENT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantCancelAlreadyCanceledShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenCanceled(apiPrefix, ClientId) | ||
) | ||
.When( | ||
DELETE, | ||
URI(ctx => ShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantCancelConfirmedShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenConfirmed(apiPrefix, ClientId) | ||
) | ||
.When( | ||
DELETE, | ||
URI(ctx => ShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task ReturnsNonEmptyShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenCanceled(apiPrefix, ClientId) | ||
) | ||
.When(GET, URI(ctx => ShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>()))) | ||
.Then(OK); | ||
|
||
private static readonly Faker Faker = new(); | ||
private readonly Guid NotExistingShoppingCartId = Guid.NewGuid(); | ||
private readonly Guid ClientId = Guid.NewGuid(); | ||
private readonly ProductItemRequest ProductItem = new(Guid.NewGuid(), Faker.Random.Number(1, 500)); | ||
} |
114 changes: 114 additions & 0 deletions
114
...Sourcing/09-ApplicationLogic.EventStoreDB.Tests/ShoppingCarts/ConfirmShoppingCartTests.cs
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,114 @@ | ||
using ApplicationLogic.Marten.Immutable.ShoppingCarts; | ||
using Bogus; | ||
using Ogooreck.API; | ||
using Xunit; | ||
using static Ogooreck.API.ApiSpecification; | ||
using static ApplicationLogic.Marten.Tests.ShoppingCarts.Scenarios; | ||
using static ApplicationLogic.Marten.Tests.ShoppingCarts.Fixtures; | ||
|
||
namespace ApplicationLogic.Marten.Tests.ShoppingCarts; | ||
|
||
public class ConfirmShoppingCartTests(ApiSpecification<Program> api): | ||
IClassFixture<ApiSpecification<Program>> | ||
{ | ||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantConfirmNotExistingShoppingCart(string apiPrefix) => | ||
api.Given() | ||
.When( | ||
POST, | ||
URI(ConfirmShoppingCartUrl(apiPrefix, ClientId, NotExistingShoppingCartId)) | ||
) | ||
.Then(NOT_FOUND); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantConfirmEmptyShoppingCart(string apiPrefix) => | ||
api.Given(OpenedShoppingCart(apiPrefix, ClientId)) | ||
.When( | ||
POST, | ||
URI(ctx => ConfirmShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task ConfirmsNonEmptyShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem) | ||
) | ||
.When( | ||
POST, | ||
URI(ctx => ConfirmShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(NO_CONTENT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantConfirmAlreadyConfirmedShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenConfirmed(apiPrefix, ClientId) | ||
) | ||
.When( | ||
POST, | ||
URI(ctx => ConfirmShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task CantConfirmCanceledShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenCanceled(apiPrefix, ClientId) | ||
) | ||
.When( | ||
POST, | ||
URI(ctx => ConfirmShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>())) | ||
) | ||
.Then(CONFLICT); | ||
|
||
|
||
[Theory] | ||
[Trait("Category", "SkipCI")] | ||
[InlineData("immutable")] | ||
[InlineData("mutable")] | ||
[InlineData("mixed")] | ||
public Task ReturnsNonEmptyShoppingCart(string apiPrefix) => | ||
api.Given( | ||
OpenedShoppingCart(apiPrefix, ClientId), | ||
WithProductItem(apiPrefix, ClientId, ProductItem), | ||
ThenConfirmed(apiPrefix, ClientId) | ||
) | ||
.When(GET, URI(ctx => ShoppingCartUrl(apiPrefix, ClientId, ctx.GetCreatedId<Guid>()))) | ||
.Then(OK); | ||
|
||
private static readonly Faker Faker = new(); | ||
private readonly Guid NotExistingShoppingCartId = Guid.NewGuid(); | ||
private readonly Guid ClientId = Guid.NewGuid(); | ||
private readonly ProductItemRequest ProductItem = new(Guid.NewGuid(), Faker.Random.Number(1, 500)); | ||
} |
Oops, something went wrong.