Example #1
0
        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);
        }
Example #2
0
        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();
        }
Example #3
0
        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();
        }
Example #4
0
        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();
        }