Exemplo n.º 1
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);
        }