Exemplo n.º 1
0
        private void assertBooleanParsing(SifFormatter formatter, String stringValue, Boolean value)
        {
            Console.WriteLine("Testing Boolean parse of '" + stringValue + "' using " + formatter.ToString());
            Boolean?testValue = formatter.ToBool(stringValue);

            Assertion.AssertEquals("Boolean Value", value, testValue);
            Assertion.AssertEquals("String Value", stringValue, formatter.ToString(value));

            testValue = formatter.ToBool(null);
            Assertion.AssertNull("Boolean value should be null", testValue);
        }
Exemplo n.º 2
0
        private void assertThrowsFormatException(SifFormatter formatter)
        {
            bool threwProperException = false;

            // Boolean
            try
            {
                formatter.ToBool("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("NumberFormatException was not thrown for toBoolean()", threwProperException);

            // DECIMAL
            threwProperException = false;
            try
            {
                formatter.ToDecimal("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for toDecimal()", threwProperException);

            // DATE
            threwProperException = false;
            try
            {
                formatter.ToDate("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for ToDate()", threwProperException);


            //
            // DateTime and Duration are not supported by the SIF1xFormatter
            //
            if (!(formatter is Sif1xFormatter))
            {
                // DATETIME
                threwProperException = false;
                try
                {
                    formatter.ToDateTime("asdf");
                }
                catch (FormatException)
                {
                    threwProperException = true;
                }
                Assertion.Assert("IllegalArgumentException was not thrown for ToDateTime()", threwProperException);

                // DURATION
                threwProperException = false;
                try
                {
                    formatter.ToTimeSpan("asdf");
                }
                catch (FormatException)
                {
                    threwProperException = true;
                }

                Assertion.Assert("IllegalArgumentException was not thrown for toDuration()", threwProperException);
            }
            // INT
            threwProperException = false;
            try
            {
                formatter.ToInt("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for toint()", threwProperException);

            // TIME
            threwProperException = false;
            try
            {
                formatter.ToTime("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for toTime()", threwProperException);
        }