public void Constructor_ExpectedValues() { // Call var converter = new NoValueRoundedDoubleConverter(); // Assert Assert.IsInstanceOf <RoundedDoubleConverter>(converter); }
public void ConvertTo_NaNToString_ReturnHyphen() { // Setup var converter = new NoValueRoundedDoubleConverter(); // Call var text = (string)converter.ConvertTo(RoundedDouble.NaN, typeof(string)); // Assert Assert.AreEqual("-", text); }
public void CanConvertTo_ToString_ReturnTrue() { // Setup var converter = new NoValueRoundedDoubleConverter(); // Call bool canConvertToString = converter.CanConvertTo(typeof(string)); // Assert Assert.IsTrue(canConvertToString); }
public void ConvertFrom_NoValueText_ReturnNaN(string text) { // Setup var converter = new NoValueRoundedDoubleConverter(); // Call var result = (RoundedDouble)converter.ConvertFrom(text); // Assert Assert.IsNaN(result.Value); Assert.AreEqual(RoundedDouble.MaximumNumberOfDecimalPlaces, result.NumberOfDecimalPlaces); }
public void ConvertTo_NumberToString_ReturnStringInLocalEnglishCulture(double value) { // Setup var roundedDouble = new RoundedDouble(2, value); var converter = new NoValueRoundedDoubleConverter(); // Call var text = (string)converter.ConvertTo(roundedDouble, typeof(string)); // Assert Assert.AreEqual(roundedDouble.ToString(), text); }
private static void DoConvertFrom_SomeNumericalTextInCurrentCulture_ReturnConvertedRoundedDouble(double input) { // Setup var mocks = new MockRepository(); var context = mocks.Stub <ITypeDescriptorContext>(); mocks.ReplayAll(); string text = input.ToString(CultureInfo.CurrentCulture); var converter = new NoValueRoundedDoubleConverter(); // Call var conversionResult = (RoundedDouble)converter.ConvertFrom(context, CultureInfo.CurrentCulture, text); // Assert Assert.AreEqual(RoundedDouble.MaximumNumberOfDecimalPlaces, conversionResult.NumberOfDecimalPlaces); Assert.AreEqual(input, conversionResult.Value); mocks.VerifyAll(); }
public void ConvertFrom_TextDoesNotRepresentNumber_ThrowNotSupportedException() { // Setup var mocks = new MockRepository(); var context = mocks.Stub <ITypeDescriptorContext>(); mocks.ReplayAll(); const string text = "I'm not a number!"; var converter = new NoValueRoundedDoubleConverter(); // Call TestDelegate call = () => converter.ConvertFrom(context, CultureInfo.CurrentCulture, text); // Assert string message = Assert.Throws <NotSupportedException>(call).Message; Assert.AreEqual("De tekst moet een getal zijn.", message); mocks.VerifyAll(); }
public void ConvertFrom_TextTooLongToStoreInDouble_ThrowNotSupportedException() { // Setup var mocks = new MockRepository(); var context = mocks.Stub <ITypeDescriptorContext>(); mocks.ReplayAll(); string text = "1" + double.MaxValue.ToString(CultureInfo.CurrentCulture); var converter = new NoValueRoundedDoubleConverter(); // Call TestDelegate call = () => converter.ConvertFrom(context, CultureInfo.CurrentCulture, text); // Assert string message = Assert.Throws <NotSupportedException>(call).Message; Assert.AreEqual("De tekst is een getal dat te groot of te klein is om gerepresenteerd te worden.", message); mocks.VerifyAll(); }