From e331da2277a7a52deceeee17baa79ea4c7feefe8 Mon Sep 17 00:00:00 2001
From: Jan Tattermusch <jtattermusch@google.com>
Date: Fri, 8 Apr 2016 11:05:39 -0700
Subject: [PATCH] make Grpc.Core.Tests work with NUnit3

---
 src/csharp/Grpc.Core.Tests/ChannelTest.cs            |  4 ++--
 src/csharp/Grpc.Core.Tests/ClientServerTest.cs       | 10 +++++-----
 src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs |  2 +-
 src/csharp/Grpc.Core.Tests/HalfcloseTest.cs          |  2 +-
 src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs |  2 +-
 src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs  |  8 ++++----
 src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs    |  2 +-
 7 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/csharp/Grpc.Core.Tests/ChannelTest.cs b/src/csharp/Grpc.Core.Tests/ChannelTest.cs
index ed0ec14df5..6330f50fae 100644
--- a/src/csharp/Grpc.Core.Tests/ChannelTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ChannelTest.cs
@@ -70,7 +70,7 @@ namespace Grpc.Core.Tests
         public void WaitForStateChangedAsync_InvalidArgument()
         {
             var channel = new Channel("localhost", ChannelCredentials.Insecure);
-            Assert.Throws(typeof(ArgumentException), () => channel.WaitForStateChangedAsync(ChannelState.FatalFailure));
+            Assert.ThrowsAsync(typeof(ArgumentException), async () => await channel.WaitForStateChangedAsync(ChannelState.FatalFailure));
             channel.ShutdownAsync().Wait();
         }
 
@@ -87,7 +87,7 @@ namespace Grpc.Core.Tests
         {
             var channel = new Channel("localhost", ChannelCredentials.Insecure);
             channel.ShutdownAsync().Wait();
-            Assert.Throws(typeof(InvalidOperationException), () => channel.ShutdownAsync().GetAwaiter().GetResult());
+            Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await channel.ShutdownAsync());
         }
     }
 }
diff --git a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs
index 77f6a63156..6c13a4fa48 100644
--- a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs
@@ -93,7 +93,7 @@ namespace Grpc.Core.Tests
             var ex = Assert.Throws<RpcException>(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
             Assert.AreEqual(StatusCode.Unknown, ex.Status.StatusCode); 
 
-            var ex2 = Assert.Throws<RpcException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
+            var ex2 = Assert.ThrowsAsync<RpcException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
             Assert.AreEqual(StatusCode.Unknown, ex2.Status.StatusCode);
         }
 
@@ -108,7 +108,7 @@ namespace Grpc.Core.Tests
             var ex = Assert.Throws<RpcException>(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
             Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode);
 
-            var ex2 = Assert.Throws<RpcException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
+            var ex2 = Assert.ThrowsAsync<RpcException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
             Assert.AreEqual(StatusCode.Unauthenticated, ex2.Status.StatusCode);
         }
 
@@ -124,7 +124,7 @@ namespace Grpc.Core.Tests
             var ex = Assert.Throws<RpcException>(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
             Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode);
 
-            var ex2 = Assert.Throws<RpcException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
+            var ex2 = Assert.ThrowsAsync<RpcException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
             Assert.AreEqual(StatusCode.Unauthenticated, ex2.Status.StatusCode);
         }
 
@@ -204,7 +204,7 @@ namespace Grpc.Core.Tests
             await barrier.Task;  // make sure the handler has started.
             cts.Cancel();
 
-            var ex = Assert.Throws<RpcException>(async () => await call.ResponseAsync);
+            var ex = Assert.ThrowsAsync<RpcException>(async () => await call.ResponseAsync);
             Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode);
         }
 
@@ -290,7 +290,7 @@ namespace Grpc.Core.Tests
                 return request;
             });
 
-            Assert.Throws(typeof(TaskCanceledException), 
+            Assert.ThrowsAsync(typeof(TaskCanceledException), 
                 async () => await channel.WaitForStateChangedAsync(channel.State, DateTime.UtcNow.AddMilliseconds(10)));
 
             var stateChangedTask = channel.WaitForStateChangedAsync(channel.State);
diff --git a/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs b/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs
index 90c510ec61..cec8c7ce6b 100644
--- a/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs
@@ -105,7 +105,7 @@ namespace Grpc.Core.Tests
             var parentCall = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall(new CallOptions(cancellationToken: cts.Token)));
             await readyToCancelTcs.Task;
             cts.Cancel();
-            Assert.Throws(typeof(RpcException), async () => await parentCall);
+            Assert.ThrowsAsync(typeof(RpcException), async () => await parentCall);
             Assert.AreEqual("CHILD_CALL_CANCELLED", await successTcs.Task);
         }
 
diff --git a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
index fe6edb858b..b4cb451d94 100644
--- a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
+++ b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
@@ -91,7 +91,7 @@ namespace Grpc.Core.Tests
             await call.RequestStream.CompleteAsync();
 
             // Second attempt to close from client is not allowed.
-            Assert.Throws(typeof(InvalidOperationException), async () => await call.RequestStream.CompleteAsync());
+            Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await call.RequestStream.CompleteAsync());
         }
     }
 }
diff --git a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
index 543f6375df..60530d3250 100644
--- a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
+++ b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs
@@ -84,7 +84,7 @@ namespace Grpc.Core.Internal.Tests
 
             Assert.AreEqual(StatusCode.Internal, asyncCall.GetStatus().StatusCode);
             Assert.IsNull(asyncCall.GetTrailers());
-            var ex = Assert.Throws<RpcException>(() => resultTask.GetAwaiter().GetResult());
+            var ex = Assert.ThrowsAsync<RpcException>(async () => await resultTask);
             Assert.AreEqual(StatusCode.Internal, ex.Status.StatusCode);
         }
 
diff --git a/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs b/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs
index 37fb36946a..0663e77d1e 100644
--- a/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs
+++ b/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs
@@ -112,7 +112,7 @@ namespace Grpc.Core.Tests
             });
 
             var call = Calls.AsyncServerStreamingCall(helper.CreateServerStreamingCall(), "REQUEST");
-            var ex = Assert.Throws<RpcException>(async () => await call.ResponseStream.MoveNext());
+            var ex = Assert.ThrowsAsync<RpcException>(async () => await call.ResponseStream.MoveNext());
             Assert.AreEqual(StatusCode.Internal, ex.Status.StatusCode);
         }
 
@@ -134,7 +134,7 @@ namespace Grpc.Core.Tests
         {
             helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) =>
             {
-                Assert.Throws<IOException>(async () => await requestStream.MoveNext());
+                Assert.ThrowsAsync<IOException>(async () => await requestStream.MoveNext());
                 return "RESPONSE";
             });
 
@@ -153,7 +153,7 @@ namespace Grpc.Core.Tests
         [Test]
         public void RequestSerializationError_AsyncUnary()
         {
-            Assert.Throws<IOException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "UNSERIALIZABLE_VALUE"));
+            Assert.ThrowsAsync<IOException>(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "UNSERIALIZABLE_VALUE"));
         }
 
         [Test]
@@ -166,7 +166,7 @@ namespace Grpc.Core.Tests
             });
             var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall());
             await call.RequestStream.WriteAsync("A");
-            Assert.Throws<IOException>(async () => await call.RequestStream.WriteAsync("UNSERIALIZABLE_VALUE"));
+            Assert.ThrowsAsync<IOException>(async () => await call.RequestStream.WriteAsync("UNSERIALIZABLE_VALUE"));
             await call.RequestStream.WriteAsync("B");
             await call.RequestStream.CompleteAsync();
 
diff --git a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs
index a1648f3671..772beadd4a 100644
--- a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs
@@ -155,7 +155,7 @@ namespace Grpc.Core.Tests
         {
             helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
             {
-                Assert.Throws(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null));
+                Assert.ThrowsAsync(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null));
                 return "PASS";
             });
 
-- 
GitLab