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); }
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 ParseConnectionStringIntoFormatExceptionTest(string connectionString) { Assert.Throws <FormatException>(() => { ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock(); BobConnectionStringParser.ParseConnectionStringInto(connectionString, target); }); }
public void ParseConnectionStringIntoTest(string connectionString, ModifiableBobConnectionParametersMock expected) { ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock(); BobConnectionStringParser.ParseConnectionStringInto(connectionString, target); Assert.Equal(expected, target); }
public void SetValueThrowsTest(string key, string value) { ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock(); Assert.Throws <FormatException>(() => { target.SetValue(key, value, allowCustomParameters: false); }); }
public void CopyFromTheoryTest(string connectionString, ModifiableBobConnectionParametersMock data) { Assert.NotNull(connectionString); ModifiableBobConnectionParametersMock target = new ModifiableBobConnectionParametersMock(); target.CopyFrom(data); Assert.Equal(data, target); }
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); }
public void InfiniteTimeoutValidationTest() { ModifiableBobConnectionParametersMock data = new ModifiableBobConnectionParametersMock() { Host = "host", OperationTimeout = Timeout.InfiniteTimeSpan, ConnectionTimeout = Timeout.InfiniteTimeSpan }; Assert.True(data.IsValid()); }
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 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)); }
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); }); }
public void ValidationForCorrectInputTest(string connectionString, ModifiableBobConnectionParametersMock data) { Assert.NotNull(connectionString); Assert.True(data.IsValid()); }
public void ToStringTest(ModifiableBobConnectionParametersMock parameters, string expected) { Assert.Equal(expected, parameters.ToString(includePassword: true)); }