Ejemplo n.º 1
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);
            });
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public void SetValueThrowsTest(string key, string value)
        {
            ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock();

            Assert.Throws <FormatException>(() =>
            {
                target.SetValue(key, value, allowCustomParameters: false);
            });
        }
Ejemplo n.º 4
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 ?? "");
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
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);
            });
        }