aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core.Tests/ServerTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.Core.Tests/ServerTest.cs')
-rw-r--r--src/csharp/Grpc.Core.Tests/ServerTest.cs39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/csharp/Grpc.Core.Tests/ServerTest.cs b/src/csharp/Grpc.Core.Tests/ServerTest.cs
index 1119aa370e..485006ebac 100644
--- a/src/csharp/Grpc.Core.Tests/ServerTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ServerTest.cs
@@ -32,6 +32,7 @@
#endregion
using System;
+using System.Linq;
using Grpc.Core;
using Grpc.Core.Internal;
using Grpc.Core.Utils;
@@ -44,11 +45,45 @@ namespace Grpc.Core.Tests
[Test]
public void StartAndShutdownServer()
{
- Server server = new Server();
- server.AddListeningPort("localhost", Server.PickUnusedPort);
+ Server server = new Server
+ {
+ Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
+ };
server.Start();
server.ShutdownAsync().Wait();
GrpcEnvironment.Shutdown();
}
+
+ [Test]
+ public void PickUnusedPort()
+ {
+ Server server = new Server
+ {
+ Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
+ };
+
+ var boundPort = server.Ports.Single();
+ Assert.AreEqual(0, boundPort.Port);
+ Assert.Greater(boundPort.BoundPort, 0);
+
+ server.Start();
+ server.ShutdownAsync();
+ GrpcEnvironment.Shutdown();
+ }
+
+ [Test]
+ public void CannotModifyAfterStarted()
+ {
+ Server server = new Server
+ {
+ Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
+ };
+ server.Start();
+ Assert.Throws(typeof(InvalidOperationException), () => server.Ports.Add("localhost", 9999, ServerCredentials.Insecure));
+ Assert.Throws(typeof(InvalidOperationException), () => server.Services.Add(ServerServiceDefinition.CreateBuilder("serviceName").Build()));
+
+ server.ShutdownAsync().Wait();
+ GrpcEnvironment.Shutdown();
+ }
}
}