private void TbxPort_TextChanged(object sender, TextChangedEventArgs e) { if (ServiceBuilder == null) { return; } ServiceBuilder.ServerPort = serverPortConverter.ConvertBack(tbxPort.Text); ServiceBuilder.ClientPort = clientPortConverter.ConvertBack(tbxPort.Text); }
public void IntConverter_ConvertBack() { IValueConverter converter; object actualValue; Type expectedType; converter = new IntConverter(); expectedType = typeof(int); // // Test with null. // try { converter.ConvertBack(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with incorrect value. // try { converter.ConvertBack("true"); Assert.Fail("Expected FormatException to be thrown."); } catch (FormatException) { } try { converter.ConvertBack("999999999999999"); Assert.Fail("Expected OverflowException to be thrown."); } catch (OverflowException) { } // // Test with 0. // actualValue = converter.ConvertBack("0"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0, actualValue, "Converted value is incorrect."); // // Test with positive value. // actualValue = converter.ConvertBack("1024"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(1024, actualValue, "Converted value is incorrect."); // // Test with negative value. // actualValue = converter.ConvertBack("-1024"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(-1024, actualValue, "Converted value is incorrect."); }
public void IntConverter_ConvertBack() { IValueConverter converter; object actualValue; Type expectedType; converter = new IntConverter(); expectedType = typeof(int); // // Test with null. // try { converter.ConvertBack(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with incorrect value. // try { converter.ConvertBack("true"); Assert.Fail("Expected FormatException to be thrown."); } catch (FormatException) { } try { converter.ConvertBack("999999999999999"); Assert.Fail("Expected OverflowException to be thrown."); } catch (OverflowException) { } // // Test with 0. // actualValue = converter.ConvertBack("0"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0, actualValue, "Converted value is incorrect."); // // Test with positive value. // actualValue = converter.ConvertBack("1024"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(1024, actualValue, "Converted value is incorrect."); // // Test with negative value. // actualValue = converter.ConvertBack("-1024"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(-1024, actualValue, "Converted value is incorrect."); }