blob: 7e913b3b8b8000fe16b8b517460e1f14614f3172 [file] [log] [blame]
Jan Tattermusch20831382015-02-24 14:16:04 -08001#region Copyright notice and license
2
3// Copyright 2015, Google Inc.
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#endregion
33
34using System;
35using System.Collections.Generic;
36using System.Threading;
37using System.Threading.Tasks;
Jan Tattermusch075dde42015-03-11 18:21:00 -070038using grpc.testing;
Jan Tattermusch20831382015-02-24 14:16:04 -080039using Grpc.Core;
40using Grpc.Core.Utils;
41using NUnit.Framework;
Jan Tattermusch20831382015-02-24 14:16:04 -080042
43namespace Grpc.IntegrationTesting
44{
45 /// <summary>
46 /// Runs interop tests in-process.
47 /// </summary>
48 public class InteropClientServerTest
49 {
50 string host = "localhost";
51 Server server;
52 Channel channel;
Jan Tattermusch7eb3a762015-05-07 14:26:13 -070053 TestService.ITestServiceClient client;
Jan Tattermusch20831382015-02-24 14:16:04 -080054
55 [TestFixtureSetUp]
56 public void Init()
57 {
Jan Tattermusch20831382015-02-24 14:16:04 -080058 server = new Server();
Jan Tattermusch7eb3a762015-05-07 14:26:13 -070059 server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
Jan Tattermuscha96ac052015-07-24 14:49:30 -070060 int port = server.AddPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
Jan Tattermusch20831382015-02-24 14:16:04 -080061 server.Start();
Jan Tattermuschb0829eb2015-03-03 09:30:55 -080062
Jan Tattermuschc8f7d102015-06-08 17:53:45 -070063 var options = new List<ChannelOption>
64 {
Jan Tattermusch2ddb5a62015-06-08 17:51:36 -070065 new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
66 };
67 channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options);
Jan Tattermuschb5332812015-07-14 19:29:35 -070068 client = TestService.NewClient(channel);
Jan Tattermusch20831382015-02-24 14:16:04 -080069 }
70
71 [TestFixtureTearDown]
72 public void Cleanup()
73 {
74 channel.Dispose();
Jan Tattermusch20831382015-02-24 14:16:04 -080075 server.ShutdownAsync().Wait();
76 GrpcEnvironment.Shutdown();
77 }
78
79 [Test]
80 public void EmptyUnary()
81 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -080082 InteropClient.RunEmptyUnary(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080083 }
84
85 [Test]
86 public void LargeUnary()
87 {
Jan Tattermuscha5272b62015-04-30 11:56:46 -070088 InteropClient.RunLargeUnary(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080089 }
90
91 [Test]
92 public void ClientStreaming()
93 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -080094 InteropClient.RunClientStreaming(client);
Jan Tattermusch20831382015-02-24 14:16:04 -080095 }
96
97 [Test]
98 public void ServerStreaming()
99 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -0800100 InteropClient.RunServerStreaming(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800101 }
102
103 [Test]
104 public void PingPong()
105 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -0800106 InteropClient.RunPingPong(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800107 }
108
109 [Test]
110 public void EmptyStream()
111 {
Jan Tattermusch503bbac2015-02-26 18:19:47 -0800112 InteropClient.RunEmptyStream(client);
Jan Tattermusch20831382015-02-24 14:16:04 -0800113 }
114
Jan Tattermusche5c44602015-05-01 11:12:34 -0700115 [Test]
116 public void CancelAfterBegin()
117 {
118 InteropClient.RunCancelAfterBegin(client);
119 }
Jan Tattermusch20831382015-02-24 14:16:04 -0800120
Jan Tattermusche5c44602015-05-01 11:12:34 -0700121 [Test]
122 public void CancelAfterFirstResponse()
123 {
124 InteropClient.RunCancelAfterFirstResponse(client);
125 }
Jan Tattermusch20831382015-02-24 14:16:04 -0800126 }
127}