diff options
Diffstat (limited to 'src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs')
-rw-r--r-- | src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs index fa5d6688a6..332795e0e5 100644 --- a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs +++ b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs @@ -63,7 +63,7 @@ namespace math.Tests server.Start(); channel = new Channel(host + ":" + port); - // TODO: get rid of the custom header here once we have dedicated tests + // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests // for header support. var stubConfig = new StubConfiguration((headerBuilder) => { @@ -97,55 +97,67 @@ namespace math.Tests Assert.AreEqual(0, response.Remainder); } - // TODO: test division by zero + // TODO(jtattermusch): test division by zero [Test] public void DivAsync() { - DivReply response = client.DivAsync(new DivArgs.Builder { Dividend = 10, Divisor = 3 }.Build()).Result; - Assert.AreEqual(3, response.Quotient); - Assert.AreEqual(1, response.Remainder); + Task.Run(async () => + { + DivReply response = await client.DivAsync(new DivArgs.Builder { Dividend = 10, Divisor = 3 }.Build()); + Assert.AreEqual(3, response.Quotient); + Assert.AreEqual(1, response.Remainder); + }).Wait(); } [Test] public void Fib() { - var recorder = new RecordingObserver<Num>(); - client.Fib(new FibArgs.Builder { Limit = 6 }.Build(), recorder); + Task.Run(async () => + { + var call = client.Fib(new FibArgs.Builder { Limit = 6 }.Build()); - CollectionAssert.AreEqual(new List<long> { 1, 1, 2, 3, 5, 8 }, - recorder.ToList().Result.ConvertAll((n) => n.Num_)); + var responses = await call.ResponseStream.ToList(); + CollectionAssert.AreEqual(new List<long> { 1, 1, 2, 3, 5, 8 }, + responses.ConvertAll((n) => n.Num_)); + }).Wait(); } // TODO: test Fib with limit=0 and cancellation [Test] public void Sum() { - var clientStreamingResult = client.Sum(); - var numList = new List<long> { 10, 20, 30 }.ConvertAll( - n => Num.CreateBuilder().SetNum_(n).Build()); - numList.Subscribe(clientStreamingResult.Inputs); - - Assert.AreEqual(60, clientStreamingResult.Task.Result.Num_); + Task.Run(async () => + { + var call = client.Sum(); + var numbers = new List<long> { 10, 20, 30 }.ConvertAll( + n => Num.CreateBuilder().SetNum_(n).Build()); + + await call.RequestStream.WriteAll(numbers); + var result = await call.Result; + Assert.AreEqual(60, result.Num_); + }).Wait(); } [Test] public void DivMany() { - List<DivArgs> divArgsList = new List<DivArgs> + Task.Run(async () => { - new DivArgs.Builder { Dividend = 10, Divisor = 3 }.Build(), - new DivArgs.Builder { Dividend = 100, Divisor = 21 }.Build(), - new DivArgs.Builder { Dividend = 7, Divisor = 2 }.Build() - }; - - var recorder = new RecordingObserver<DivReply>(); - var requestObserver = client.DivMany(recorder); - divArgsList.Subscribe(requestObserver); - var result = recorder.ToList().Result; - - CollectionAssert.AreEqual(new long[] { 3, 4, 3 }, result.ConvertAll((divReply) => divReply.Quotient)); - CollectionAssert.AreEqual(new long[] { 1, 16, 1 }, result.ConvertAll((divReply) => divReply.Remainder)); + var divArgsList = new List<DivArgs> + { + new DivArgs.Builder { Dividend = 10, Divisor = 3 }.Build(), + new DivArgs.Builder { Dividend = 100, Divisor = 21 }.Build(), + new DivArgs.Builder { Dividend = 7, Divisor = 2 }.Build() + }; + + var call = client.DivMany(); + await call.RequestStream.WriteAll(divArgsList); + var result = await call.ResponseStream.ToList(); + + CollectionAssert.AreEqual(new long[] { 3, 4, 3 }, result.ConvertAll((divReply) => divReply.Quotient)); + CollectionAssert.AreEqual(new long[] { 1, 16, 1 }, result.ConvertAll((divReply) => divReply.Remainder)); + }).Wait(); } } } |