OLD | NEW |
(Empty) | |
| 1 #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 |
| 34 using System; |
| 35 using System.Collections.Generic; |
| 36 using Grpc.Core; |
| 37 using Grpc.Core.Internal; |
| 38 using Grpc.Core.Utils; |
| 39 using NUnit.Framework; |
| 40 |
| 41 namespace Grpc.Core.Tests |
| 42 { |
| 43 public class ChannelOptionsTest |
| 44 { |
| 45 [Test] |
| 46 public void IntOption() |
| 47 { |
| 48 var option = new ChannelOption("somename", 1); |
| 49 |
| 50 Assert.AreEqual(ChannelOption.OptionType.Integer, option.Type); |
| 51 Assert.AreEqual("somename", option.Name); |
| 52 Assert.AreEqual(1, option.IntValue); |
| 53 Assert.Throws(typeof(InvalidOperationException), () => { var s = opt
ion.StringValue; }); |
| 54 } |
| 55 |
| 56 [Test] |
| 57 public void StringOption() |
| 58 { |
| 59 var option = new ChannelOption("somename", "ABCDEF"); |
| 60 |
| 61 Assert.AreEqual(ChannelOption.OptionType.String, option.Type); |
| 62 Assert.AreEqual("somename", option.Name); |
| 63 Assert.AreEqual("ABCDEF", option.StringValue); |
| 64 Assert.Throws(typeof(InvalidOperationException), () => { var s = opt
ion.IntValue; }); |
| 65 } |
| 66 |
| 67 [Test] |
| 68 public void ConstructorPreconditions() |
| 69 { |
| 70 Assert.Throws(typeof(ArgumentNullException), () => { new ChannelOpti
on(null, "abc"); }); |
| 71 Assert.Throws(typeof(ArgumentNullException), () => { new ChannelOpti
on(null, 1); }); |
| 72 Assert.Throws(typeof(ArgumentNullException), () => { new ChannelOpti
on("abc", null); }); |
| 73 } |
| 74 |
| 75 [Test] |
| 76 public void CreateChannelArgsNull() |
| 77 { |
| 78 var channelArgs = ChannelOptions.CreateChannelArgs(null); |
| 79 Assert.IsTrue(channelArgs.IsInvalid); |
| 80 } |
| 81 |
| 82 [Test] |
| 83 public void CreateChannelArgsEmpty() |
| 84 { |
| 85 var options = new List<ChannelOption>(); |
| 86 var channelArgs = ChannelOptions.CreateChannelArgs(options); |
| 87 channelArgs.Dispose(); |
| 88 } |
| 89 |
| 90 [Test] |
| 91 public void CreateChannelArgs() |
| 92 { |
| 93 var options = new List<ChannelOption> |
| 94 { |
| 95 new ChannelOption("ABC", "XYZ"), |
| 96 new ChannelOption("somename", "IJKLM"), |
| 97 new ChannelOption("intoption", 12345), |
| 98 new ChannelOption("GHIJK", 12345), |
| 99 }; |
| 100 |
| 101 var channelArgs = ChannelOptions.CreateChannelArgs(options); |
| 102 channelArgs.Dispose(); |
| 103 } |
| 104 } |
| 105 } |
OLD | NEW |