public void WhenInvalidIntPassed_ShouldReturnZero(string invalidInt)
        {
            //Arange

            //Act
            int result = _apiTypeConverter.ToInt(invalidInt);

            //Assert
            Assert.AreEqual(0, result);
        }
Пример #2
0
        private object To(string value, Type type)
        {
            if (type == typeof(DateTime?))
            {
                return(_apiTypeConverter.ToUtcDateTimeNullable(value));
            }
            else if (type == typeof(int?))
            {
                return(_apiTypeConverter.ToIntNullable(value));
            }
            else if (type == typeof(int))
            {
                return(_apiTypeConverter.ToInt(value));
            }
            else if (type == typeof(List <int>))
            {
                return(_apiTypeConverter.ToListOfInts(value));
            }
            else if (type == typeof(List <string>))
            {
                return(_apiTypeConverter.ToListOfStrings(value));
            }
            else if (type == typeof(bool?))
            {
                // Because currently status is the only boolean and we need to accept published and unpublished statuses.
                return(_apiTypeConverter.ToStatus(value));
            }
            else if (IsNullableEnum(type))
            {
                return(_apiTypeConverter.ToEnumNullable(value, type));
            }

            // It should be the last resort, because it is not exception safe.
            return(Convert.ChangeType(value, type));
        }
Пример #3
0
        private object To(string value, Type type)
        {
            if (type == typeof(DateTime?))
            {
                return(_apiTypeConverter.ToUtcDateTimeNullable(value));
            }
            if (type == typeof(int?))
            {
                return(_apiTypeConverter.ToIntNullable(value));
            }
            if (type == typeof(int))
            {
                return(_apiTypeConverter.ToInt(value));
            }
            if (type == typeof(List <int>))
            {
                return(_apiTypeConverter.ToListOfInts(value));
            }
            if (type == typeof(List <string>))
            {
                return(_apiTypeConverter.ToListOfStrings(value));
            }
            if (IsNullableEnum(type))
            {
                return(_apiTypeConverter.ToEnumNullable(value, type));
            }

            // It should be the last resort, because it is not exception safe.
            return(Convert.ChangeType(value, type));
        }
Пример #4
0
        public void Invalid_int_should_return_zero(string invalidInt)
        {
            int result = _apiTypeConverter.ToInt(invalidInt);

            result.ShouldEqual(0);
        }