Exemplo n.º 1
0
        public void CopyFromSimpleTest()
        {
            CopyFromAllParametersCoveredTest();

            ModifiableBobConnectionParametersMock source = new ModifiableBobConnectionParametersMock()
            {
                Host     = "host",
                Port     = 123,
                User     = "******",
                Password = "******",
                MaxReceiveMessageSize = 100,
                MaxSendMessageSize    = -100,
                ConnectionTimeout     = TimeSpan.MaxValue,
                OperationTimeout      = TimeSpan.FromSeconds(10)
            }.WithCustomParam("Custom1", "111");

            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock()
            {
                Host     = "qwerty",
                Port     = null,
                User     = "******",
                Password = null,
                MaxReceiveMessageSize = null,
                MaxSendMessageSize    = null,
                ConnectionTimeout     = TimeSpan.FromHours(1),
                OperationTimeout      = TimeSpan.FromHours(1)
            }.WithCustomParam("ToBeCleared", "111");

            Assert.NotEqual(source, target);

            target.CopyFrom(source);
            Assert.Equal(source, target);
        }
Exemplo n.º 2
0
        public void SetValueToCustomParamsTest()
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();

            target.SetValue("Abba", "Abba", allowCustomParameters: true);
            Assert.Single(target.CustomParameters);
            Assert.True(target.CustomParameters.ContainsKey("Abba"));
            Assert.Equal("Abba", target.CustomParameters["Abba"]);

            target.SetValue("AbbA", "Bob", allowCustomParameters: true);
            Assert.Single(target.CustomParameters);
            Assert.True(target.CustomParameters.ContainsKey("abba"));
            Assert.Equal("Bob", target.CustomParameters["Abba"]);

            target.SetValue("Mamba", "Bob", allowCustomParameters: true);
            Assert.Equal(2, target.CustomParameters.Count);
            Assert.True(target.CustomParameters.ContainsKey("Mamba"));
            Assert.Equal("Bob", target.CustomParameters["mamba"]);


            Assert.Throws <ArgumentException>(() =>
            {
                target.SetValue("Vombat", "111", allowCustomParameters: false);
            });
        }
Exemplo n.º 3
0
        public void SetValueCornerCaseTest()
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();

            target.SetValue("Host", null, false);
            Assert.Null(target.GetValue("Host", false));

            target.SetValue("Host", "", false);
            Assert.Equal("", target.GetValue("Host", false));

            target.SetValue("Host", "  ", false);
            Assert.Equal("  ", target.GetValue("Host", false));


            target.SetValue("User", null, false);
            Assert.Null(target.GetValue("User", false));

            target.SetValue("User", "", false);
            Assert.Equal("", target.GetValue("User", false));

            target.SetValue("User", "  ", false);
            Assert.Equal("  ", target.GetValue("User", false));


            target.SetValue("Password", null, false);
            Assert.Null(target.GetValue("Password", false));

            target.SetValue("Password", "", false);
            Assert.Equal("", target.GetValue("Password", false));

            target.SetValue("Password", "  ", false);
            Assert.Equal("  ", target.GetValue("Password", false));
        }
Exemplo n.º 4
0
 public void ParseConnectionStringIntoFormatExceptionTest(string connectionString)
 {
     Assert.Throws <FormatException>(() =>
     {
         ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();
         BobConnectionStringParser.ParseConnectionStringInto(connectionString, target);
     });
 }
Exemplo n.º 5
0
        public void ParseConnectionStringIntoTest(string connectionString, ModifiableBobConnectionParametersMock expected)
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();

            BobConnectionStringParser.ParseConnectionStringInto(connectionString, target);

            Assert.Equal(expected, target);
        }
Exemplo n.º 6
0
        public void SetValueThrowsTest(string key, string value)
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();

            Assert.Throws <FormatException>(() =>
            {
                target.SetValue(key, value, allowCustomParameters: false);
            });
        }
Exemplo n.º 7
0
        public void CopyFromTheoryTest(string connectionString, ModifiableBobConnectionParametersMock data)
        {
            Assert.NotNull(connectionString);

            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();

            target.CopyFrom(data);

            Assert.Equal(data, target);
        }
Exemplo n.º 8
0
        public void ParseToStringRoundtripTest(string connectionString, ModifiableBobConnectionParametersMock data)
        {
            Assert.NotNull(connectionString);

            var stringRep = data.ToString(includePassword: true);
            var parsed    = new ModifiableBobConnectionParametersMock();

            BobConnectionStringParser.ParseConnectionStringInto(stringRep, parsed);
            Assert.Equal(data, parsed);
        }
Exemplo n.º 9
0
        public void InfiniteTimeoutValidationTest()
        {
            ModifiableBobConnectionParametersMock data = new ModifiableBobConnectionParametersMock()
            {
                Host              = "host",
                OperationTimeout  = Timeout.InfiniteTimeSpan,
                ConnectionTimeout = Timeout.InfiniteTimeSpan
            };

            Assert.True(data.IsValid());
        }
Exemplo n.º 10
0
        public void SetGetValueRoundtripTest(string key, string value, bool allowCustom, string expected = null)
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock()
            {
                Host     = "------",
                User     = "******",
                Password = "******"
            };

            target.SetValue(key, value, allowCustom);
            var result = target.GetValue(key, allowCustom);

            Assert.Equal(expected ?? value, result ?? "");
        }
Exemplo n.º 11
0
        public void GetValueTest()
        {
            ModifiableBobConnectionParametersMock source = new ModifiableBobConnectionParametersMock()
            {
                Host     = "localhost",
                Port     = null,
                User     = "******",
                Password = null,
                MaxReceiveMessageSize = 100500,
                MaxSendMessageSize    = null,
                ConnectionTimeout     = TimeSpan.Parse("12:00:00"),
                OperationTimeout      = null
            }
            .WithCustomParam("Custom1", "Value1");

            Assert.Equal("localhost", source.GetValue("Host", allowCustomParameters: true));
            Assert.Null(source.GetValue("Port", allowCustomParameters: true));
            Assert.Equal("localhost", source.GetValue("Address", allowCustomParameters: true));
            Assert.Equal("localhost", source.GetValue("Server", allowCustomParameters: true));
            Assert.Equal("user", source.GetValue("USER", allowCustomParameters: true));
            Assert.Equal("user", source.GetValue("USER ID", allowCustomParameters: true));
            Assert.Null(source.GetValue("Password", allowCustomParameters: true));
            Assert.Equal("100500", source.GetValue("MaxReceiveMessageSize", allowCustomParameters: true));
            Assert.Equal("100500", source.GetValue("MaxReceiveMessageLength", allowCustomParameters: true));
            Assert.Null(source.GetValue("MaxSendMessageSize", allowCustomParameters: true));
            Assert.Null(source.GetValue("MaxSendMessageLength", allowCustomParameters: true));
            Assert.Equal("12:00:00", source.GetValue("ConnectionTimeout", allowCustomParameters: true));
            Assert.Equal("12:00:00", source.GetValue("Connect Timeout", allowCustomParameters: true));
            Assert.Null(source.GetValue("OperationTimeout", allowCustomParameters: true));

            Assert.Equal("Value1", source.GetValue("Custom1", allowCustomParameters: true));

            Assert.Throws <ArgumentException>(() => source.GetValue("Custom2", allowCustomParameters: true));


            source.Port = 1000;

            Assert.Equal("localhost", source.GetValue("Host", allowCustomParameters: true));
            Assert.Equal("1000", source.GetValue("Port", allowCustomParameters: true));
            Assert.Equal("localhost:1000", source.GetValue("Address", allowCustomParameters: true));
        }
Exemplo n.º 12
0
        public void SetValueTest(string property, string key, string value, string expected = null)
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock()
            {
                Host     = "------",
                User     = "******",
                Password = "******"
            };

            target.SetValue(key, value, allowCustomParameters: false);

            var propVal = target.GetType().GetProperty(property, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(target);

            expected = expected ?? value;

            if (propVal == null)
            {
                Assert.True(string.IsNullOrEmpty(expected));
            }
            else
            {
                Assert.Equal(expected, propVal.ToString());
            }
        }
Exemplo n.º 13
0
        public void ValidationTest(string key, string value)
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock()
            {
                Host = "host"
            };

            Assert.True(target.IsValid());

            target.SetValue(key, value, allowCustomParameters: false);

            Assert.False(target.IsValid());
            Assert.False(target.Validate(ValidationExceptionBehaviour.NoException));

            Assert.Throws <FormatException>(() =>
            {
                target.Validate(ValidationExceptionBehaviour.FormatException);
            });

            Assert.Throws <InvalidBobConnectionParametersException>(() =>
            {
                target.Validate(ValidationExceptionBehaviour.InvalidConnectionParametersException);
            });
        }
Exemplo n.º 14
0
 public void ValidationForCorrectInputTest(string connectionString, ModifiableBobConnectionParametersMock data)
 {
     Assert.NotNull(connectionString);
     Assert.True(data.IsValid());
 }
Exemplo n.º 15
0
 public void ToStringTest(ModifiableBobConnectionParametersMock parameters, string expected)
 {
     Assert.Equal(expected, parameters.ToString(includePassword: true));
 }