Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
MemberNotNullWhen

MemberNotNullWhen

style

ISempty

surogates

wip

tests

docs

tests

wip

result

tests

update nuget

.net6,.net7,.net8

pipline

nuget

nuget

nuget

nuget

nuget

nuget2

fix build

pipline

packages
  • Loading branch information
KSemenenko committed Jun 13, 2024
1 parent 8aa8da7 commit aa35617
Show file tree
Hide file tree
Showing 48 changed files with 813 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

# run build and test
- name: Restore dependencies
Expand Down
34 changes: 15 additions & 19 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,31 @@ name: nuget
on:
push:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
nuget-pack:

build_and_publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release
run: dotnet build --configuration Release

- name: Test
run: dotnet test --configuration Release
run: dotnet test --configuration Release

- name: Pack
run: dotnet pack -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --configuration Release

- name: publish nuget packages
run: |
shopt -s globstar
for file in **/*.nupkg
do
dotnet nuget push "$file" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
done
run: dotnet pack --configuration Release -o "packages"

- name: Push
run: dotnet nuget push "packages/*.snupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
11 changes: 9 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<Project>

<PropertyGroup>
<LangVersion>12</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Nullable>enable</Nullable>
</PropertyGroup>

<!--NuGet-->
<PropertyGroup>
<Authors>ManagedCode</Authors>
Expand All @@ -17,8 +24,8 @@
<RepositoryUrl>https://github.com/managedcode/Communication</RepositoryUrl>
<PackageProjectUrl>https://github.com/managedcode/Communication</PackageProjectUrl>
<Product>Managed Code - Communication</Product>
<Version>8.0.0</Version>
<PackageVersion>8.0.0</PackageVersion>
<Version>8.0.2</Version>
<PackageVersion>8.0.2</PackageVersion>

</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;net7.0;net8.0;</TargetFrameworks>
<IsPackable>true</IsPackable>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<DebugType>embedded</DebugType>
<RootNamespace>ManagedCode.Communication.Extensions</RootNamespace>
<OutputType>Library</OutputType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public sealed class CommandSurrogateConverter : IConverter<Command, CommandSurro
{
public Command ConvertFromSurrogate(in CommandSurrogate surrogate)
{
return new Command(surrogate.Id);
return new Command(surrogate.Id, surrogate.CommandType);
}

public CommandSurrogate ConvertToSurrogate(in Command value)
{
return new CommandSurrogate(value.Id);
return new CommandSurrogate(value.Id, value.CommandType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public sealed class CommandTSurrogateConverter<T> : IConverter<Command<T>, Comma
{
public Command<T> ConvertFromSurrogate(in CommandTSurrogate<T> surrogate)
{
return new Command<T>(surrogate.Id, surrogate.Value);
return new Command<T>(surrogate.Id, surrogate.CommandType, surrogate.Value);
}

public CommandTSurrogate<T> ConvertToSurrogate(in Command<T> value)
{
return new CommandTSurrogate<T>(value.Id, value.Value);
return new CommandTSurrogate<T>(value.Id, value.CommandType, value.Value);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>true</IsPackable>
<DebugType>embedded</DebugType>
<RootNamespace>ManagedCode.Communication</RootNamespace>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<!--NuGet-->
Expand All @@ -17,9 +16,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.2.3" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="7.2.3" />
<PackageReference Include="Microsoft.Orleans.Serialization.Abstractions" Version="7.2.3" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.1.0" />
<PackageReference Include="Microsoft.Orleans.Runtime" Version="8.1.0" />
<PackageReference Include="Microsoft.Orleans.Serialization.Abstractions" Version="8.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace ManagedCode.Communication.Surrogates;

// This is the surrogate which will act as a stand-in for the foreign type.
// Surrogates should use plain fields instead of properties for better perfomance.
[Immutable]
[GenerateSerializer]
public struct CollectionResultTSurrogate<T>
Expand All @@ -29,6 +27,4 @@ public CollectionResultTSurrogate(bool isSuccess, T[]? collection, int pageNumbe
[Id(4)] public int TotalItems;
[Id(5)] public Error[]? Errors;
[Id(6)] public Dictionary<string, string>? InvalidObject;
}

// This is a converter which converts between the surrogate and the foreign type.
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ namespace ManagedCode.Communication.Surrogates;
[GenerateSerializer]
public struct CommandSurrogate
{
[Id(0)] public string? Id;
[Id(0)] public string Id;
[Id(1)] public string CommandType;

public CommandSurrogate(string? id)
public CommandSurrogate(string id, string commandType)
{
Id = id;
CommandType = commandType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ namespace ManagedCode.Communication.Surrogates;
[GenerateSerializer]
public struct CommandTSurrogate<T>
{
[Id(0)] public string? Id;
[Id(1)] public T? Value;
[Id(0)] public string Id;
[Id(1)] public string CommandType;
[Id(2)] public T? Value;

public CommandTSurrogate(string? id, T? value)
public CommandTSurrogate(string id, string commandType, T? value)
{
Id = id;
CommandType = commandType;
Value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace ManagedCode.Communication.Surrogates;

// This is the surrogate which will act as a stand-in for the foreign type.
// Surrogates should use plain fields instead of properties for better perfomance.
[Immutable]
[GenerateSerializer]
public struct ErrorSurrogate
Expand All @@ -19,6 +17,4 @@ public ErrorSurrogate(Exception? exception, string message, string? errorCode =
[Id(0)] public string? ErrorCode;
[Id(1)] public string Message;
[Id(2)] public Exception? Exception;
}

// This is a converter which converts between the surrogate and the foreign type.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace ManagedCode.Communication.Surrogates;

// This is the surrogate which will act as a stand-in for the foreign type.
// Surrogates should use plain fields instead of properties for better perfomance.
[Immutable]
[GenerateSerializer]
public struct ResultSurrogate
Expand All @@ -21,6 +19,4 @@ public ResultSurrogate(bool isSuccess, Error[]? errors, Dictionary<string, strin
[Id(1)] public Error[]? Errors;

[Id(2)] public Dictionary<string, string>? InvalidObject;
}

// This is a converter which converts between the surrogate and the foreign type.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace ManagedCode.Communication.Surrogates;

// This is the surrogate which will act as a stand-in for the foreign type.
// Surrogates should use plain fields instead of properties for better perfomance.
[Immutable]
[GenerateSerializer]
public struct ResultTSurrogate<T>
Expand All @@ -25,5 +23,3 @@ public ResultTSurrogate(bool isSuccess, T? value, Error[]? errors, Dictionary<st

[Id(3)] public T? Value;
}

// This is a converter which converts between the surrogate and the foreign type.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;

Expand Down Expand Up @@ -47,4 +50,98 @@ public void SucceedPaged()
ok.TotalPages.Should().Be(15000 / 100);
ok.PageSize.Should().Be(100);
}

[Fact]
public void FailWithoutError()
{
var fail = CollectionResult<int>.Fail();
fail.IsSuccess.Should().BeFalse();
fail.IsFailed.Should().BeTrue();
fail.GetError().Should().BeNull();
Assert.Throws<Exception>(() => fail.ThrowIfFail());
Assert.True(fail == false);
Assert.False(fail);
fail.AsTask().Result.IsSuccess.Should().BeFalse();
fail.AsValueTask().Result.IsSuccess.Should().BeFalse();
}

[Fact]
public void FailWithError()
{
var fail = CollectionResult<int>.Fail("Test Error");
fail.IsSuccess.Should().BeFalse();
fail.IsFailed.Should().BeTrue();
fail.GetError().Should().NotBeNull();
fail.GetError()?.Message.Should().Be("Test Error");
Assert.Throws<Exception>(() => fail.ThrowIfFail());
Assert.True(fail == false);
Assert.False(fail);
fail.AsTask().Result.IsSuccess.Should().BeFalse();
fail.AsValueTask().Result.IsSuccess.Should().BeFalse();
}

[Fact]
public void InvalidWithoutMessage()
{
var invalid = CollectionResult<int>.Invalid();
invalid.IsSuccess.Should().BeFalse();
invalid.IsInvalid.Should().BeTrue();
invalid.InvalidObject.Should().NotBeNull();
invalid.InvalidObject?.ContainsKey("message").Should().BeTrue();
invalid.InvalidObject?["message"].Should().Be(nameof(CollectionResult<int>.Invalid));
}

[Fact]
public void InvalidWithMessage()
{
var invalid = CollectionResult<int>.Invalid("Test Invalid");
invalid.IsSuccess.Should().BeFalse();
invalid.IsInvalid.Should().BeTrue();
invalid.InvalidObject.Should().NotBeNull();
invalid.InvalidObject?.ContainsKey("message").Should().BeTrue();
invalid.InvalidObject?["message"].Should().Be("Test Invalid");
}

[Fact]
public void SucceedWithEmptyCollection()
{
var ok = CollectionResult<int>.Succeed(new int[0]);
ok.IsSuccess.Should().BeTrue();
ok.Collection.Length.Should().Be(0);
}

[Fact]
public void FailWithException()
{
var fail = CollectionResult<int>.Fail(new Exception("Test Exception"));
fail.IsSuccess.Should().BeFalse();
fail.GetError()?.Message.Should().Be("Test Exception");
}

[Fact]
public void InvalidWithKeyValue()
{
var invalid = CollectionResult<int>.Invalid("TestKey", "TestValue");
invalid.IsSuccess.Should().BeFalse();
invalid.InvalidObject?.ContainsKey("TestKey").Should().BeTrue();
invalid.InvalidObject?["TestKey"].Should().Be("TestValue");
}

[Fact]
public async Task FromTaskWithException()
{
var task = Task.FromException<IEnumerable<int>>(new Exception("Test Exception"));
var result = await CollectionResult<int>.From(task);
result.IsSuccess.Should().BeFalse();
result.GetError()?.Message.Should().Be("Test Exception");
}

[Fact]
public async Task FromValueTaskWithException()
{
var valueTask = new ValueTask<IEnumerable<int>>(Task.FromException<IEnumerable<int>>(new Exception("Test Exception")));
var result = await CollectionResult<int>.From(valueTask);
result.IsSuccess.Should().BeFalse();
result.GetError()?.Message.Should().Be("Test Exception");
}
}
Loading

0 comments on commit aa35617

Please sign in to comment.