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 System.Collections.Generic; 21 using Grpc.Core; 22 using Grpc.Core.Internal; 23 using Grpc.Core.Utils; 24 using NUnit.Framework; 25 26 namespace Grpc.Core.Tests 27 { 28 public class ChannelOptionsTest 29 { 30 [Test] IntOption()31 public void IntOption() 32 { 33 var option = new ChannelOption("somename", 1); 34 35 Assert.AreEqual(ChannelOption.OptionType.Integer, option.Type); 36 Assert.AreEqual("somename", option.Name); 37 Assert.AreEqual(1, option.IntValue); 38 Assert.Throws(typeof(InvalidOperationException), () => { var s = option.StringValue; }); 39 } 40 41 [Test] StringOption()42 public void StringOption() 43 { 44 var option = new ChannelOption("somename", "ABCDEF"); 45 46 Assert.AreEqual(ChannelOption.OptionType.String, option.Type); 47 Assert.AreEqual("somename", option.Name); 48 Assert.AreEqual("ABCDEF", option.StringValue); 49 Assert.Throws(typeof(InvalidOperationException), () => { var s = option.IntValue; }); 50 } 51 52 [Test] ConstructorPreconditions()53 public void ConstructorPreconditions() 54 { 55 Assert.Throws(typeof(ArgumentNullException), () => { new ChannelOption(null, "abc"); }); 56 Assert.Throws(typeof(ArgumentNullException), () => { new ChannelOption(null, 1); }); 57 Assert.Throws(typeof(ArgumentNullException), () => { new ChannelOption("abc", null); }); 58 } 59 60 [Test] CreateChannelArgsNull()61 public void CreateChannelArgsNull() 62 { 63 var channelArgs = ChannelOptions.CreateChannelArgs(null); 64 Assert.IsTrue(channelArgs.IsInvalid); 65 } 66 67 [Test] CreateChannelArgsEmpty()68 public void CreateChannelArgsEmpty() 69 { 70 var options = new List<ChannelOption>(); 71 var channelArgs = ChannelOptions.CreateChannelArgs(options); 72 channelArgs.Dispose(); 73 } 74 75 [Test] CreateChannelArgs()76 public void CreateChannelArgs() 77 { 78 var options = new List<ChannelOption> 79 { 80 new ChannelOption("ABC", "XYZ"), 81 new ChannelOption("somename", "IJKLM"), 82 new ChannelOption("intoption", 12345), 83 new ChannelOption("GHIJK", 12345), 84 }; 85 86 var channelArgs = ChannelOptions.CreateChannelArgs(options); 87 channelArgs.Dispose(); 88 } 89 } 90 } 91