-
Notifications
You must be signed in to change notification settings - Fork 16
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
Showing
34 changed files
with
1,818 additions
and
5 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
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "@bartelink", | ||
"classifications": [ | ||
"Equinox", | ||
"Propulsion", | ||
"Event Sourcing", | ||
"Process Manager" | ||
], | ||
"tags": { | ||
"language": "F#", | ||
"type": "solution" | ||
}, | ||
"identity": "Propulsion.Hotel", | ||
"name": "Propulsion Hotel Sample", | ||
"shortName": "proHotel", | ||
"sourceName": "Hotel", | ||
"preferNameDirectory": true, | ||
"symbols": { | ||
"skipIntegrationTests": { | ||
"type": "parameter", | ||
"datatype": "bool", | ||
"isRequired": false, | ||
"defaultValue": "false", | ||
"description": "Add Skip attribute to integration tests" | ||
} | ||
} | ||
} |
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,13 @@ | ||
[<Microsoft.FSharp.Core.AutoOpen>] | ||
module Domain.Tests.Arbitraries | ||
|
||
open Domain | ||
open FsCheck.FSharp | ||
|
||
/// For unit tests, we only ever use the Domain Services wired to a MemoryStore, so we default Store to that | ||
type Generators = | ||
|
||
static member MemoryStore = Gen.constant (Config.Store.Memory <| Equinox.MemoryStore.VolatileStore()) | ||
static member Store = Arb.fromGen Generators.MemoryStore | ||
|
||
[<assembly: FsCheck.Xunit.Properties(Arbitrary = [| typeof<Generators> |])>] do () |
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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<WarningLevel>5</WarningLevel> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
|
||
<PackageReference Include="FsCheck.Xunit" Version="3.0.0-beta2" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Domain\Domain.fsproj" /> | ||
<ProjectReference Include="..\Reactor\Reactor.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Arbitraries.fs" /> | ||
<Compile Include="GroupCheckoutFlow.fs" /> | ||
</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,44 @@ | ||
module Domain.Tests.GroupCheckoutFlow | ||
|
||
open Domain | ||
open FsCheck | ||
open FsCheck.Xunit | ||
open Reactor | ||
open Swensen.Unquote | ||
|
||
[<Property>] | ||
let ``Happy path including Reaction`` (store, groupCheckoutId, paymentId, stays : _ []) = async { | ||
let staysService = GuestStay.Config.create store | ||
let sut = GroupCheckout.Config.create store | ||
let processor = GroupCheckoutProcess.Service(staysService, sut, 2) | ||
let mutable charged = 0 | ||
for stayId, chargeId, PositiveInt amount in stays do | ||
charged <- charged + amount | ||
do! staysService.Charge(stayId, chargeId, amount) | ||
let stays = [| for stayId, _, _ in stays -> stayId |] | ||
|
||
match! sut.Merge(groupCheckoutId, stays) with | ||
// If no stays were added to the group checkout, no checkouts actions should be pending | ||
| GroupCheckout.Flow.Ready 0m -> | ||
// We'll run the Reactor, but only to confirm it is a no-op | ||
[||] =! stays | ||
match! processor.React(groupCheckoutId) with | ||
| GroupCheckoutProcess.Outcome.Noop, _ -> () | ||
| GroupCheckoutProcess.Outcome.Merged _, _ -> failwith "Should be noop" | ||
// If any stays have been added, they should be recorded, and work should be triggered | ||
| GroupCheckout.Flow.MergeStays staysToDo -> | ||
staysToDo =! stays | ||
match! processor.React(groupCheckoutId) with | ||
| GroupCheckoutProcess.Outcome.Merged (ok, fail), _ -> test <@ ok = stays.Length && 0 = fail @> | ||
| GroupCheckoutProcess.Outcome.Noop, _ -> failwith "Should not be noop" | ||
// We should not end up in any other states | ||
| GroupCheckout.Flow.Ready _ | ||
| GroupCheckout.Flow.Finished -> failwith "unexpected" | ||
|
||
do! sut.Pay(groupCheckoutId, paymentId, charged) | ||
|
||
let! _ = sut.Confirm(groupCheckoutId) | ||
|
||
let! next = sut.Read(groupCheckoutId) | ||
test <@ GroupCheckout.Flow.Finished = next @> | ||
} |
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,49 @@ | ||
module Domain.Config | ||
|
||
[<RequireQualifiedAccess; NoComparison; NoEquality>] | ||
type Store = | ||
| Memory of Equinox.MemoryStore.VolatileStore<struct (int * System.ReadOnlyMemory<byte>)> | ||
| Dynamo of Equinox.DynamoStore.DynamoStoreContext * Equinox.Core.ICache | ||
| Mdb of Equinox.MessageDb.MessageDbContext * Equinox.Core.ICache | ||
|
||
let log = Serilog.Log.ForContext("isMetric", true) | ||
let resolve cat = Equinox.Decider.resolve log cat | ||
|
||
module EventCodec = | ||
|
||
open FsCodec.SystemTextJson | ||
|
||
let private defaultOptions = Options.Create() | ||
let gen<'t when 't :> TypeShape.UnionContract.IUnionContract> = | ||
Codec.Create<'t>(options = defaultOptions) | ||
|
||
module Memory = | ||
|
||
let create codec initial fold store : Equinox.Category<_, _, _> = | ||
Equinox.MemoryStore.MemoryStoreCategory(store, FsCodec.Deflate.EncodeUncompressed codec, fold, initial) | ||
|
||
let defaultCacheDuration = System.TimeSpan.FromMinutes 20. | ||
|
||
module Dynamo = | ||
|
||
open Equinox.DynamoStore | ||
|
||
let private create codec initial fold accessStrategy (context, cache) = | ||
let cacheStrategy = CachingStrategy.SlidingWindow (cache, defaultCacheDuration) | ||
DynamoStoreCategory(context, FsCodec.Deflate.EncodeUncompressed codec, fold, initial, cacheStrategy, accessStrategy) | ||
|
||
let createUnoptimized codec initial fold (context, cache) = | ||
let accessStrategy = AccessStrategy.Unoptimized | ||
create codec initial fold accessStrategy (context, cache) | ||
|
||
module Mdb = | ||
|
||
open Equinox.MessageDb | ||
|
||
let private create codec initial fold accessStrategy (context, cache) = | ||
let cacheStrategy = CachingStrategy.SlidingWindow (cache, defaultCacheDuration) | ||
MessageDbCategory(context, codec, fold, initial, cacheStrategy, ?access = accessStrategy) | ||
|
||
let createUnoptimized codec initial fold (context, cache) = | ||
let accessStrategy = None | ||
create codec initial fold accessStrategy (context, cache) |
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<WarningLevel>5</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<!-- TODO remove, only required if you have a very old SDK --> | ||
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Equinox.DynamoStore" Version="4.0.0-rc.7" /> | ||
<PackageReference Include="Equinox.MemoryStore" Version="4.0.0-rc.7" /> | ||
<PackageReference Include="Equinox.MessageDb" Version="4.0.0-rc.7" /> | ||
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.9" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Config.fs" /> | ||
<Compile Include="Types.fs" /> | ||
<Compile Include="GuestStay.fs" /> | ||
<Compile Include="GroupCheckout.fs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.