Skip to content

Commit

Permalink
Adjust .editorconfig, use .NET 8 recommended styles. Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zsrdjan committed Jul 19, 2024
1 parent 236d475 commit 60bb72c
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 56 deletions.
10 changes: 4 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ root = true

; For more visit http://editorconfig.org.

; Choose between lf or rf on "end_of_line" property
[*.proto]
indent_style = tab
indent_size = tab
tab_width = 4

[*.{asax,ascx,aspx,cs,cshtml,css,htm,html,js,jsx,master,razor,skin,ts,tsx,vb,xaml,xamlx,xoml}]
indent_style = space
indent_size = 4
Expand Down Expand Up @@ -74,3 +68,7 @@ dotnet_style_qualification_for_field = false:hint
dotnet_style_qualification_for_method = false:hint
dotnet_style_qualification_for_property = false:hint
dotnet_style_require_accessibility_modifiers = for_non_interface_members:hint

[*.cs]
dotnet_diagnostic.CA1715.severity = none # Identifiers should have correct prefix
dotnet_diagnostic.CA1707.severity = none # Identifiers should not contain underscores
12 changes: 8 additions & 4 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
[Parameter(Position = 0, Mandatory = 1)][scriptblock]$cmd,
[Parameter(Position = 1, Mandatory = 0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
if ($lastexitcode -ne 0)
{
throw ("Exec: " + $errorMessage)
}
}

$artifacts = ".\artifacts"

if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse }
if (Test-Path $artifacts)
{
Remove-Item $artifacts -Force -Recurse
}

exec { & dotnet clean -c Release }

Expand Down
10 changes: 5 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
<Authors>Ivan Dugalić, Srđan Živojinović</Authors>
<Copyright>Copyright © 2024 Fraktalio. All rights reserved.</Copyright>
<Company>Fraktalio</Company>

<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>

<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Features>strict</Features>
<AnalysisLevel>latest</AnalysisLevel>
<WarningLevel>9999</WarningLevel>
<AnalysisLevel>8.0</AnalysisLevel>
<AnalysisMode>Recommended</AnalysisMode>

<PackageTags>domain-modeling;event-sourcing;eventsourcing;cqrs</PackageTags>
<PackageIcon>gradient_128x128.png</PackageIcon>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down
20 changes: 10 additions & 10 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="FakeItEasy" Version="8.1.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="5.0.0" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="Verify.NUnit" Version="22.5.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.0"/>
<PackageVersion Include="FakeItEasy" Version="8.1.0"/>
<PackageVersion Include="FluentAssertions" Version="6.12.0"/>
<PackageVersion Include="JetBrains.Annotations" Version="2023.3.0"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0"/>
<PackageVersion Include="MinVer" Version="5.0.0"/>
<PackageVersion Include="NUnit" Version="3.14.0"/>
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageVersion Include="Verify.NUnit" Version="22.5.0"/>
<PackageVersion Include="NUnit.Analyzers" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
12 changes: 8 additions & 4 deletions Push.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
$scriptName = $MyInvocation.MyCommand.Name
$artifacts = "./artifacts"

if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) {
if ( [string]::IsNullOrEmpty($Env:NUGET_API_KEY))
{
Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)."
} else {
}
else
{
Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object {
Write-Host "$($scriptName): Pushing $($_.Name)"
Write-Host "$( $scriptName ): Pushing $( $_.Name )"
dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY
if ($lastexitcode -ne 0) {
if ($lastexitcode -ne 0)
{
throw ("Exec: " + $errorMessage)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fraktalio.FModel/Fraktalio.FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fraktalio.FModel/InternalDecider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// <typeparam name="So">Output State type</typeparam>
/// <typeparam name="Ei">Input Event type</typeparam>
/// <typeparam name="Eo">Output Event type</typeparam>
internal class InternalDecider<C, Si, So, Ei, Eo>
internal sealed class InternalDecider<C, Si, So, Ei, Eo>
{
/// <summary>
/// [InternalDecider] is a datatype that represents the main decision-making algorithm.
Expand Down
3 changes: 2 additions & 1 deletion src/Fraktalio.FModel/InternalDeciderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ internal static class InternalDeciderExtensions
/// <typeparam name="Ei_SUPER">Super type of the Ei and Ei2 types</typeparam>
/// <typeparam name="Eo_SUPER">super type of the Eo and Eo2 types</typeparam>
/// <returns></returns>
internal static InternalDecider<C_SUPER?, Tuple<Si, Si2>, Tuple<So, So2>, Ei_SUPER, Eo_SUPER?> Combine<C, Si, So, Ei,
internal static InternalDecider<C_SUPER?, Tuple<Si, Si2>, Tuple<So, So2>, Ei_SUPER, Eo_SUPER?> Combine<C, Si, So,
Ei,
Eo, C2, Si2, So2, Ei2, Eo2, C_SUPER, Ei_SUPER, Eo_SUPER>(
this InternalDecider<C?, Si, So, Ei?, Eo?> x,
InternalDecider<C2?, Si2, So2, Ei2?, Eo2?> y)
Expand Down
4 changes: 1 addition & 3 deletions src/Fraktalio.FModel/InternalView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Fraktalio.FModel;
/// <typeparam name="Si">Input State type</typeparam>
/// <typeparam name="So">Output State type</typeparam>
/// <typeparam name="E">Event type</typeparam>
internal class InternalView<Si, So, E>(Func<Si, E, So> evolve, So initialState)
internal sealed class InternalView<Si, So, E>(Func<Si, E, So> evolve, So initialState)
{
internal Func<Si, E, So> Evolve { get; } = evolve;
internal So InitialState { get; } = initialState;
Expand Down Expand Up @@ -77,6 +77,4 @@ public InternalView<Si, Son, E> ApplyOnState<Son>(InternalView<Si, Func<So, Son>

internal InternalView<Si, Tuple<So, Son>, E> ProductOnState<Son>(InternalView<Si, Son, E> fb) =>
ApplyOnState(fb.MapOnState(b => new Func<So, Tuple<So, Son>>(a => new Tuple<So, Son>(a, b))));


}
6 changes: 4 additions & 2 deletions src/Fraktalio.FModel/ViewBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Fraktalio.FModel;

internal class ViewBuilder<S, E>
internal sealed class ViewBuilder<S, E>
{
private Func<S, E, S> Evolve { get; set; } = (s, _) => s;
private Func<S> InitialState { get; set; } = () => throw new Exception("Initial State is not initialized");

private Func<S> InitialState { get; set; } =
() => throw new InvalidOperationException("Initial State is not initialized");

public void SetEvolve(Func<S, E, S> value) => Evolve = value;

Expand Down
34 changes: 20 additions & 14 deletions test/Fraktalio.FModel.Tests/EventSourcedDeciderTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Fraktalio.FModel.Tests.Examples.Numbers;
using System.Globalization;
using Fraktalio.FModel.Tests.Examples.Numbers;
using Fraktalio.FModel.Tests.Examples.Numbers.Even;
using Fraktalio.FModel.Tests.Examples.Numbers.Odd;
using Fraktalio.FModel.Tests.Extensions;
Expand Down Expand Up @@ -51,15 +52,17 @@ public void GivenEvents_SubtractOddNumber() =>
[Test]
public void GivenEvents_LeftMapOverCommand_AddEvenNumber() =>
_evenDecider.MapLeftOnCommand<int>(cn =>
new EvenNumberCommand.AddEvenNumber(Description.Create(cn.ToString()), Number.Create(cn)))
new EvenNumberCommand.AddEvenNumber(Description.Create(cn.ToString(CultureInfo.InvariantCulture)),
Number.Create(cn)))
.GivenEvents([],
() => 2)
.ThenEvents([new EvenNumberAdded(Description.Create("2"), Number.Create(2))]);

[Test]
public void GivenState_LeftMapOverCommand_AddEvenNumber() =>
_evenDecider.MapLeftOnCommand<int>(cn =>
new EvenNumberCommand.AddEvenNumber(Description.Create(cn.ToString()), Number.Create(cn)))
new EvenNumberCommand.AddEvenNumber(Description.Create(cn.ToString(CultureInfo.InvariantCulture)),
Number.Create(cn)))
.GivenState(null,
() => 2)
.ThenState(new EvenNumberState(Description.Create("Initial state + 2"), Number.Create(2)));
Expand All @@ -68,31 +71,34 @@ public void GivenState_LeftMapOverCommand_AddEvenNumber() =>
//TODO ID: check if this is correct
public void GivenEmptyEvents_DimapOverEventParameter_AddEvenNumber() =>
_evenDecider.DimapOnEvent<EvenNumberEvent?>(
fl => fl != null ? fl with { Value = fl.Value} : null,
fl => fl != null ? fl with { Value = fl.Value } : null,
fr => fr != null
? new EvenNumberAdded(Description.Create(fr.Value.Value.ToString()), Number.Create(fr.Value))
? new EvenNumberAdded(Description.Create(fr.Value.Value.ToString(CultureInfo.InvariantCulture)),
Number.Create(fr.Value))
: null)
.GivenEvents([], () => new EvenNumberCommand.AddEvenNumber(Description.Create("2"), Number.Create(2)))
.ThenEvents([new EvenNumberAdded(Description.Create("2"), Number.Create(2))]);

[Test]
//TODO ID: check if this is correct
public void GivenEmptyEvents_DimapOverStateParameter_AddEvenNumber() =>
_evenDecider.DimapOnState<EvenNumberState>(
fl => fl with { Value = fl.Value},
fr =>
new EvenNumberState(Description.Create(fr.Value.Value.ToString()), Number.Create(fr.Value))
)
fl => fl with { Value = fl.Value },
fr =>
new EvenNumberState(Description.Create(fr.Value.Value.ToString(CultureInfo.InvariantCulture)),
Number.Create(fr.Value))
)
.GivenEvents([], () => new EvenNumberCommand.AddEvenNumber(Description.Create("2"), Number.Create(2)))
.ThenEvents([new EvenNumberAdded(Description.Create("2"), Number.Create(2))]);

[Test]
//TODO ID: check if this is correct
public void GivenEmptyState_DimapOverStateParameter_AddEvenNumber() =>
_evenDecider.DimapOnState<EvenNumberState>(
fl => fl with { Value = fl.Value},
fr =>
new EvenNumberState(Description.Create(fr.Value.Value.ToString()), Number.Create(fr.Value))
fl => fl with { Value = fl.Value },
fr =>
new EvenNumberState(Description.Create(fr.Value.Value.ToString(CultureInfo.InvariantCulture)),
Number.Create(fr.Value))
)
.GivenState(null, () => new EvenNumberCommand.AddEvenNumber(Description.Create("2"), Number.Create(2)))
.ThenState(new EvenNumberState(Description.Create("2"), Number.Create(2)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class SubtractEvenNumber(Description description, Number number)

public abstract class OddNumberCommand(Description description, Number number) : NumberCommand(description, number)
{
public sealed class AddOddNumber(Description description, Number number) : OddNumberCommand(description, number);
public sealed class AddOddNumber(Description description, Number number)
: OddNumberCommand(description, number);

public sealed class SubtractOddNumber(Description description, Number number)
: OddNumberCommand(description, number);
Expand Down
5 changes: 3 additions & 2 deletions test/Fraktalio.FModel.Tests/SagaTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Fraktalio.FModel.Tests.Examples.Numbers;
using System.Globalization;
using Fraktalio.FModel.Tests.Examples.Numbers;
using Fraktalio.FModel.Tests.Extensions;
using OddNumberCommand = Fraktalio.FModel.Tests.Examples.Numbers.NumberCommand.OddNumberCommand;
using EvenNumberCommand = Fraktalio.FModel.Tests.Examples.Numbers.NumberCommand.EvenNumberCommand;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void Given_OddNumberAdded_CombinedSaga_CreatesAddEvenNumberCommand()
[Test]
public void MapLeftOnActionResult() =>
_evenSaga.MapLeftOnActionResult<int>(arn =>
new EvenNumberAdded(Description.Create(arn.ToString()), Number.Create(arn)))
new EvenNumberAdded(Description.Create(arn.ToString(CultureInfo.InvariantCulture)), Number.Create(arn)))
.WhenActionResult(
2)
.ExpectActions(
Expand Down
7 changes: 5 additions & 2 deletions test/Fraktalio.FModel.Tests/ViewTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using Fraktalio.FModel.Tests.Examples.Numbers;
using Fraktalio.FModel.Tests.Examples.Numbers.Even;
using Fraktalio.FModel.Tests.Examples.Numbers.Odd;
Expand Down Expand Up @@ -30,7 +31,8 @@ public void GivenMultipleEvents_EvenNumberState() =>
public void MapLefOnEvent_EvenNumbersAdded()
{
var mappedEvenView = _evenView.MapLeftOnEvent<int>(number =>
new EvenNumberAdded(Description.Create(number.ToString()), Number.Create(number)));
new EvenNumberAdded(Description.Create(number.ToString(CultureInfo.InvariantCulture)),
Number.Create(number)));
mappedEvenView.GivenEvents([
2,
4
Expand All @@ -43,7 +45,8 @@ public void DimapOnState_EvenNumbersAdded()
{
var mappedEvenView =
_evenView.DimapOnState(fl =>
new EvenNumberState(Description.Create(fl.ToString()), Number.Create(fl)),
new EvenNumberState(Description.Create(fl.ToString(CultureInfo.InvariantCulture)),
Number.Create(fl)),
fr => fr.Value.Value);

mappedEvenView.GivenEvents([
Expand Down

0 comments on commit 60bb72c

Please sign in to comment.