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); }); }
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)); }
public void SetValueThrowsTest(string key, string value) { ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock(); Assert.Throws <FormatException>(() => { target.SetValue(key, value, allowCustomParameters: false); }); }
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 ?? ""); }
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()); } }
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); }); }