Skip to content

Commit

Permalink
Adding a test for different tuples for TProgress and TResult
Browse files Browse the repository at this point in the history
  • Loading branch information
darkl committed Apr 21, 2023
1 parent 1605f76 commit 8fef06c
Showing 1 changed file with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async Task ProgressiveCallsCallerProgress()
Assert.That(result, Is.EqualTo(10));
}


[Test]
public async Task ProgressiveCallsCallerProgressObservable()
{
Expand Down Expand Up @@ -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<ILongOpService>();

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()
{
Expand Down Expand Up @@ -205,11 +231,72 @@ public IWampCancellableInvocation Invoke<TMessage>(IWampRawRpcOperationRouterCal
}
}

public class MyValueTupleOperation : IWampRpcOperation
{
public const string ProcedureUri = "com.myapp.longopvaluetuple";

public string Procedure => ProcedureUri;

public IWampCancellableInvocation Invoke<TMessage>(IWampRawRpcOperationRouterCallback caller, IWampFormatter<TMessage> formatter, InvocationDetails details)
{
return null;
}

public IWampCancellableInvocation Invoke<TMessage>(IWampRawRpcOperationRouterCallback caller, IWampFormatter<TMessage> formatter,
InvocationDetails details,
TMessage[] arguments)
{
TMessage number = arguments[0];
int n = formatter.Deserialize<int>(number);

for (int i = 0; i < n; i++)
{
caller.Result(WampObjectFormatter.Value,
new YieldOptions { Progress = true },
new object[]{},
new Dictionary<string, object>
{
{ "a", i },
{ "b", i }
});
}

if (EndWithError)
{
caller.Error(WampObjectFormatter.Value,
new Dictionary<string, string>(),
"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<TMessage>(IWampRawRpcOperationRouterCallback caller, IWampFormatter<TMessage> formatter, InvocationDetails details,
TMessage[] arguments, IDictionary<string, TMessage> argumentsKeywords)
{
return null;
}
}

public interface ILongOpService
{
[WampProcedure(MyOperation.ProcedureUri)]
[WampProgressiveResultProcedure]
Task<string> LongOp(int n, IProgress<int> progress);

[WampProcedure(MyValueTupleOperation.ProcedureUri)]
[WampProgressiveResultProcedure]
Task<(int, string)> LongOpValueTuple(int n, IProgress<(int a, int b)> progress);

}

public class LongOpService : ILongOpService
Expand All @@ -224,6 +311,17 @@ public async Task<string> LongOp(int n, IProgress<int> 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
Expand Down

0 comments on commit 8fef06c

Please sign in to comment.