Skip to content

Commit

Permalink
Upgraded to .NET 7, bumped dependencies and added samples with F# d35963
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Nov 17, 2022
1 parent d359631 commit 4ad5760
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: "6.0.x"
dotnet-version: "7.0.x"

- name: Restore NuGet packages
run: ./build.sh test
2 changes: 1 addition & 1 deletion .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
config: Release
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
dotnet_core_version: 6.0.x
dotnet_core_version: 7.0.x

jobs:
publish_job:
Expand Down
121 changes: 120 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# 🥒 Ogooreck

Ogooreck is a Sneaky Test library. It helps to write readable and self-documenting tests.
Ogooreck is a Sneaky Test library. It helps to write readable and self-documenting tests. It's both C# and F# friendly!

Main assumptions:
- write tests seamlessly,
Expand Down Expand Up @@ -49,6 +49,7 @@ Read more in the [Testing business logic in Event Sourcing, and beyond!](https:/

You can use `DeciderSpecification` to run decider and command handling tests. See the example:

**C#**
```csharp
using FluentAssertions;
using Ogooreck.BusinessLogic;
Expand Down Expand Up @@ -130,6 +131,124 @@ public static class BankAccountEventsBuilder
}
```

**F#**
```fsharp
module BankAccountTests
open System
open Deciders.BankAccount
open Deciders.BankAccountPrimitives
open Deciders.BankAccountDecider
open Ogooreck.BusinessLogic
open FsCheck.Xunit
let random = Random()
let spec =
Specification.For(decide, evolve, Initial)
let BankAccountOpenedWith bankAccountId now version =
let accountNumber =
AccountNumber.parse (Guid.NewGuid().ToString())
let clientId = ClientId.newId ()
let currencyISOCode =
CurrencyIsoCode.parse "USD"
BankAccountOpened
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
CreatedAt = now
Version = version }
let BankAccountClosedWith bankAccountId now version =
BankAccountClosed
{ BankAccountId = bankAccountId
Reason = Guid.NewGuid().ToString()
ClosedAt = now
Version = version }
[<Property>]
let ``GIVEN non existing bank account WHEN open with valid params THEN bank account is opened``
bankAccountId
accountNumber
clientId
currencyISOCode
now
=
let notExistingAccount = Array.empty
spec
.Given(notExistingAccount)
.When(
OpenBankAccount
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
Now = now }
)
.Then(
BankAccountOpened
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
CreatedAt = now
Version = 1 }
)
|> ignore
[<Property>]
let ``GIVEN open bank account WHEN record deposit with valid params THEN deposit is recorded``
bankAccountId
amount
cashierId
now
=
spec
.Given(BankAccountOpenedWith bankAccountId now 1)
.When(
RecordDeposit
{ Amount = amount
CashierId = cashierId
Now = now }
)
.Then(
DepositRecorded
{ BankAccountId = bankAccountId
Amount = amount
CashierId = cashierId
RecordedAt = now
Version = 2 }
)
|> ignore
[<Property>]
let ``GIVEN closed bank account WHEN record deposit with valid params THEN fails with invalid operation exception``
bankAccountId
amount
cashierId
now
=
spec
.Given(
BankAccountOpenedWith bankAccountId now 1,
BankAccountClosedWith bankAccountId now 2
)
.When(
RecordDeposit
{ Amount = amount
CashierId = cashierId
Now = now }
)
.ThenThrows<InvalidOperationException>
|> ignore
```

See full sample in [tests](/src/Ogooreck.Sample.BusinessLogic.Tests/Deciders/BankAccountTests.cs).

### Event-Sourced command handlers
Expand Down
4 changes: 2 additions & 2 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@echo off
FOR /f %%v IN ('dotnet --version') DO set version=%%v
set target_framework=
IF "%version:~0,2%"=="6." (set target_framework=net6.0)
IF "%version:~0,2%"=="7." (set target_framework=net7.0)

IF [%target_framework%]==[] (
echo "BUILD FAILURE: .NET 6 SDK required to run build"
echo "BUILD FAILURE: .NET 7 SDK required to run build"
exit /b 1
)

Expand Down
6 changes: 3 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ErrorActionPreference = "Stop";
$version = dotnet --version;
if ($version.StartsWith("6.")) {
$target_framework="net6.0"
if ($version.StartsWith("7.")) {
$target_framework="net7.0"
} else {
Write-Output "BUILD FAILURE: .NET 6 SDK required to run build"
Write-Output "BUILD FAILURE: .NET 7 SDK required to run build"
exit 1
}

Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
set -euo pipefail

version="$(dotnet --version)"
if [[ $version = 6.* ]]; then
target_framework="net6.0"
if [[ $version = 7.* ]]; then
target_framework="net7.0"
else
echo "BUILD FAILURE: .NET 6 SDK required to run build"
echo "BUILD FAILURE: .NET 7 SDK required to run build"
exit 1
fi

Expand Down
123 changes: 122 additions & 1 deletion mdsource/README.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# 🥒 Ogooreck

Ogooreck is a Sneaky Test library. It helps to write readable and self-documenting tests.
Ogooreck is a Sneaky Test library. It helps to write readable and self-documenting tests. It's both C# and F# friendly!

Main assumptions:
- write tests seamlessly,
Expand Down Expand Up @@ -49,6 +49,7 @@ Read more in the [Testing business logic in Event Sourcing, and beyond!](https:/

You can use `DeciderSpecification` to run decider and command handling tests. See the example:

**C#**
```csharp
using FluentAssertions;
using Ogooreck.BusinessLogic;
Expand Down Expand Up @@ -132,6 +133,126 @@ public static class BankAccountEventsBuilder

See full sample in [tests](/src/Ogooreck.Sample.BusinessLogic.Tests/Deciders/BankAccountTests.cs).

**F#**
```fsharp
module BankAccountTests
open System
open Deciders.BankAccount
open Deciders.BankAccountPrimitives
open Deciders.BankAccountDecider
open Ogooreck.BusinessLogic
open FsCheck.Xunit
let random = Random()
let spec =
Specification.For(decide, evolve, Initial)
let BankAccountOpenedWith bankAccountId now version =
let accountNumber =
AccountNumber.parse (Guid.NewGuid().ToString())
let clientId = ClientId.newId ()
let currencyISOCode =
CurrencyIsoCode.parse "USD"
BankAccountOpened
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
CreatedAt = now
Version = version }
let BankAccountClosedWith bankAccountId now version =
BankAccountClosed
{ BankAccountId = bankAccountId
Reason = Guid.NewGuid().ToString()
ClosedAt = now
Version = version }
[<Property>]
let ``GIVEN non existing bank account WHEN open with valid params THEN bank account is opened``
bankAccountId
accountNumber
clientId
currencyISOCode
now
=
let notExistingAccount = Array.empty
spec
.Given(notExistingAccount)
.When(
OpenBankAccount
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
Now = now }
)
.Then(
BankAccountOpened
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
CreatedAt = now
Version = 1 }
)
|> ignore
[<Property>]
let ``GIVEN open bank account WHEN record deposit with valid params THEN deposit is recorded``
bankAccountId
amount
cashierId
now
=
spec
.Given(BankAccountOpenedWith bankAccountId now 1)
.When(
RecordDeposit
{ Amount = amount
CashierId = cashierId
Now = now }
)
.Then(
DepositRecorded
{ BankAccountId = bankAccountId
Amount = amount
CashierId = cashierId
RecordedAt = now
Version = 2 }
)
|> ignore
[<Property>]
let ``GIVEN closed bank account WHEN record deposit with valid params THEN fails with invalid operation exception``
bankAccountId
amount
cashierId
now
=
spec
.Given(
BankAccountOpenedWith bankAccountId now 1,
BankAccountClosedWith bankAccountId now 2
)
.When(
RecordDeposit
{ Amount = amount
CashierId = cashierId
Now = now }
)
.ThenThrows<InvalidOperationException>
|> ignore
```

See full sample in [tests](/src/Ogooreck.Sample.BusinessLogic.FSharp.Tests/Deciders/BankAccountTests.fs).

### Event-Sourced command handlers

You can use `HandlerSpecification` to run event-sourced command handling tests for pure functions and entities. See the example:
Expand Down
6 changes: 3 additions & 3 deletions src/Ogooreck.Build/Ogooreck.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bullseye" Version="4.0.0" />
<PackageReference Include="SimpleExec" Version="10.0.0" />
<PackageReference Include="Bullseye" Version="4.2.0" />
<PackageReference Include="SimpleExec" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Ogooreck.Build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using static Bullseye.Targets;
using static SimpleExec.Command;

const string framework = "net6.0";
const string framework = "net7.0";
const string configuration = "Release";

Target("default", DependsOn("compile"));
Expand Down
12 changes: 6 additions & 6 deletions src/Ogooreck.Sample.Api.Tests/Ogooreck.Sample.Api.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.6" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -22,7 +22,7 @@


<ItemGroup>
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.4.0">
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 4ad5760

Please sign in to comment.