aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/csharp/Grpc.Core.Tests')
-rw-r--r--src/csharp/Grpc.Core.Tests/AuthContextTest.cs86
-rw-r--r--src/csharp/Grpc.Core.Tests/AuthPropertyTest.cs (renamed from src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs)55
-rw-r--r--src/csharp/Grpc.Core.Tests/ClientServerTest.cs12
-rw-r--r--src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj19
-rw-r--r--src/csharp/Grpc.Core.Tests/TestResult.xml41
-rw-r--r--src/csharp/Grpc.Core.Tests/packages.config7
-rw-r--r--src/csharp/Grpc.Core.Tests/project.json8
7 files changed, 145 insertions, 83 deletions
diff --git a/src/csharp/Grpc.Core.Tests/AuthContextTest.cs b/src/csharp/Grpc.Core.Tests/AuthContextTest.cs
new file mode 100644
index 0000000000..f5fa469520
--- /dev/null
+++ b/src/csharp/Grpc.Core.Tests/AuthContextTest.cs
@@ -0,0 +1,86 @@
+#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 NUnit.Framework;
+using Grpc.Core;
+using System.Linq;
+
+namespace Grpc.Core.Tests
+{
+ public class AuthContextTest
+ {
+ [Test]
+ public void EmptyContext()
+ {
+ var context = new AuthContext(null, new Dictionary<string, List<AuthProperty>>());
+ Assert.IsFalse(context.IsPeerAuthenticated);
+ Assert.IsNull(context.PeerIdentityPropertyName);
+ Assert.AreEqual(0, context.PeerIdentity.Count());
+ Assert.AreEqual(0, context.Properties.Count());
+ Assert.AreEqual(0, context.FindPropertiesByName("nonexistent").Count());
+ }
+
+ [Test]
+ public void AuthenticatedContext()
+ {
+ var property1 = AuthProperty.Create("abc", new byte[] { 68, 69, 70 });
+ var context = new AuthContext("some_identity", new Dictionary<string, List<AuthProperty>>
+ {
+ {"some_identity", new List<AuthProperty> {property1}}
+ });
+ Assert.IsTrue(context.IsPeerAuthenticated);
+ Assert.AreEqual("some_identity", context.PeerIdentityPropertyName);
+ Assert.AreEqual(1, context.PeerIdentity.Count());
+ }
+
+ [Test]
+ public void FindPropertiesByName()
+ {
+ var property1 = AuthProperty.Create("abc", new byte[] {68, 69, 70});
+ var property2 = AuthProperty.Create("abc", new byte[] {71, 72, 73 });
+ var property3 = AuthProperty.Create("abc", new byte[] {});
+ var context = new AuthContext(null, new Dictionary<string, List<AuthProperty>>
+ {
+ {"existent", new List<AuthProperty> {property1, property2}},
+ {"foobar", new List<AuthProperty> {property3}},
+ });
+ Assert.AreEqual(3, context.Properties.Count());
+ Assert.AreEqual(0, context.FindPropertiesByName("nonexistent").Count());
+
+ var existentProperties = new List<AuthProperty>(context.FindPropertiesByName("existent"));
+ Assert.AreEqual(2, existentProperties.Count);
+ }
+ }
+}
diff --git a/src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs b/src/csharp/Grpc.Core.Tests/AuthPropertyTest.cs
index 1a9e441611..745191b80d 100644
--- a/src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs
+++ b/src/csharp/Grpc.Core.Tests/AuthPropertyTest.cs
@@ -32,46 +32,51 @@
#endregion
using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Grpc.Core;
-using Grpc.Core.Internal;
-using Grpc.Core.Utils;
using NUnit.Framework;
namespace Grpc.Core.Tests
{
- /// <summary>
- /// Tests if the version of nunit-console used is sufficient to run async tests.
- /// </summary>
- public class NUnitVersionTest
+ public class AuthPropertyTest
{
- private int testRunCount = 0;
+ [Test]
+ public void Create_NameIsNotNull()
+ {
+ Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create(null, new byte[0]));
+ Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe(null, new byte[0]));
+ }
- [TestFixtureTearDown]
- public void Cleanup()
+ [Test]
+ public void Create_ValueIsNotNull()
{
- if (testRunCount != 2)
- {
- Console.Error.WriteLine("You are using and old version of NUnit that doesn't support async tests and skips them instead. " +
- "This test has failed to indicate that.");
- Console.Error.Flush();
- throw new Exception("NUnitVersionTest has failed.");
- }
+ Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create("abc", null));
+ Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe("abc", null));
}
[Test]
- public void NUnitVersionTest1()
+ public void Create()
{
- testRunCount++;
+ var valueBytes = new byte[] { 68, 69, 70 };
+ var authProperty = AuthProperty.Create("abc", valueBytes);
+
+ Assert.AreEqual("abc", authProperty.Name);
+ Assert.AreNotSame(valueBytes, authProperty.ValueBytesUnsafe);
+ CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytes);
+ CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytesUnsafe);
+ Assert.AreEqual("DEF", authProperty.Value);
}
- // Old version of NUnit will skip this test
[Test]
- public async Task NUnitVersionTest2()
+ public void CreateUnsafe()
{
- testRunCount++;
- await Task.Delay(10);
+ var valueBytes = new byte[] { 68, 69, 70 };
+ var authProperty = AuthProperty.CreateUnsafe("abc", valueBytes);
+
+ Assert.AreEqual("abc", authProperty.Name);
+ Assert.AreSame(valueBytes, authProperty.ValueBytesUnsafe);
+ Assert.AreNotSame(valueBytes, authProperty.ValueBytes);
+ CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytes);
+ CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytesUnsafe);
+ Assert.AreEqual("DEF", authProperty.Value);
}
}
}
diff --git a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs
index 6bf9756962..3a99107c42 100644
--- a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs
@@ -376,6 +376,18 @@ namespace Grpc.Core.Tests
}
[Test]
+ public void ServerCallContext_AuthContextNotPopulated()
+ {
+ helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
+ {
+ Assert.IsFalse(context.AuthContext.IsPeerAuthenticated);
+ Assert.AreEqual(0, context.AuthContext.Properties.Count());
+ return "PASS";
+ });
+ Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"));
+ }
+
+ [Test]
public async Task Channel_WaitForStateChangedAsync()
{
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
index 646effe21a..a1a2e4eebd 100644
--- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
+++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
@@ -27,17 +27,17 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="nunit.framework">
- <HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
- </Reference>
- <Reference Include="nunitlite">
- <HintPath>..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll</HintPath>
+ <Reference Include="System.Interactive.Async">
+ <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
- <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
- <Reference Include="System.Interactive.Async">
- <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath>
+ <Reference Include="nunit.framework">
+ <HintPath>..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="nunitlite">
+ <HintPath>..\packages\NUnitLite.3.6.0\lib\net45\nunitlite.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -64,7 +64,6 @@
<Compile Include="ChannelOptionsTest.cs" />
<Compile Include="Internal\TimespecTest.cs" />
<Compile Include="TimeoutsTest.cs" />
- <Compile Include="NUnitVersionTest.cs" />
<Compile Include="ChannelTest.cs" />
<Compile Include="MockServiceHelper.cs" />
<Compile Include="ResponseHeadersTest.cs" />
@@ -81,6 +80,8 @@
<Compile Include="ShutdownHookPendingCallTest.cs" />
<Compile Include="ShutdownHookClientTest.cs" />
<Compile Include="AppDomainUnloadTest.cs" />
+ <Compile Include="AuthContextTest.cs" />
+ <Compile Include="AuthPropertyTest.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/src/csharp/Grpc.Core.Tests/TestResult.xml b/src/csharp/Grpc.Core.Tests/TestResult.xml
deleted file mode 100644
index 13da80739c..0000000000
--- a/src/csharp/Grpc.Core.Tests/TestResult.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="no"?>
-<!--This file represents the results of running a test suite-->
-<test-results name="/usr/local/google/home/jtattermusch/github/grpc/src/csharp/GrpcCoreTests/bin/Debug/GrpcCoreTests.dll" total="3" errors="0" failures="0" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2015-01-29" time="19:40:47">
- <environment nunit-version="2.6.0.0" clr-version="4.0.30319.17020" os-version="Unix 3.13.0.43" platform="Unix" cwd="/usr/local/google/home/jtattermusch/github/grpc/src/csharp/GrpcCoreTests" machine-name="jtattermusch.mtv.corp.google.com" user="jtattermusch" user-domain="jtattermusch.mtv.corp.google.com" />
- <culture-info current-culture="en-US" current-uiculture="en-US" />
- <test-suite type="Assembly" name="/usr/local/google/home/jtattermusch/github/grpc/src/csharp/GrpcCoreTests/bin/Debug/GrpcCoreTests.dll" executed="True" result="Success" success="True" time="0.172" asserts="0">
- <results>
- <test-suite type="Namespace" name="Google" executed="True" result="Success" success="True" time="0.166" asserts="0">
- <results>
- <test-suite type="Namespace" name="GRPC" executed="True" result="Success" success="True" time="0.166" asserts="0">
- <results>
- <test-suite type="Namespace" name="Core" executed="True" result="Success" success="True" time="0.166" asserts="0">
- <results>
- <test-suite type="Namespace" name="Tests" executed="True" result="Success" success="True" time="0.166" asserts="0">
- <results>
- <test-suite type="TestFixture" name="CallsTest" executed="True" result="Success" success="True" time="0.009" asserts="0">
- <results>
- <test-case name="Grpc.Core.Tests.CallsTest.Test1" executed="True" result="Success" success="True" time="0.004" asserts="0" />
- </results>
- </test-suite>
- <test-suite type="TestFixture" name="ClientServerTest" executed="True" result="Success" success="True" time="0.149" asserts="0">
- <results>
- <test-case name="Grpc.Core.Tests.ClientServerTest.EmptyCall" executed="True" result="Success" success="True" time="0.111" asserts="0" />
- </results>
- </test-suite>
- <test-suite type="TestFixture" name="ServerTest" executed="True" result="Success" success="True" time="0.001" asserts="0">
- <results>
- <test-case name="Grpc.Core.Tests.ServerTest.StartAndShutdownServer" executed="True" result="Success" success="True" time="0.001" asserts="0" />
- </results>
- </test-suite>
- </results>
- </test-suite>
- </results>
- </test-suite>
- </results>
- </test-suite>
- </results>
- </test-suite>
- </results>
- </test-suite>
-</test-results> \ No newline at end of file
diff --git a/src/csharp/Grpc.Core.Tests/packages.config b/src/csharp/Grpc.Core.Tests/packages.config
index 4750735fad..994a278762 100644
--- a/src/csharp/Grpc.Core.Tests/packages.config
+++ b/src/csharp/Grpc.Core.Tests/packages.config
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
- <package id="NUnit" version="3.2.0" targetFramework="net45" />
- <package id="NUnit.ConsoleRunner" version="3.2.0" />
- <package id="NUnitLite" version="3.2.0" targetFramework="net45" />
+ <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
+ <package id="NUnit" version="3.6.0" targetFramework="net45" />
+ <package id="NUnitLite" version="3.6.0" targetFramework="net45" />
<package id="OpenCover" version="4.6.519" />
<package id="ReportGenerator" version="2.4.4.0" />
<package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" />
diff --git a/src/csharp/Grpc.Core.Tests/project.json b/src/csharp/Grpc.Core.Tests/project.json
index 045207a413..14e5ed51ad 100644
--- a/src/csharp/Grpc.Core.Tests/project.json
+++ b/src/csharp/Grpc.Core.Tests/project.json
@@ -45,10 +45,10 @@
"Grpc.Core": {
"target": "project"
},
- "Newtonsoft.Json": "8.0.3",
- "NUnit": "3.2.0",
- "NUnitLite": "3.2.0-*",
- "NUnit.ConsoleRunner": "3.2.0",
+ "Newtonsoft.Json": "9.0.1",
+ "NUnit": "3.6.0",
+ "NUnitLite": "3.6.0",
+ "NUnit.ConsoleRunner": "3.6.0",
"OpenCover": "4.6.519",
"ReportGenerator": "2.4.4.0"
},