-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
24 changed files
with
274 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Program = let [<EntryPoint>] main _ = 0 |
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,47 @@ | ||
module fsCustomerTest.Tests | ||
|
||
open System.Text.Json | ||
open Sekiban.Core.Shared | ||
open Sekiban.Testing.SingleProjections | ||
open Xunit | ||
open Xunit.Abstractions | ||
open fsCustomer.Dependency | ||
open fsCustomer.Domain | ||
|
||
[<Fact>] | ||
let ``My test`` () = Assert.True(true) | ||
|
||
|
||
|
||
|
||
type BranchSpec(testOutputHelper: ITestOutputHelper) = | ||
inherit AggregateTest<Branch, FsCustomerDependency>() | ||
member this.TestOutputHelper = testOutputHelper | ||
|
||
[<Fact>] | ||
member this.Serialize() = | ||
let serialized = SekibanJsonHelper.Serialize(Branch("Japan")) | ||
this.TestOutputHelper.WriteLine(serialized) | ||
let deserialized = SekibanJsonHelper.Deserialize<Branch>(serialized) | ||
let serializedFromDeserialized = SekibanJsonHelper.Serialize(deserialized) | ||
this.TestOutputHelper.WriteLine(serializedFromDeserialized) | ||
Assert.Equal(serialized, serializedFromDeserialized) | ||
|
||
[<Fact>] | ||
member this.SerializeOptionChecking() = | ||
let options: JsonSerializerOptions = JsonSerializerOptions() | ||
// options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull | ||
// options.PropertyNameCaseInsensitive = true | ||
let serialized = JsonSerializer.Serialize<Branch>(Branch("Japan"), options) | ||
this.TestOutputHelper.WriteLine(serialized) | ||
let deserialized = JsonSerializer.Deserialize<Branch>(serialized, options) | ||
|
||
let serializedFromDeserialized = | ||
JsonSerializer.Serialize<Branch>(deserialized, options) | ||
|
||
this.TestOutputHelper.WriteLine(serializedFromDeserialized) | ||
Assert.Equal(serialized, serializedFromDeserialized) | ||
|
||
[<Fact>] | ||
member this.CreateAggregate() = | ||
this.WhenCommand(CreateBranch("Japan")).ThenPayloadIs(Branch("Japan")) |
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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Tests.fs"/> | ||
<Compile Include="Program.fs"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0"/> | ||
<PackageReference Include="xunit" Version="2.5.0"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\samples\fsharp\fsCustomer.fsproj"/> | ||
<ProjectReference Include="..\src\Sekiban.Testing\Sekiban.Testing.csproj"/> | ||
</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,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.0", | ||
"rollForward": "latestMajor", | ||
"allowPrerelease": true | ||
} | ||
} |
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,24 @@ | ||
module fsCustomer.Dependency | ||
|
||
open System.Reflection | ||
open Sekiban.Core.Dependency | ||
open fsCustomer.Domain | ||
|
||
|
||
type FsCustomerDependency() = | ||
inherit DomainDependencyDefinitionBase() | ||
|
||
override this.Define() = | ||
do | ||
this | ||
.AddAggregate<Branch>() | ||
.AddCommandHandler<CreateBranch, CreateBranchHandler>() | ||
|> ignore | ||
|
||
this | ||
.AddAggregate<Client>() | ||
.AddCommandHandler<CreateClient, CreateClientHandler>() | ||
.AddAggregateQuery<ClientEmailExistsQuery>() | ||
|> ignore | ||
|
||
override this.GetExecutingAssembly() = Assembly.GetExecutingAssembly() |
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,92 @@ | ||
module fsCustomer.Domain | ||
|
||
open System | ||
open System.Text.Json.Serialization | ||
open FSharp.Control | ||
open Sekiban.Core.Aggregate | ||
open Sekiban.Core.Command | ||
open Sekiban.Core.Events | ||
open Sekiban.Core.Query.QueryModel | ||
|
||
type Branch [<JsonConstructor>] (name: string) = | ||
member this.Name = name | ||
interface IAggregatePayload | ||
new() = Branch("") | ||
|
||
type CreateBranch(name: string) = | ||
member this.Name = name | ||
|
||
interface ICommand<Branch> with | ||
member this.GetAggregateId() = Guid.NewGuid() | ||
|
||
type BranchCreated = | ||
{ Name: string } | ||
|
||
interface IEventPayload<Branch, Branch, BranchCreated> with | ||
static member OnEvent(aggregatePayload, ev) = Branch(ev.Payload.Name) | ||
|
||
type CreateBranchHandler() = | ||
interface ICommandHandler<Branch, CreateBranch> with | ||
member this.HandleCommandAsync(getAggregateState, command) = | ||
taskSeq { yield { Name = command.Name } :> IEventPayloadApplicableTo<Branch> } | ||
|
||
|
||
type Client(name: string, email: string, branchId: Guid) = | ||
member this.Name = name | ||
member this.Email = email | ||
member this.BranchId = branchId | ||
interface IAggregatePayload | ||
new() = Client("", "", Guid.Empty) | ||
|
||
type CreateClient = | ||
{ Name: string | ||
Email: string | ||
BranchId: Guid } | ||
|
||
interface ICommand<Client> with | ||
member this.GetAggregateId() = Guid.NewGuid() | ||
|
||
type ClientCreated = | ||
{ Name: string | ||
Email: string | ||
BranchId: Guid } | ||
|
||
interface IEventPayload<Client, Client, ClientCreated> with | ||
static member OnEvent(aggregatePayload, ev) = | ||
Client(ev.Payload.Name, ev.Payload.Email, ev.Payload.BranchId) | ||
|
||
type ClientEmailExistsQueryResponse = | ||
{ Exists: bool } | ||
|
||
interface IQueryResponse | ||
|
||
type ClientEmailExistsQueryParam = | ||
{ Email: string } | ||
|
||
interface IQueryParameter<ClientEmailExistsQueryResponse> | ||
|
||
|
||
|
||
type ClientEmailExistsQuery = | ||
interface IAggregateQuery<Client, ClientEmailExistsQueryParam, ClientEmailExistsQueryResponse> with | ||
member this.HandleFilter(queryParam, list) = | ||
{ Exists = list |> Seq.exists (fun client -> client.Payload.Email = queryParam.Email) } | ||
|
||
type CreateClientHandler(queryExecutor: IQueryExecutor) = | ||
member this.QueryExecutor = queryExecutor | ||
|
||
interface ICommandHandler<Client, CreateClient> with | ||
member this.HandleCommandAsync(getAggregateState, command) = | ||
taskSeq { | ||
let branchExistsResponse = | ||
this.QueryExecutor.ExecuteAsync({ Email = command.Email }) | ||
|> Async.AwaitTask | ||
|> Async.RunSynchronously | ||
|
||
if branchExistsResponse.Exists then | ||
yield | ||
{ Name = command.Name | ||
Email = command.Email | ||
BranchId = command.BranchId } | ||
:> IEventPayloadApplicableTo<Client> | ||
} |
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 fsCustomer | ||
|
||
module Say = | ||
let hello name = | ||
printfn "Hello %s" name |
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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<LangVersion>default</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Library.fs"/> | ||
<Compile Include="Domain.fs"/> | ||
<Compile Include="Dependency.fs"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Sekiban.Core\Sekiban.Core.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FSharp.Control.AsyncSeq" Version="3.2.1"/> | ||
<PackageReference Include="FSharp.Control.TaskSeq" Version="0.3.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
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
Oops, something went wrong.