From ed37b3132e13e5fc85f35c02a0f9a025dc11ad7f Mon Sep 17 00:00:00 2001 From: emikerimov Date: Sat, 4 Apr 2026 18:05:49 +0300 Subject: [PATCH] feat: GrpcExtensions --- .../Extensions/GrpcCallResult.cs | 17 ++++++++++++++++ .../Extensions/GrpcExtensions.cs | 20 +++++++++++++++++++ ...mo.Dev.Platform.Testing.Behavioural.csproj | 1 + .../Program.cs | 2 -- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcCallResult.cs create mode 100644 src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcExtensions.cs diff --git a/src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcCallResult.cs b/src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcCallResult.cs new file mode 100644 index 0000000..e897f9e --- /dev/null +++ b/src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcCallResult.cs @@ -0,0 +1,17 @@ +using Grpc.Core; + +namespace Itmo.Dev.Platform.Testing.Behavioural.Extensions; + +public abstract record GrpcCallResult +{ + private GrpcCallResult() { } + + public sealed record Success(T Value) : GrpcCallResult; + + public sealed record Failure(RpcException Exception) : GrpcCallResult + { + public StatusCode StatusCode => Exception.StatusCode; + + public string Detail => Exception.Status.Detail; + } +} diff --git a/src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcExtensions.cs b/src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcExtensions.cs new file mode 100644 index 0000000..4f42b66 --- /dev/null +++ b/src/Itmo.Dev.Platform.Testing.Behavioural/Extensions/GrpcExtensions.cs @@ -0,0 +1,20 @@ +using Grpc.Core; + +namespace Itmo.Dev.Platform.Testing.Behavioural.Extensions; + +public static class GrpcExtensions +{ + public static async Task> AsResultAsync(this AsyncUnaryCall call) + { + try + { + T value = await call; + + return new GrpcCallResult.Success(value); + } + catch (RpcException e) + { + return new GrpcCallResult.Failure(e); + } + } +} \ No newline at end of file diff --git a/src/Itmo.Dev.Platform.Testing.Behavioural/Itmo.Dev.Platform.Testing.Behavioural.csproj b/src/Itmo.Dev.Platform.Testing.Behavioural/Itmo.Dev.Platform.Testing.Behavioural.csproj index de3d045..c49afa1 100644 --- a/src/Itmo.Dev.Platform.Testing.Behavioural/Itmo.Dev.Platform.Testing.Behavioural.csproj +++ b/src/Itmo.Dev.Platform.Testing.Behavioural/Itmo.Dev.Platform.Testing.Behavioural.csproj @@ -20,6 +20,7 @@ + diff --git a/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs b/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs index 578b329..85d38cc 100644 --- a/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs +++ b/tests/Itmo.Dev.Platform.Kafka.Tests.Startup/Program.cs @@ -1,7 +1,5 @@ using Itmo.Dev.Platform.Common.Extensions; using Itmo.Dev.Platform.Observability; -using Microsoft.Extensions.Options; -using Newtonsoft.Json; using OpenTelemetry.Trace; using Serilog;