From 8fef06c12581872e810bd86a59af4505dbcf00cc Mon Sep 17 00:00:00 2001 From: Elad Zelingher Date: Fri, 21 Apr 2023 11:40:02 -0500 Subject: [PATCH] Adding a test for different tuples for TProgress and TResult --- .../Integration/RpcProgressTests.cs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/netstandard/Tests/WampSharp.Tests.Wampv2/Integration/RpcProgressTests.cs b/src/netstandard/Tests/WampSharp.Tests.Wampv2/Integration/RpcProgressTests.cs index 0b2977a0..adbb23d9 100644 --- a/src/netstandard/Tests/WampSharp.Tests.Wampv2/Integration/RpcProgressTests.cs +++ b/src/netstandard/Tests/WampSharp.Tests.Wampv2/Integration/RpcProgressTests.cs @@ -40,6 +40,7 @@ public async Task ProgressiveCallsCallerProgress() Assert.That(result, Is.EqualTo(10)); } + [Test] public async Task ProgressiveCallsCallerProgressObservable() { @@ -116,6 +117,31 @@ public async Task ProgressiveCallsCalleeProxyProgress() Assert.That(result, Is.EqualTo("10")); } + [Test] + public async Task ProgressiveCallsCalleeProxyProgressValueTuples() + { + WampPlayground playground = new WampPlayground(); + + CallerCallee dualChannel = await playground.GetCallerCalleeDualChannel(); + IWampChannel calleeChannel = dualChannel.CalleeChannel; + IWampChannel callerChannel = dualChannel.CallerChannel; + + MyValueTupleOperation myOperation = new MyValueTupleOperation(); + + await calleeChannel.RealmProxy.RpcCatalog.Register(myOperation, new RegisterOptions()); + ILongOpService proxy = callerChannel.RealmProxy.Services.GetCalleeProxy(); + + List<(int a, int b)> results = new List<(int a, int b)>(); + MyProgress<(int a, int b)> progress = new MyProgress<(int a, int b)>(i => results.Add(i)); + + var result = await proxy.LongOpValueTuple(10, progress); + + CollectionAssert.AreEquivalent(Enumerable.Range(0, 10).Select(x => (a:x,b:x)), results); + + Assert.That(result, Is.EqualTo((10, "10"))); + } + + [Test] public async Task ProgressiveCallsCalleeProxyObservable() { @@ -205,11 +231,72 @@ public IWampCancellableInvocation Invoke(IWampRawRpcOperationRouterCal } } + public class MyValueTupleOperation : IWampRpcOperation + { + public const string ProcedureUri = "com.myapp.longopvaluetuple"; + + public string Procedure => ProcedureUri; + + public IWampCancellableInvocation Invoke(IWampRawRpcOperationRouterCallback caller, IWampFormatter formatter, InvocationDetails details) + { + return null; + } + + public IWampCancellableInvocation Invoke(IWampRawRpcOperationRouterCallback caller, IWampFormatter formatter, + InvocationDetails details, + TMessage[] arguments) + { + TMessage number = arguments[0]; + int n = formatter.Deserialize(number); + + for (int i = 0; i < n; i++) + { + caller.Result(WampObjectFormatter.Value, + new YieldOptions { Progress = true }, + new object[]{}, + new Dictionary + { + { "a", i }, + { "b", i } + }); + } + + if (EndWithError) + { + caller.Error(WampObjectFormatter.Value, + new Dictionary(), + "longop.error", + new object[] { "Something bad happened" }); + } + else + { + caller.Result(WampObjectFormatter.Value, + new YieldOptions(), + new object[] { n, n.ToString() }); + } + + return null; + } + + public bool EndWithError { get; set; } + + public IWampCancellableInvocation Invoke(IWampRawRpcOperationRouterCallback caller, IWampFormatter formatter, InvocationDetails details, + TMessage[] arguments, IDictionary argumentsKeywords) + { + return null; + } + } + public interface ILongOpService { [WampProcedure(MyOperation.ProcedureUri)] [WampProgressiveResultProcedure] Task LongOp(int n, IProgress progress); + + [WampProcedure(MyValueTupleOperation.ProcedureUri)] + [WampProgressiveResultProcedure] + Task<(int, string)> LongOpValueTuple(int n, IProgress<(int a, int b)> progress); + } public class LongOpService : ILongOpService @@ -224,6 +311,17 @@ public async Task LongOp(int n, IProgress progress) return n.ToString(); } + + public async Task<(int, string)> LongOpValueTuple(int n, IProgress<(int a, int b)> progress) + { + for (int i = 0; i < n; i++) + { + progress.Report((i, i)); + await Task.Delay(100); + } + + return (n, n.ToString()); + } } public interface ILongOpObservableService