diff --git a/src/csharp/.nuget/packages.config b/src/csharp/.nuget/packages.config
index acb43ae4b3d..6154b3561f4 100644
--- a/src/csharp/.nuget/packages.config
+++ b/src/csharp/.nuget/packages.config
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/src/csharp/Grpc.Core.Tests/ChannelTest.cs b/src/csharp/Grpc.Core.Tests/ChannelTest.cs
index ed0ec14df5c..6330f50faed 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 77f6a63156b..6c13a4fa483 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(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
Assert.AreEqual(StatusCode.Unknown, ex.Status.StatusCode);
- var ex2 = Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
+ var ex2 = Assert.ThrowsAsync(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(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode);
- var ex2 = Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
+ var ex2 = Assert.ThrowsAsync(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(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode);
- var ex2 = Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc"));
+ var ex2 = Assert.ThrowsAsync(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(async () => await call.ResponseAsync);
+ var ex = Assert.ThrowsAsync(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 90c510ec61f..cec8c7ce6bb 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/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
index 3bfd49b10fe..0cd059c2327 100644
--- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
+++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
@@ -4,7 +4,7 @@
DebugAnyCPU{86EC5CB4-4EA2-40A2-8057-86542A0353BB}
- Library
+ ExeGrpc.Core.TestsGrpc.Core.Testsv4.5
@@ -35,29 +35,18 @@
..\keys\Grpc.snk
-
- ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll
- False
-
-
- ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll
- False
-
+
- ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
+ ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll
-
- ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll
- False
+
+ ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll
-
- ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll
- False
+
+ ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll
-
-
- False
- ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll
+
+ ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
@@ -94,6 +83,7 @@
+
diff --git a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
index fe6edb858bb..b4cb451d944 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 543f6375df1..60530d32508 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(() => resultTask.GetAwaiter().GetResult());
+ var ex = Assert.ThrowsAsync(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 37fb36946af..0663e77d1ea 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(async () => await call.ResponseStream.MoveNext());
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext());
Assert.AreEqual(StatusCode.Internal, ex.Status.StatusCode);
}
@@ -134,7 +134,7 @@ namespace Grpc.Core.Tests
{
helper.ClientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) =>
{
- Assert.Throws(async () => await requestStream.MoveNext());
+ Assert.ThrowsAsync(async () => await requestStream.MoveNext());
return "RESPONSE";
});
@@ -153,7 +153,7 @@ namespace Grpc.Core.Tests
[Test]
public void RequestSerializationError_AsyncUnary()
{
- Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "UNSERIALIZABLE_VALUE"));
+ Assert.ThrowsAsync(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(async () => await call.RequestStream.WriteAsync("UNSERIALIZABLE_VALUE"));
+ Assert.ThrowsAsync(async () => await call.RequestStream.WriteAsync("UNSERIALIZABLE_VALUE"));
await call.RequestStream.WriteAsync("B");
await call.RequestStream.CompleteAsync();
diff --git a/src/csharp/Grpc.Core.Tests/NUnitMain.cs b/src/csharp/Grpc.Core.Tests/NUnitMain.cs
new file mode 100644
index 00000000000..9c1d7bf3c8a
--- /dev/null
+++ b/src/csharp/Grpc.Core.Tests/NUnitMain.cs
@@ -0,0 +1,59 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Reflection;
+using Grpc.Core;
+using Grpc.Core.Logging;
+using NUnit.Common;
+using NUnitLite;
+
+namespace Grpc.Core.Tests
+{
+ ///
+ /// Provides entry point for NUnitLite
+ ///
+ public class NUnitMain
+ {
+ public static int Main(string[] args)
+ {
+ // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406.
+ GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error));
+#if DOTNET5_4
+ return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In);
+#else
+ return new AutoRun().Execute(args);
+#endif
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs
index a1648f36712..772beadd4a3 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(async (request, context) =>
{
- Assert.Throws(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null));
+ Assert.ThrowsAsync(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null));
return "PASS";
});
diff --git a/src/csharp/Grpc.Core.Tests/SanityTest.cs b/src/csharp/Grpc.Core.Tests/SanityTest.cs
index 343ab1e85a1..3830f0cbacf 100644
--- a/src/csharp/Grpc.Core.Tests/SanityTest.cs
+++ b/src/csharp/Grpc.Core.Tests/SanityTest.cs
@@ -38,6 +38,7 @@ using System.Reflection;
using Grpc.Core;
using Grpc.Core.Internal;
using Grpc.Core.Utils;
+using Newtonsoft.Json;
using NUnit.Framework;
namespace Grpc.Core.Tests
@@ -55,27 +56,23 @@ namespace Grpc.Core.Tests
[Test]
public void TestsJsonUpToDate()
{
- var testClasses = DiscoverAllTestClasses();
- string testsJson = GetTestsJson();
+ var discoveredTests = DiscoverAllTestClasses();
+ string discoveredTestsJson = JsonConvert.SerializeObject(discoveredTests, Formatting.Indented);
- // we don't have a JSON parser at hand, but check that the test class
- // name is contained in the file instead.
- foreach (var className in testClasses) {
- Assert.IsTrue(testsJson.Contains(className),
- string.Format("Test class \"{0}\" is missing in C# tests.json file", className));
- }
+ Assert.AreEqual(discoveredTestsJson, ReadTestsJson());
}
///
/// Gets list of all test classes obtained by inspecting all the test assemblies.
///
- private List DiscoverAllTestClasses()
+ private Dictionary> DiscoverAllTestClasses()
{
var assemblies = GetTestAssemblies();
- var testClasses = new List();
+ var testsByAssembly = new Dictionary>();
foreach (var assembly in assemblies)
{
+ var testClasses = new List();
foreach (var t in assembly.GetTypes())
{
foreach (var m in t.GetMethods())
@@ -89,16 +86,19 @@ namespace Grpc.Core.Tests
}
}
+ testClasses.Sort();
+ testsByAssembly.Add(assembly.GetName().Name, testClasses);
}
- testClasses.Sort();
- return testClasses;
+ return testsByAssembly;
}
- private string GetTestsJson()
+ ///
+ /// Reads contents of tests.json file.
+ ///
+ private string ReadTestsJson()
{
var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var testsJsonFile = Path.Combine(assemblyDir, "..", "..", "..", "tests.json");
-
return File.ReadAllText(testsJsonFile);
}
diff --git a/src/csharp/Grpc.Core.Tests/packages.config b/src/csharp/Grpc.Core.Tests/packages.config
index 610831dfe1e..aa7d951fdc7 100644
--- a/src/csharp/Grpc.Core.Tests/packages.config
+++ b/src/csharp/Grpc.Core.Tests/packages.config
@@ -1,6 +1,7 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj
index 251a6889464..95077a6ca5a 100644
--- a/src/csharp/Grpc.Core/Grpc.Core.csproj
+++ b/src/csharp/Grpc.Core/Grpc.Core.csproj
@@ -58,6 +58,7 @@
+
@@ -140,9 +141,7 @@
-
-
-
+
Resources\roots.pem
diff --git a/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs b/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
index da74e55a95f..5e8dced6414 100644
--- a/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
+++ b/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs
@@ -38,117 +38,28 @@ using System.Globalization;
namespace Grpc.Core.Logging
{
/// Logger that logs to System.Console.
- public class ConsoleLogger : ILogger
+ public class ConsoleLogger : TextWriterLogger
{
- // Format similar enough to C core log format except nanosecond precision is not supported.
- const string DateTimeFormatString = "MMdd HH:mm:ss.ffffff";
-
- readonly Type forType;
- readonly string forTypeString;
-
/// Creates a console logger not associated to any specific type.
public ConsoleLogger() : this(null)
{
}
/// Creates a console logger that logs messsage specific for given type.
- private ConsoleLogger(Type forType)
+ private ConsoleLogger(Type forType) : base(() => Console.Error, forType)
{
- this.forType = forType;
- if (forType != null)
- {
- var namespaceStr = forType.Namespace ?? "";
- if (namespaceStr.Length > 0)
- {
- namespaceStr += ".";
- }
- this.forTypeString = namespaceStr + forType.Name + " ";
- }
- else
- {
- this.forTypeString = "";
- }
}
///
/// Returns a logger associated with the specified type.
///
- public ILogger ForType()
+ public override ILogger ForType()
{
- if (typeof(T) == forType)
+ if (typeof(T) == AssociatedType)
{
return this;
}
return new ConsoleLogger(typeof(T));
}
-
- /// Logs a message with severity Debug.
- public void Debug(string message)
- {
- Log("D", message);
- }
-
- /// Logs a formatted message with severity Debug.
- public void Debug(string format, params object[] formatArgs)
- {
- Debug(string.Format(format, formatArgs));
- }
-
- /// Logs a message with severity Info.
- public void Info(string message)
- {
- Log("I", message);
- }
-
- /// Logs a formatted message with severity Info.
- public void Info(string format, params object[] formatArgs)
- {
- Info(string.Format(format, formatArgs));
- }
-
- /// Logs a message with severity Warning.
- public void Warning(string message)
- {
- Log("W", message);
- }
-
- /// Logs a formatted message with severity Warning.
- public void Warning(string format, params object[] formatArgs)
- {
- Warning(string.Format(format, formatArgs));
- }
-
- /// Logs a message and an associated exception with severity Warning.
- public void Warning(Exception exception, string message)
- {
- Warning(message + " " + exception);
- }
-
- /// Logs a message with severity Error.
- public void Error(string message)
- {
- Log("E", message);
- }
-
- /// Logs a formatted message with severity Error.
- public void Error(string format, params object[] formatArgs)
- {
- Error(string.Format(format, formatArgs));
- }
-
- /// Logs a message and an associated exception with severity Error.
- public void Error(Exception exception, string message)
- {
- Error(message + " " + exception);
- }
-
- private void Log(string severityString, string message)
- {
- Console.Error.WriteLine("{0}{1} {2}{3}",
- severityString,
- DateTime.Now.ToString(DateTimeFormatString, CultureInfo.InvariantCulture),
- forTypeString,
- message);
- }
}
}
diff --git a/src/csharp/Grpc.Core/Logging/TextWriterLogger.cs b/src/csharp/Grpc.Core/Logging/TextWriterLogger.cs
new file mode 100644
index 00000000000..397320ddffa
--- /dev/null
+++ b/src/csharp/Grpc.Core/Logging/TextWriterLogger.cs
@@ -0,0 +1,176 @@
+#region Copyright notice and license
+
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using Grpc.Core.Utils;
+
+namespace Grpc.Core.Logging
+{
+ /// Logger that logs to an arbitrary System.IO.TextWriter.
+ public class TextWriterLogger : ILogger
+ {
+ // Format similar enough to C core log format except nanosecond precision is not supported.
+ const string DateTimeFormatString = "MMdd HH:mm:ss.ffffff";
+
+ readonly Func textWriterProvider;
+ readonly Type forType;
+ readonly string forTypeString;
+
+ ///
+ /// Creates a console logger not associated to any specific type and writes to given System.IO.TextWriter.
+ /// User is responsible for providing an instance of TextWriter that is thread-safe.
+ ///
+ public TextWriterLogger(TextWriter textWriter) : this(() => textWriter)
+ {
+ GrpcPreconditions.CheckNotNull(textWriter);
+ }
+
+ ///
+ /// Creates a console logger not associated to any specific type and writes to a System.IO.TextWriter obtained from given provider.
+ /// User is responsible for providing an instance of TextWriter that is thread-safe.
+ ///
+ public TextWriterLogger(Func textWriterProvider) : this(textWriterProvider, null)
+ {
+ }
+
+ /// Creates a console logger that logs messsage specific for given type.
+ protected TextWriterLogger(Func textWriterProvider, Type forType)
+ {
+ this.textWriterProvider = GrpcPreconditions.CheckNotNull(textWriterProvider);
+ this.forType = forType;
+ if (forType != null)
+ {
+ var namespaceStr = forType.Namespace ?? "";
+ if (namespaceStr.Length > 0)
+ {
+ namespaceStr += ".";
+ }
+ this.forTypeString = namespaceStr + forType.Name + " ";
+ }
+ else
+ {
+ this.forTypeString = "";
+ }
+ }
+
+ ///
+ /// Returns a logger associated with the specified type.
+ ///
+ public virtual ILogger ForType()
+ {
+ if (typeof(T) == forType)
+ {
+ return this;
+ }
+ return new TextWriterLogger(this.textWriterProvider, typeof(T));
+ }
+
+ /// Logs a message with severity Debug.
+ public void Debug(string message)
+ {
+ Log("D", message);
+ }
+
+ /// Logs a formatted message with severity Debug.
+ public void Debug(string format, params object[] formatArgs)
+ {
+ Debug(string.Format(format, formatArgs));
+ }
+
+ /// Logs a message with severity Info.
+ public void Info(string message)
+ {
+ Log("I", message);
+ }
+
+ /// Logs a formatted message with severity Info.
+ public void Info(string format, params object[] formatArgs)
+ {
+ Info(string.Format(format, formatArgs));
+ }
+
+ /// Logs a message with severity Warning.
+ public void Warning(string message)
+ {
+ Log("W", message);
+ }
+
+ /// Logs a formatted message with severity Warning.
+ public void Warning(string format, params object[] formatArgs)
+ {
+ Warning(string.Format(format, formatArgs));
+ }
+
+ /// Logs a message and an associated exception with severity Warning.
+ public void Warning(Exception exception, string message)
+ {
+ Warning(message + " " + exception);
+ }
+
+ /// Logs a message with severity Error.
+ public void Error(string message)
+ {
+ Log("E", message);
+ }
+
+ /// Logs a formatted message with severity Error.
+ public void Error(string format, params object[] formatArgs)
+ {
+ Error(string.Format(format, formatArgs));
+ }
+
+ /// Logs a message and an associated exception with severity Error.
+ public void Error(Exception exception, string message)
+ {
+ Error(message + " " + exception);
+ }
+
+ /// Gets the type associated with this logger.
+ protected Type AssociatedType
+ {
+ get { return forType; }
+ }
+
+ private void Log(string severityString, string message)
+ {
+ textWriterProvider().WriteLine("{0}{1} {2}{3}",
+ severityString,
+ DateTime.Now.ToString(DateTimeFormatString, CultureInfo.InvariantCulture),
+ forTypeString,
+ message);
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj
index 9aeab059f95..cfe668b6bed 100644
--- a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj
+++ b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj
@@ -3,10 +3,8 @@
DebugAnyCPU
- 10.0.0
- 2.0{143B1C29-C442-4BE0-BF3F-A8F92288AC9F}
- Library
+ ExeGrpc.Examples.TestsGrpc.Examples.Testsv4.5
@@ -37,18 +35,19 @@
..\keys\Grpc.snk
-
- False
+
+ ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll
- ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
+ ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll
-
-
- False
+ ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll
+
+ ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll
+
@@ -56,6 +55,7 @@
+
diff --git a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs
index 290d42808e7..875202b9509 100644
--- a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs
+++ b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs
@@ -149,7 +149,7 @@ namespace Math.Tests
using (var call = client.Fib(new FibArgs { Limit = 0 },
deadline: DateTime.UtcNow.AddMilliseconds(500)))
{
- var ex = Assert.Throws(async () => await call.ResponseStream.ToListAsync());
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.ToListAsync());
// We can't guarantee the status code always DeadlineExceeded. See issue #2685.
Assert.Contains(ex.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal });
diff --git a/src/csharp/Grpc.Examples.Tests/NUnitMain.cs b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs
new file mode 100644
index 00000000000..ea87802766b
--- /dev/null
+++ b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs
@@ -0,0 +1,59 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Reflection;
+using Grpc.Core;
+using Grpc.Core.Logging;
+using NUnit.Common;
+using NUnitLite;
+
+namespace Grpc.Examples.Tests
+{
+ ///
+ /// Provides entry point for NUnitLite
+ ///
+ public class NUnitMain
+ {
+ public static int Main(string[] args)
+ {
+ // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406.
+ GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error));
+#if DOTNET5_4
+ return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In);
+#else
+ return new AutoRun().Execute(args);
+#endif
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Examples.Tests/packages.config b/src/csharp/Grpc.Examples.Tests/packages.config
index ed30d2d428e..ce030f9d777 100644
--- a/src/csharp/Grpc.Examples.Tests/packages.config
+++ b/src/csharp/Grpc.Examples.Tests/packages.config
@@ -1,6 +1,7 @@
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/csharp/Grpc.Examples/Grpc.Examples.csproj b/src/csharp/Grpc.Examples/Grpc.Examples.csproj
index 15b04c8d8b7..f0a0aa3a266 100644
--- a/src/csharp/Grpc.Examples/Grpc.Examples.csproj
+++ b/src/csharp/Grpc.Examples/Grpc.Examples.csproj
@@ -41,6 +41,9 @@
False..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll
+
+ ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll
+
diff --git a/src/csharp/Grpc.Examples/packages.config b/src/csharp/Grpc.Examples/packages.config
index dfb8304ad10..a424cd2ea02 100644
--- a/src/csharp/Grpc.Examples/packages.config
+++ b/src/csharp/Grpc.Examples/packages.config
@@ -2,5 +2,5 @@
-
+
\ No newline at end of file
diff --git a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj
index bb6488b4f12..0bea9c03e7a 100644
--- a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj
+++ b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj
@@ -1,11 +1,11 @@
-
+DebugAnyCPU{F8C6D937-C44B-4EE3-A431-B0FBAEACE47D}
- Library
+ ExePropertiesGrpc.HealthCheck.TestsGrpc.HealthCheck.Tests
@@ -37,13 +37,6 @@
..\keys\Grpc.snk
-
- False
- ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll
-
-
- ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
-
@@ -51,6 +44,15 @@
+
+ ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll
+
+
+ ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll
+
+
+ ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll
+
@@ -59,14 +61,15 @@
+
- {ccc4440e-49f7-4790-b0af-feabb0837ae7}
+ {CCC4440E-49F7-4790-B0AF-FEABB0837AE7}Grpc.Core
- {aa5e328a-8835-49d7-98ed-c29f2b3049f0}
+ {AA5E328A-8835-49D7-98ED-C29F2B3049F0}Grpc.HealthCheck
diff --git a/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs
new file mode 100644
index 00000000000..0820523f35c
--- /dev/null
+++ b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs
@@ -0,0 +1,59 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Reflection;
+using Grpc.Core;
+using Grpc.Core.Logging;
+using NUnit.Common;
+using NUnitLite;
+
+namespace Grpc.HealthCheck.Tests
+{
+ ///
+ /// Provides entry point for NUnitLite
+ ///
+ public class NUnitMain
+ {
+ public static int Main(string[] args)
+ {
+ // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406.
+ GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error));
+#if DOTNET5_4
+ return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In);
+#else
+ return new AutoRun().Execute(args);
+#endif
+ }
+ }
+}
diff --git a/src/csharp/Grpc.HealthCheck.Tests/packages.config b/src/csharp/Grpc.HealthCheck.Tests/packages.config
index 47280939791..8066d8fcebd 100644
--- a/src/csharp/Grpc.HealthCheck.Tests/packages.config
+++ b/src/csharp/Grpc.HealthCheck.Tests/packages.config
@@ -1,5 +1,6 @@
-
+
+
\ No newline at end of file
diff --git a/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs b/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs
index 99aa7290301..5fd0e14e78d 100644
--- a/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs
+++ b/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs
@@ -84,7 +84,7 @@ namespace Grpc.IntegrationTesting
{
var call = client.StreamingInputCall();
- var ex = Assert.Throws(async () => await call);
+ var ex = Assert.ThrowsAsync(async () => await call);
Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
}
@@ -93,7 +93,7 @@ namespace Grpc.IntegrationTesting
{
var call = client.StreamingOutputCall(new StreamingOutputCallRequest());
- var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext());
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext());
Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
}
@@ -102,7 +102,7 @@ namespace Grpc.IntegrationTesting
{
var call = client.FullDuplexCall();
- var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext());
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext());
Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode);
}
diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
index 7ea80b11f0d..c16d0e5c5d0 100644
--- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
+++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
@@ -4,7 +4,7 @@
DebugAnyCPU{C61154BA-DD4A-4838-8420-0162A28925E0}
- Library
+ ExeGrpc.IntegrationTestingGrpc.IntegrationTestingv4.5
@@ -38,47 +38,43 @@
..\keys\Grpc.snk
-
- False
- ..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll
- ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll
-
- False
+
+ ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll
+
+
+
+
+
+
+ ..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll
+
+ ..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.dll
-
- False
+ ..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.PlatformServices.dll
-
- False
+ ..\packages\Google.Apis.Core.1.11.1\lib\net45\Google.Apis.Core.dll
-
- False
+ ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll
-
- ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll
-
-
- False
+ ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
- ..\packages\NUnit.2.6.4\lib\nunit.framework.dll
+ ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll
-
-
- False
+ ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll
-
-
-
+
+ ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll
+
@@ -116,6 +112,7 @@
+
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index 7ca52219360..54365179603 100644
--- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
+++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
@@ -445,7 +445,7 @@ namespace Grpc.IntegrationTesting
await Task.Delay(1000);
cts.Cancel();
- var ex = Assert.Throws(async () => await call.ResponseAsync);
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseAsync);
Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode);
}
Console.WriteLine("Passed!");
@@ -471,7 +471,7 @@ namespace Grpc.IntegrationTesting
cts.Cancel();
- var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext());
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext());
Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode);
}
Console.WriteLine("Passed!");
@@ -493,7 +493,7 @@ namespace Grpc.IntegrationTesting
// Deadline was reached before write has started. Eat the exception and continue.
}
- var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext());
+ var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext());
Assert.AreEqual(StatusCode.DeadlineExceeded, ex.Status.StatusCode);
}
Console.WriteLine("Passed!");
@@ -572,7 +572,7 @@ namespace Grpc.IntegrationTesting
await call.RequestStream.WriteAsync(request);
await call.RequestStream.CompleteAsync();
- var e = Assert.Throws(async () => await call.ResponseStream.ToListAsync());
+ var e = Assert.ThrowsAsync(async () => await call.ResponseStream.ToListAsync());
Assert.AreEqual(StatusCode.Unknown, e.Status.StatusCode);
Assert.AreEqual(echoStatus.Message, e.Status.Detail);
}
diff --git a/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs
new file mode 100644
index 00000000000..d8902de08f5
--- /dev/null
+++ b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs
@@ -0,0 +1,59 @@
+#region Copyright notice and license
+
+// Copyright 2016, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#endregion
+
+using System;
+using System.Reflection;
+using Grpc.Core;
+using Grpc.Core.Logging;
+using NUnit.Common;
+using NUnitLite;
+
+namespace Grpc.IntegrationTesting
+{
+ ///
+ /// Provides entry point for NUnitLite
+ ///
+ public class NUnitMain
+ {
+ public static int Main(string[] args)
+ {
+ // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406.
+ GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error));
+#if DOTNET5_4
+ return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In);
+#else
+ return new AutoRun().Execute(args);
+#endif
+ }
+ }
+}
diff --git a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs
index ce108d808b6..774563d752f 100644
--- a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs
+++ b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs
@@ -35,6 +35,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Grpc.Core;
@@ -50,9 +51,29 @@ namespace Grpc.IntegrationTesting
{
public const string DefaultHostOverride = "foo.test.google.fr";
- public const string ClientCertAuthorityPath = "data/ca.pem";
- public const string ServerCertChainPath = "data/server1.pem";
- public const string ServerPrivateKeyPath = "data/server1.key";
+ public static string ClientCertAuthorityPath
+ {
+ get
+ {
+ return GetPath("data/ca.pem");
+ }
+ }
+
+ public static string ServerCertChainPath
+ {
+ get
+ {
+ return GetPath("data/server1.pem");
+ }
+ }
+
+ public static string ServerPrivateKeyPath
+ {
+ get
+ {
+ return GetPath("data/server1.key");
+ }
+ }
public static SslCredentials CreateSslCredentials()
{
@@ -66,5 +87,11 @@ namespace Grpc.IntegrationTesting
File.ReadAllText(ServerPrivateKeyPath));
return new SslServerCredentials(new[] { keyCertPair });
}
+
+ private static string GetPath(string relativePath)
+ {
+ var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ return Path.Combine(assemblyDir, relativePath);
+ }
}
}
diff --git a/src/csharp/Grpc.IntegrationTesting/packages.config b/src/csharp/Grpc.IntegrationTesting/packages.config
index 0ae8bf4e707..3fef67dca4f 100644
--- a/src/csharp/Grpc.IntegrationTesting/packages.config
+++ b/src/csharp/Grpc.IntegrationTesting/packages.config
@@ -8,5 +8,6 @@
-
+
+
\ No newline at end of file
diff --git a/src/csharp/tests.json b/src/csharp/tests.json
index 718bfa3287b..f733352a310 100644
--- a/src/csharp/tests.json
+++ b/src/csharp/tests.json
@@ -1,11 +1,5 @@
{
- "assemblies": [
- "Grpc.Core.Tests",
- "Grpc.Examples.Tests",
- "Grpc.HealthCheck.Tests",
- "Grpc.IntegrationTesting"
- ],
- "tests": [
+ "Grpc.Core.Tests": [
"Grpc.Core.Internal.Tests.AsyncCallTest",
"Grpc.Core.Internal.Tests.ChannelArgsSafeHandleTest",
"Grpc.Core.Internal.Tests.CompletionQueueEventTest",
@@ -32,13 +26,19 @@
"Grpc.Core.Tests.ServerTest",
"Grpc.Core.Tests.ShutdownTest",
"Grpc.Core.Tests.TimeoutsTest",
- "Grpc.Core.Tests.UserAgentStringTest",
- "Math.Tests.MathClientServerTest",
+ "Grpc.Core.Tests.UserAgentStringTest"
+ ],
+ "Grpc.Examples.Tests": [
+ "Math.Tests.MathClientServerTest"
+ ],
+ "Grpc.HealthCheck.Tests": [
"Grpc.HealthCheck.Tests.HealthClientServerTest",
- "Grpc.HealthCheck.Tests.HealthServiceImplTest",
- "Grpc.IntegrationTesting.HistogramTest",
+ "Grpc.HealthCheck.Tests.HealthServiceImplTest"
+ ],
+ "Grpc.IntegrationTesting": [
"Grpc.IntegrationTesting.GeneratedClientTest",
"Grpc.IntegrationTesting.GeneratedServiceBaseTest",
+ "Grpc.IntegrationTesting.HistogramTest",
"Grpc.IntegrationTesting.InteropClientServerTest",
"Grpc.IntegrationTesting.MetadataCredentialsTest",
"Grpc.IntegrationTesting.RunnerClientServerTest",
diff --git a/tools/dockerfile/grpc_interop_csharp/Dockerfile b/tools/dockerfile/grpc_interop_csharp/Dockerfile
index 3789cd32038..93cd25010ef 100644
--- a/tools/dockerfile/grpc_interop_csharp/Dockerfile
+++ b/tools/dockerfile/grpc_interop_csharp/Dockerfile
@@ -80,13 +80,9 @@ RUN echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat
# Install dependencies
RUN apt-get update && apt-get -y dist-upgrade && apt-get install -y \
mono-devel \
- nunit \
- nunit-console \
- monodevelop
-
-# Download NuGet
-RUN cd /var/local && wget www.nuget.org/NuGet.exe
-ENV NUGET mono /var/local/NuGet.exe
+ ca-certificates-mono \
+ nuget \
+ && apt-get clean
# Define the default command.
CMD ["bash"]
diff --git a/tools/dockerfile/grpc_interop_csharp/build_interop.sh b/tools/dockerfile/grpc_interop_csharp/build_interop.sh
index dc1f7a331ab..fd5436c44ff 100755
--- a/tools/dockerfile/grpc_interop_csharp/build_interop.sh
+++ b/tools/dockerfile/grpc_interop_csharp/build_interop.sh
@@ -40,6 +40,4 @@ cp -r /var/local/jenkins/service_account $HOME || true
cd /var/local/git/grpc
# build C# interop client & server
-make CONFIG=dbg grpc_csharp_ext
-(cd src/csharp && mono /var/local/NuGet.exe restore Grpc.sln)
-(cd src/csharp && xbuild Grpc.sln)
+tools/run_tests/run_tests.py -l csharp -c dbg --build_only
diff --git a/tools/run_tests/post_tests_csharp.bat b/tools/run_tests/post_tests_csharp.bat
new file mode 100644
index 00000000000..7851b9137ac
--- /dev/null
+++ b/tools/run_tests/post_tests_csharp.bat
@@ -0,0 +1,25 @@
+@rem Runs C# tests for given assembly from command line. The Grpc.sln solution needs to be built before running the tests.
+
+setlocal
+
+if not "%CONFIG%" == "gcov" (
+ goto :EOF
+)
+
+@rem enter src/csharp directory
+cd /d %~dp0\..\..\src\csharp
+
+@rem Generate code coverage report
+@rem TODO(jtattermusch): currently the report list is hardcoded
+packages\ReportGenerator.2.4.4.0\tools\ReportGenerator.exe -reports:"coverage_csharp_*.xml" -targetdir:"..\..\reports\csharp_coverage" -reporttypes:"Html;TextSummary" || goto :error
+
+@rem Generate the index.html file
+echo ^^^^^csharp coverage^^ ^^ >..\..\reports\index.html
+
+endlocal
+
+goto :EOF
+
+:error
+echo Failed!
+exit /b %errorlevel%
diff --git a/tools/run_tests/run_csharp.sh b/tools/run_tests/post_tests_csharp.sh
similarity index 73%
rename from tools/run_tests/run_csharp.sh
rename to tools/run_tests/post_tests_csharp.sh
index dad44c4e4f6..bb6f5c6e188 100755
--- a/tools/run_tests/run_csharp.sh
+++ b/tools/run_tests/post_tests_csharp.sh
@@ -30,23 +30,15 @@
set -ex
-CONFIG=${CONFIG:-opt}
-NUNIT_CONSOLE="mono packages/NUnit.Runners.2.6.4/tools/nunit-console.exe"
+if [ "$CONFIG" != "gcov" ] ; then exit ; fi
# change to gRPC repo root
cd $(dirname $0)/../..
-(cd src/csharp; $NUNIT_CONSOLE $@)
-
-if [ "$CONFIG" = "gcov" ]
-then
- # Generate the csharp extension coverage report
- gcov objs/gcov/src/csharp/ext/*.o
- lcov --base-directory . --directory . -c -o coverage.info
- lcov -e coverage.info '**/src/csharp/ext/*' -o coverage.info
- genhtml -o reports/csharp_ext_coverage --num-spaces 2 \
- -t 'gRPC C# native extension test coverage' coverage.info \
- --rc genhtml_hi_limit=95 --rc genhtml_med_limit=80 --no-prefix
-fi
-
-
+# Generate the csharp extension coverage report
+gcov objs/gcov/src/csharp/ext/*.o
+lcov --base-directory . --directory . -c -o coverage.info
+lcov -e coverage.info '**/src/csharp/ext/*' -o coverage.info
+genhtml -o reports/csharp_ext_coverage --num-spaces 2 \
+ -t 'gRPC C# native extension test coverage' coverage.info \
+ --rc genhtml_hi_limit=95 --rc genhtml_med_limit=80 --no-prefix
diff --git a/tools/run_tests/run_csharp.bat b/tools/run_tests/run_csharp.bat
deleted file mode 100644
index 29c879e23be..00000000000
--- a/tools/run_tests/run_csharp.bat
+++ /dev/null
@@ -1,27 +0,0 @@
-@rem Runs C# tests for given assembly from command line. The Grpc.sln solution needs to be built before running the tests.
-
-setlocal
-
-@rem enter src/csharp directory
-cd /d %~dp0\..\..\src\csharp
-
-if not "%CONFIG%" == "gcov" (
- packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe %* || goto :error
-) else (
- @rem Run all tests with code coverage
-
- packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe" -targetdir:"." -targetargs:"%*" -filter:"+[Grpc.Core]*" -register:user -output:coverage_results.xml || goto :error
-
- packages\ReportGenerator.2.4.4.0\tools\ReportGenerator.exe -reports:"coverage_results.xml" -targetdir:"..\..\reports\csharp_coverage" -reporttypes:"Html;TextSummary" || goto :error
-
- @rem Generate the index.html file
- echo ^^^^^csharp coverage^^ ^^ >..\..\reports\index.html
-)
-
-endlocal
-
-goto :EOF
-
-:error
-echo Failed!
-exit /b %errorlevel%
diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py
index dfac94660b6..9dff686bbf6 100755
--- a/tools/run_tests/run_tests.py
+++ b/tools/run_tests/run_tests.py
@@ -486,41 +486,48 @@ class CSharpLanguage(object):
def test_specs(self):
with open('src/csharp/tests.json') as f:
- tests_json = json.load(f)
- assemblies = tests_json['assemblies']
- tests = tests_json['tests']
+ tests_by_assembly = json.load(f)
msbuild_config = _MSBUILD_CONFIG[self.config.build_config]
- assembly_files = ['%s/bin/%s/%s.dll' % (a, msbuild_config, a)
- for a in assemblies]
-
- extra_args = ['-labels'] + assembly_files
-
+ nunit_args = ['--labels=All',
+ '--noresult',
+ '--workers=1']
if self.platform == 'windows':
- script_name = 'tools\\run_tests\\run_csharp.bat'
- extra_args += ['-domain=None']
+ runtime_cmd = []
else:
- script_name = 'tools/run_tests/run_csharp.sh'
-
- if self.config.build_config == 'gcov':
- # On Windows, we only collect C# code coverage.
- # On Linux, we only collect coverage for native extension.
- # For code coverage all tests need to run as one suite.
- return [self.config.job_spec([script_name] + extra_args, None,
- shortname='csharp.coverage',
- environ=_FORCE_ENVIRON_FOR_WRAPPERS)]
- else:
- specs = []
- for test in tests:
- cmdline = [script_name, '-run=%s' % test] + extra_args
- if self.platform == 'windows':
- # use different output directory for each test to prevent
- # TestResult.xml clash between parallel test runs.
- cmdline += ['-work=test-result/%s' % uuid.uuid4()]
- specs.append(self.config.job_spec(cmdline, None,
- shortname='csharp.%s' % test,
+ runtime_cmd = ['mono']
+
+ specs = []
+ for assembly in tests_by_assembly.iterkeys():
+ assembly_file = 'src/csharp/%s/bin/%s/%s.exe' % (assembly, msbuild_config, assembly)
+ if self.config.build_config != 'gcov' or self.platform != 'windows':
+ # normally, run each test as a separate process
+ for test in tests_by_assembly[assembly]:
+ cmdline = runtime_cmd + [assembly_file, '--test=%s' % test] + nunit_args
+ specs.append(self.config.job_spec(cmdline,
+ None,
+ shortname='csharp.%s' % test,
+ environ=_FORCE_ENVIRON_FOR_WRAPPERS))
+ else:
+ # For C# test coverage, run all tests from the same assembly at once
+ # using OpenCover.Console (only works on Windows).
+ cmdline = ['src\\csharp\\packages\\OpenCover.4.6.519\\tools\\OpenCover.Console.exe',
+ '-target:%s' % assembly_file,
+ '-targetdir:src\\csharp',
+ '-targetargs:%s' % ' '.join(nunit_args),
+ '-filter:+[Grpc.Core]*',
+ '-register:user',
+ '-output:src\\csharp\\coverage_csharp_%s.xml' % assembly]
+
+ # set really high cpu_cost to make sure instances of OpenCover.Console run exclusively
+ # to prevent problems with registering the profiler.
+ run_exclusive = 1000000
+ specs.append(self.config.job_spec(cmdline,
+ None,
+ shortname='csharp.coverage.%s' % assembly,
+ cpu_cost=run_exclusive,
environ=_FORCE_ENVIRON_FOR_WRAPPERS))
- return specs
+ return specs
def pre_build_steps(self):
if self.platform == 'windows':
@@ -543,7 +550,10 @@ class CSharpLanguage(object):
return [['tools/run_tests/build_csharp.sh']]
def post_tests_steps(self):
- return []
+ if self.platform == 'windows':
+ return [['tools\\run_tests\\post_tests_csharp.bat']]
+ else:
+ return [['tools/run_tests/post_tests_csharp.sh']]
def makefile_name(self):
return 'Makefile'