Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pragmatic Event Sourcing with Marten using Helpdesk domain #161

Merged
merged 6 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Core.Testing/Core.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
Expand All @@ -14,7 +15,7 @@
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.6" />
<PackageReference Include="Ogooreck" Version="0.1.1" />
<PackageReference Include="Ogooreck" Version="0.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions EventSourcing.NetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Warehouse.MinimalAPI", "War
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Warehouse.Api", "Sample\Warehouse.MinimalAPI\Warehouse.Api\Warehouse.Api.csproj", "{723AD8CE-E3EF-40F6-9576-CCF2C3DB504E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Helpdesk", "Helpdesk", "{DC817F16-C74C-4133-B263-72ED456DB95A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Helpdesk.Api", "Sample\Helpdesk\Helpdesk.Api\Helpdesk.Api.csproj", "{7F6C6387-4933-4895-AA31-9E3CAFFAE24E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Helpdesk.Api.Tests", "Sample\Helpdesk\Helpdesk.Api.Tests\Helpdesk.Api.Tests.csproj", "{525AA67F-1D3A-4752-9A3F-A6A82819CF70}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -743,6 +749,14 @@ Global
{723AD8CE-E3EF-40F6-9576-CCF2C3DB504E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{723AD8CE-E3EF-40F6-9576-CCF2C3DB504E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{723AD8CE-E3EF-40F6-9576-CCF2C3DB504E}.Release|Any CPU.Build.0 = Release|Any CPU
{7F6C6387-4933-4895-AA31-9E3CAFFAE24E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F6C6387-4933-4895-AA31-9E3CAFFAE24E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F6C6387-4933-4895-AA31-9E3CAFFAE24E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F6C6387-4933-4895-AA31-9E3CAFFAE24E}.Release|Any CPU.Build.0 = Release|Any CPU
{525AA67F-1D3A-4752-9A3F-A6A82819CF70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{525AA67F-1D3A-4752-9A3F-A6A82819CF70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{525AA67F-1D3A-4752-9A3F-A6A82819CF70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{525AA67F-1D3A-4752-9A3F-A6A82819CF70}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -874,6 +888,9 @@ Global
{A5A2A4CB-08F6-49AE-B044-DD9C5F8B0F48} = {65F6E2BE-B2D4-4E56-B0CB-3062C4882B9E}
{005FC7CE-97BA-47F7-982E-63C46327F78C} = {A7186B6B-D56D-4AEF-B6B7-FAA827764C34}
{723AD8CE-E3EF-40F6-9576-CCF2C3DB504E} = {005FC7CE-97BA-47F7-982E-63C46327F78C}
{DC817F16-C74C-4133-B263-72ED456DB95A} = {A7186B6B-D56D-4AEF-B6B7-FAA827764C34}
{7F6C6387-4933-4895-AA31-9E3CAFFAE24E} = {DC817F16-C74C-4133-B263-72ED456DB95A}
{525AA67F-1D3A-4752-9A3F-A6A82819CF70} = {DC817F16-C74C-4133-B263-72ED456DB95A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A5F55604-2FF3-43B7-B657-4F18E6E95D3B}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public async Task InitializeAsync()
);

await CREATED(openResponse);
await RESPONSE_LOCATION_HEADER()(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
using Carts.ShoppingCarts.GettingCartById;
using Carts.ShoppingCarts.Products;
using Core.Testing;
using Ogooreck.API;
using Xunit;
using Ogooreck.API;
using static Ogooreck.API.ApiSpecification;

namespace Carts.Api.Tests.ShoppingCarts.Opening;

public class OpenShoppingCartTests: IClassFixture<TestWebApplicationFactory<Program>>
{
private readonly ApiSpecification<Program> API;

[Fact]
public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
API.Scenario(
Expand All @@ -21,7 +19,7 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
BODY(new OpenShoppingCartRequest(ClientId))
)
.When(POST)
.Then(CREATED),
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1)),

response =>
API.Given(
Expand All @@ -43,5 +41,6 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
public OpenShoppingCartTests(TestWebApplicationFactory<Program> fixture) =>
API = ApiSpecification<Program>.Setup(fixture);

public readonly Guid ClientId = Guid.NewGuid();
private readonly ApiSpecification<Program> API;
private readonly Guid ClientId = Guid.NewGuid();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 1)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Task InitializeOrder_ShouldReturn_CreatedStatus_With_OrderId() =>
))
)
.When(POST)
.Then(CREATED);
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1));

private readonly Guid ClientId = Guid.NewGuid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Task RequestPayment_ShouldReturn_CreatedStatus_With_PaymentId() =>
BODY(new RequestPaymentRequest {OrderId = OrderId, Amount = Amount})
)
.When(POST)
.Then(CREATED);
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 1));

private readonly Guid OrderId = Guid.NewGuid();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Task SendPackage_ShouldReturn_CreatedStatus_With_PackageId() =>
BODY(new SendPackage(OrderId, ProductItems))
)
.When(POST)
.Then(CREATED)
.Then(CREATED_WITH_DEFAULT_HEADERS())
.And(response => fixture.ShouldPublishInternalEventOfType<PackageWasSent>(
@event =>
@event.PackageId == response.GetCreatedId<Guid>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
BODY(new OpenShoppingCartRequest(ClientId))
)
.When(POST)
.Then(CREATED),
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 0)),

response =>
API.Given(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Task Post_ShouldReturn_CreatedStatus_With_CartId() =>
BODY(new OpenShoppingCartRequest(ClientId))
)
.When(POST)
.Then(CREATED),
.Then(CREATED_WITH_DEFAULT_HEADERS(eTag: 0)),

response =>
API.Given(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task InitializeAsync()
new ApiRequest(POST, URI("/api/ShoppingCarts"), BODY(new OpenShoppingCartRequest(ClientId)))
);

await CREATED(openResponse);
await CREATED_WITH_DEFAULT_HEADERS(eTag: 0)(openResponse);

ShoppingCartId = openResponse.GetCreatedId<Guid>();

Expand Down
27 changes: 27 additions & 0 deletions Sample/Helpdesk/Helpdesk.Api.Tests/Helpdesk.Api.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core.Testing\Core.Testing.csproj" />
<ProjectReference Include="..\Helpdesk.Api\Helpdesk.Api.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class AcknowledgeResolutionIncidentTests: IClassFixture<ApiWithResolvedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task ResolveCommand_Succeeds()
{
await API
.Given(
URI($"/api/customers/{API.Incident.CustomerId}/incidents/{API.Incident.Id}/acknowledge"),
HEADERS(IF_MATCH(2))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.Incident.Id}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Incident with
{
Status = IncidentStatus.ResolutionAcknowledgedByCustomer,
Version = 3
}
)
);
}

private readonly ApiWithResolvedIncident API;

public AcknowledgeResolutionIncidentTests(ApiWithResolvedIncident api) => API = api;
}
40 changes: 40 additions & 0 deletions Sample/Helpdesk/Helpdesk.Api.Tests/Incidents/AssignAgentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class AssignAgentToIncidentTests: IClassFixture<ApiWithLoggedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task AssignAgentCommand_ChangesIncidentCategory()
{
await API
.Given(
URI($"/api/agents/{agentId}/incidents/{API.Incident.Id}/assign"),
HEADERS(IF_MATCH(1))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.Incident.Id}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Incident with
{
AgentId = agentId,
Version = 2
}
)
);
}

private readonly Guid agentId = Guid.NewGuid();
private readonly ApiWithLoggedIncident API;

public AssignAgentToIncidentTests(ApiWithLoggedIncident api) => API = api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Bogus;
using Helpdesk.Api.Incidents;
using Helpdesk.Api.Tests.Incidents.Fixtures;
using Xunit;
using static Ogooreck.API.ApiSpecification;

namespace Helpdesk.Api.Tests.Incidents;

public class CategoriseIncidentTests: IClassFixture<ApiWithLoggedIncident>
{
[Fact]
[Trait("Category", "Acceptance")]
public async Task CategoriseCommand_ChangesIncidentCategory()
{
await API
.Given(
URI($"/api/agents/{agentId}/incidents/{API.Incident.Id}/category"),
BODY(new CategoriseIncidentRequest(category)),
HEADERS(IF_MATCH(1))
)
.When(POST)
.Then(OK);

await API
.Given(URI($"/api/incidents/{API.Incident.Id}"))
.When(GET)
.Then(
OK,
RESPONSE_BODY(
API.Incident with
{
Category = category,
Version = 2
}
)
);
}

private readonly Guid agentId = Guid.NewGuid();
private readonly IncidentCategory category = new Faker().PickRandom<IncidentCategory>();
private readonly ApiWithLoggedIncident API;

public CategoriseIncidentTests(ApiWithLoggedIncident api) => API = api;

}
Loading