1 #region Copyright notice and license 2 3 // Copyright 2015 gRPC authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 #endregion 18 19 using System; 20 using NUnit.Framework; 21 22 namespace Grpc.Core.Tests 23 { 24 public class AuthPropertyTest 25 { 26 [Test] Create_NameIsNotNull()27 public void Create_NameIsNotNull() 28 { 29 Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create(null, new byte[0])); 30 Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe(null, new byte[0])); 31 } 32 33 [Test] Create_ValueIsNotNull()34 public void Create_ValueIsNotNull() 35 { 36 Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create("abc", null)); 37 Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe("abc", null)); 38 } 39 40 [Test] Create()41 public void Create() 42 { 43 var valueBytes = new byte[] { 68, 69, 70 }; 44 var authProperty = AuthProperty.Create("abc", valueBytes); 45 46 Assert.AreEqual("abc", authProperty.Name); 47 Assert.AreNotSame(valueBytes, authProperty.ValueBytesUnsafe); 48 CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytes); 49 CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytesUnsafe); 50 Assert.AreEqual("DEF", authProperty.Value); 51 } 52 53 [Test] CreateUnsafe()54 public void CreateUnsafe() 55 { 56 var valueBytes = new byte[] { 68, 69, 70 }; 57 var authProperty = AuthProperty.CreateUnsafe("abc", valueBytes); 58 59 Assert.AreEqual("abc", authProperty.Name); 60 Assert.AreSame(valueBytes, authProperty.ValueBytesUnsafe); 61 Assert.AreNotSame(valueBytes, authProperty.ValueBytes); 62 CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytes); 63 CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytesUnsafe); 64 Assert.AreEqual("DEF", authProperty.Value); 65 } 66 } 67 } 68