Skip to content

Commit

Permalink
Added basic files structure of EventStoreDB Application Logic and Opt…
Browse files Browse the repository at this point in the history
…imistic Concurrency tests based on the Marten versions

Removed also obsolete EventStoreDB business logic tests
  • Loading branch information
oskardudycz committed May 2, 2024
1 parent 919c733 commit 91f1a7a
Show file tree
Hide file tree
Showing 162 changed files with 7,791 additions and 3,697 deletions.
@@ -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>
@@ -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;
}
}
@@ -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));
}
@@ -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));
}
@@ -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));
}

0 comments on commit 91f1a7a

Please sign in to comment.