-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eea2fa
commit 2f0415a
Showing
17 changed files
with
250 additions
and
75 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Eventuous.Tests.Fakes; | ||
using Eventuous.TestHelpers.Fakes; | ||
|
||
namespace Eventuous.Tests.Fixtures; | ||
|
||
|
39 changes: 39 additions & 0 deletions
39
src/Extensions/src/Eventuous.AspNetCore.Web/ApplicationServiceRouteBuilder.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,39 @@ | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
namespace Eventuous.AspNetCore.Web; | ||
|
||
[PublicAPI] | ||
public class ApplicationServiceRouteBuilder<T> where T : Aggregate { | ||
readonly IEndpointRouteBuilder _builder; | ||
|
||
public ApplicationServiceRouteBuilder(IEndpointRouteBuilder builder) => _builder = builder; | ||
|
||
/// <summary> | ||
/// Maps the given command type to an HTTP endpoint. The command class can be annotated with | ||
/// the <seealso cref="HttpCommandAttribute"/> if you need a custom route. | ||
/// </summary> | ||
/// <param name="enrichCommand">A function to populate command props from HttpContext</param> | ||
/// <typeparam name="TCommand">Command class</typeparam> | ||
/// <returns></returns> | ||
public ApplicationServiceRouteBuilder<T> MapCommand<TCommand>( | ||
EnrichCommandFromHttpContext<TCommand>? enrichCommand = null | ||
) where TCommand : class { | ||
_builder.MapCommand<TCommand, T>(enrichCommand); | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Maps the given command type to an HTTP endpoint using the specified route. | ||
/// </summary> | ||
/// <param name="route">HTTP route for the command</param> | ||
/// <param name="enrichCommand">A function to populate command props from HttpContext</param> | ||
/// <typeparam name="TCommand">Command type</typeparam> | ||
/// <returns></returns> | ||
public ApplicationServiceRouteBuilder<T> MapCommand<TCommand>( | ||
string route, | ||
EnrichCommandFromHttpContext<TCommand>? enrichCommand = null | ||
) where TCommand : class { | ||
_builder.MapCommand<TCommand, T>(route, enrichCommand); | ||
return this; | ||
} | ||
} |
23 changes: 12 additions & 11 deletions
23
src/Extensions/src/Eventuous.AspNetCore.Web/Eventuous.AspNetCore.Web.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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<ProjectReference Include="$(DiagRoot)\Eventuous.Diagnostics\Eventuous.Diagnostics.csproj"/> | ||
<ProjectReference Include="$(DiagRoot)\Eventuous.Diagnostics.Logging\Eventuous.Diagnostics.Logging.csproj"/> | ||
<ProjectReference Include="$(CoreRoot)\Eventuous\Eventuous.csproj"/> | ||
<ProjectReference Include="..\Eventuous.AspNetCore\Eventuous.AspNetCore.csproj"/> | ||
<Using Include="Eventuous"/> | ||
<Using Include="Microsoft.Extensions.DependencyInjection"/> | ||
<Using Include="Microsoft.AspNetCore.Mvc"/> | ||
<ProjectReference Include="$(DiagRoot)\Eventuous.Diagnostics\Eventuous.Diagnostics.csproj" /> | ||
<ProjectReference Include="$(DiagRoot)\Eventuous.Diagnostics.Logging\Eventuous.Diagnostics.Logging.csproj" /> | ||
<ProjectReference Include="$(CoreRoot)\Eventuous\Eventuous.csproj" /> | ||
<ProjectReference Include="..\Eventuous.AspNetCore\Eventuous.AspNetCore.csproj" /> | ||
<Using Include="Eventuous" /> | ||
<Using Include="Microsoft.Extensions.DependencyInjection" /> | ||
<Using Include="Microsoft.AspNetCore.Mvc" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App"/> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'"> | ||
<Compile Remove="RouteBuilderExtensions.cs"/> | ||
<Compile Remove="HttpCommandAttribute.cs"/> | ||
<Compile Remove="ResultExtensions.cs"/> | ||
<Compile Remove="RouteBuilderExtensions.cs" /> | ||
<Compile Remove="HttpCommandAttribute.cs" /> | ||
<Compile Remove="ResultExtensions.cs" /> | ||
<Compile Remove="ApplicationServiceRouteBuilder.cs" /> | ||
</ItemGroup> | ||
</Project> |
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
23 changes: 23 additions & 0 deletions
23
src/Extensions/test/Eventuous.Sut.AspNetCore/BookingService.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,23 @@ | ||
using Eventuous.AspNetCore.Web; | ||
using Eventuous.Sut.Domain; | ||
using NodaTime; | ||
|
||
namespace Eventuous.Sut.AspNetCore; | ||
|
||
public class BookingService : ApplicationService<Booking, BookingState, BookingId> { | ||
public BookingService(IAggregateStore store, StreamNameMap? streamNameMap = null) | ||
: base(store, streamNameMap: streamNameMap) | ||
=> OnNew<BookRoom>( | ||
(booking, cmd) | ||
=> booking.BookRoom( | ||
new BookingId(cmd.BookingId), | ||
cmd.RoomId, | ||
new StayPeriod(cmd.CheckIn, cmd.CheckOut), | ||
cmd.Price, | ||
cmd.GuestId | ||
) | ||
); | ||
} | ||
|
||
[HttpCommand(Route = "book")] | ||
record BookRoom(string BookingId, string RoomId, LocalDate CheckIn, LocalDate CheckOut, decimal Price, string? GuestId); |
18 changes: 18 additions & 0 deletions
18
src/Extensions/test/Eventuous.Sut.AspNetCore/Eventuous.Sut.AspNetCore.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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<IncludeSutApp>true</IncludeSutApp> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(CoreRoot)\Eventuous\Eventuous.csproj" /> | ||
<ProjectReference Include="$(LocalRoot)\Eventuous.AspNetCore.Web\Eventuous.AspNetCore.Web.csproj" /> | ||
<ProjectReference Include="$(LocalRoot)\Eventuous.AspNetCore\Eventuous.AspNetCore.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<InternalsVisibleTo Include="Eventuous.Tests.AspNetCore.Web" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> |
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,27 @@ | ||
using System.Text.Json; | ||
using Eventuous.Sut.AspNetCore; | ||
using Eventuous.Sut.Domain; | ||
using Microsoft.AspNetCore.Http.Json; | ||
using NodaTime; | ||
using NodaTime.Serialization.SystemTextJson; | ||
using BookingService = Eventuous.Sut.AspNetCore.BookingService; | ||
|
||
DefaultEventSerializer.SetDefaultSerializer( | ||
new DefaultEventSerializer( | ||
new JsonSerializerOptions(JsonSerializerDefaults.Web).ConfigureForNodaTime(DateTimeZoneProviders.Tzdb) | ||
) | ||
); | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.AddApplicationService<BookingService, Booking>(); | ||
|
||
builder.Services.Configure<JsonOptions>( | ||
options => options.SerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb) | ||
); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapAggregateCommands<Booking>() | ||
.MapCommand<BookRoom>((cmd, _) => cmd with { GuestId = TestData.GuestId }); | ||
|
||
app.Run(); |
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,5 @@ | ||
namespace Eventuous.Sut.AspNetCore; | ||
|
||
public static class TestData { | ||
public const string GuestId = "test guest"; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Extensions/test/Eventuous.Sut.AspNetCore/appsettings.json
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,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
10 changes: 7 additions & 3 deletions
10
src/Extensions/test/Eventuous.Tests.AspNetCore.Web/Eventuous.Tests.AspNetCore.Web.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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<IsTestProject>true</IsTestProject> | ||
<IncludeSutApp>true</IncludeSutApp> | ||
<IncludeTestHelpers>true</IncludeTestHelpers> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(CoreRoot)\Eventuous\Eventuous.csproj" /> | ||
<ProjectReference Include="$(LocalRoot)\Eventuous.AspNetCore.Web\Eventuous.AspNetCore.Web.csproj" /> | ||
<ProjectReference Include="..\Eventuous.Sut.AspNetCore\Eventuous.Sut.AspNetCore.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(LocalRoot)\Eventuous.AspNetCore.Web\Eventuous.AspNetCore.Web.csproj" /> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" /> | ||
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.0.0" /> | ||
<PackageReference Include="RestSharp" Version="107.3.0" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.