public void Should_be_able_to_call_ConvertToChar()
 {
     const char expected = 'a';
     object value = new DynamicDictionaryValue(expected);
     var actual = Convert.ToChar(value);
     Assert.Equal(expected, actual);
 }
 public void Should_be_able_to_call_ConvertToBoolean()
 {
     const bool expected = true;
     object value = new DynamicDictionaryValue(expected);
     var actual = Convert.ToBoolean(value);
     Assert.Equal(expected, actual);
 }
 public void Should_be_able_to_call_ConvertToInt16()
 {
     const short expected = 42;
     object value = new DynamicDictionaryValue(expected);
     var actual = Convert.ToInt16(value);
     Assert.Equal(expected, actual);
 }
 public void Should_be_able_to_call_ConvertChangeType()
 {
     const int expected = 42;
     object value = new DynamicDictionaryValue(expected);
     var actual = Convert.ChangeType(value, typeof(int));
     Assert.Equal(expected, actual);
 }
 public void Should_be_able_to_call_ConvertToDateTime()
 {
     DateTime expected = new DateTime(1952, 3, 11);
     object value = new DynamicDictionaryValue(expected);
     var actual = Convert.ToDateTime(value);
     Assert.Equal(expected, actual);
 }
        public void Should_be_able_to_implictly_cast_long_to_other_value_types()
        {
            // Given
            dynamic valueLong = new DynamicDictionaryValue((long)10);

            // Then
            Assert.Equal(10, valueLong);
            Assert.Equal(10.0, valueLong);
            Assert.Equal(10M, valueLong);
        }
        public void Integer_dictionary_values_are_Json_serialized_as_integers()
        {
            dynamic value = 42;
            var input = new DynamicDictionaryValue(value);

            var sut = new Json.JavaScriptSerializer();
            var actual = sut.Serialize(input);

            actual.ShouldEqual(@"42");
        }
        public void Should_return_true_when_hasvalue_is_checked_when_value_is_null()
        {
            // Given
            var value = new DynamicDictionaryValue(string.Empty);

            // When
            var result = value.HasValue;

            // Then
            result.ShouldBeTrue();
        }
        public void Should_return_true_when_value_is_null_and_compared_with_null_using_equality_operator()
        {
            // Given
            var value = new DynamicDictionaryValue(null);

            // When
            var result = (value == null);

            // Then
            result.ShouldBeTrue();
        }
        public void Should_return_false_when_value_is_not_null_and_compared_with_non_equal_value_using_equality_operator()
        {
            // Given
            var value = new DynamicDictionaryValue(10);

            // When
            var result = (value == 11);

            // Then
            result.ShouldBeFalse();
        }
        public void Should_return_false_when_hasvalue_is_checked_when_value_is_not_null()
        {
            // Given
            var value = new DynamicDictionaryValue(null);

            // When
            var result = value.HasValue;

            // Then
            result.ShouldBeFalse();
        }
示例#12
0
        public void Should_return_default_value_of_long_when_calling_default_given_null()
        {
            //Given
            const long expected = 1000333000222000333L;
            dynamic    value    = new DynamicDictionaryValue(null);

            //When
            long actual = value.Default(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#13
0
        public void Should_return_default_when_given_string_that_is_not_a_number()
        {
            //Given
            const int expected = 100;
            dynamic   value    = new DynamicDictionaryValue("4abc2");

            //When
            int actual = value.TryParse <int>(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#14
0
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_double()
        {
            //Given
            const double expected = 37.48d;
            dynamic      value    = new DynamicDictionaryValue("37.48");

            //When
            double actual = value.TryParse <double>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#15
0
        public void Should_still_return_default_double_type_when_no_default_value_given()
        {
            //Given
            const double expected = 0d;
            dynamic      value    = new DynamicDictionaryValue(null);

            //When
            double actual = value.Default <double>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#16
0
        public void Should_still_return_default_bool_type_when_no_default_value_given()
        {
            //Given
            const bool expected = false;
            dynamic    value    = new DynamicDictionaryValue(null);

            //When
            bool actual = value.Default <bool>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#17
0
        public void Should_return_default_value_of_datetime_when_calling_default_given_null()
        {
            //Given
            DateTime expected = DateTime.Parse("10 Dec, 2012");
            dynamic  value    = new DynamicDictionaryValue(null);

            //When
            DateTime actual = value.Default(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#18
0
        public void Should_be_able_to_call_ConvertToBoolean()
        {
            //Given
            const bool expected = true;
            object     value    = new DynamicDictionaryValue(expected);

            //When
            var actual = Convert.ToBoolean(value);

            //Then
            Assert.Equal(expected, actual);
        }
示例#19
0
        public void Should_be_able_to_call_ConvertToDecimal()
        {
            //Given
            const decimal expected = 42;
            object        value    = new DynamicDictionaryValue(expected);

            //When
            var actual = Convert.ToDecimal(value);

            //Then
            Assert.Equal(expected, actual);
        }
示例#20
0
        public void Should_return_false_when_value_is_0_and_implicitly_cast_to_bool()
        {
            // Given, When
            dynamic valueInt   = new DynamicDictionaryValue(0);
            dynamic valueFloat = new DynamicDictionaryValue(0.0);
            dynamic valueDec   = new DynamicDictionaryValue(0.0M);

            // Then
            Assert.False(valueInt);
            Assert.False(valueFloat);
            Assert.False(valueDec);
        }
示例#21
0
        public void Should_return_true_when_value_is_non_zero_and_implicitly_cast_to_bool()
        {
            // Given, When
            dynamic valueInt   = new DynamicDictionaryValue(8);
            dynamic valueFloat = new DynamicDictionaryValue(0.1);
            dynamic valueDec   = new DynamicDictionaryValue(0.1M);

            // Then
            Assert.True(valueInt);
            Assert.True(valueFloat);
            Assert.True(valueDec);
        }
示例#22
0
        public void Should_return_default_value_if_implicit_convert_fails_on_datetime()
        {
            //Given
            DateTime expected = DateTime.Parse("13 December 2012");
            dynamic  value    = new DynamicDictionaryValue("Rawrrrr");

            //When
            DateTime actual = value.TryParse(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#23
0
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_datetime()
        {
            //Given
            DateTime expected = DateTime.Parse("13 Dec, 2012");
            dynamic  value    = new DynamicDictionaryValue("13 December 2012");

            //When
            DateTime actual = value.TryParse <DateTime>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#24
0
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_short()
        {
            //Given
            const short expected = (short)13;
            dynamic     value    = new DynamicDictionaryValue("13");

            //When
            short actual = value.TryParse <short>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#25
0
        public void Should_return_default_value_of_bool_when_calling_default_given_null()
        {
            //Given
            const bool expected = true;
            dynamic    value    = new DynamicDictionaryValue(null);

            //When
            bool actual = value.Default(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#26
0
        public void Should_be_able_to_call_ConvertToDateTime()
        {
            //Given
            DateTime expected = new DateTime(1952, 3, 11);
            object   value    = new DynamicDictionaryValue(expected);

            //When
            var actual = Convert.ToDateTime(value);

            //Then
            Assert.Equal(expected, actual);
        }
示例#27
0
        public void Should_still_return_default_int_datetime_when_no_default_value_given()
        {
            //Given
            DateTime expected = DateTime.MinValue;
            dynamic  value    = new DynamicDictionaryValue(null);

            //When
            DateTime actual = value.Default <DateTime>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_be_able_to_call_ConvertToByte()
        {
            //Given
            const byte expected = 42;
            object value = new DynamicDictionaryValue(expected);

            //When
            var actual = Convert.ToByte(value);

            //Then
            Assert.Equal(expected, actual);
        }
示例#29
0
        public void Should_still_return_default_long_type_when_no_default_value_given()
        {
            //Given
            const long expected = 0L;
            dynamic    value    = new DynamicDictionaryValue(null);

            //When
            long actual = value.Default <long>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#30
0
        public void Should_still_return_default_short_type_when_no_default_value_given()
        {
            //Given
            const short expected = (short)0;
            dynamic     value    = new DynamicDictionaryValue(null);

            //When
            short actual = value.Default <short>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#31
0
        public void Should_still_return_default_float_type_when_no_default_value_given()
        {
            //Given
            const float expected = 0f;
            dynamic     value    = new DynamicDictionaryValue(null);

            //When
            float actual = value.Default <float>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#32
0
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_decimal()
        {
            //Given
            const decimal expected = 55.23m;
            dynamic       value    = new DynamicDictionaryValue("55.23");

            //When
            decimal actual = value.TryParse <decimal>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_return_false_when_value_is_0_and_implicitly_cast_to_bool()
        {
            // Given, When
            dynamic valueInt = new DynamicDictionaryValue(0);
            dynamic valueFloat = new DynamicDictionaryValue(0.0);
            dynamic valueDec = new DynamicDictionaryValue(0.0M);

            // Then
            Assert.False(valueInt);
            Assert.False(valueFloat);
            Assert.False(valueDec);
        }
示例#34
0
        public void Should_be_able_to_call_ConvertChangeType()
        {
            //Given
            const int expected = 42;
            object    value    = new DynamicDictionaryValue(expected);

            //When
            var actual = Convert.ChangeType(value, typeof(int));

            //Then
            Assert.Equal(expected, actual);
        }
示例#35
0
        public void Should_return_default_value_of_string_when_calling_default_given_null()
        {
            //Given
            const string expected = "default value";
            dynamic      value    = new DynamicDictionaryValue(null);

            //When
            string actual = value.Default(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#36
0
        public void Should_return_default_value_of_double_when_calling_default_given_null()
        {
            //Given
            const double expected = 44.23d;
            dynamic      value    = new DynamicDictionaryValue(null);

            //When
            double actual = value.Default(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#37
0
        public void String_dictionary_values_are_Json_serialized_as_strings()
        {
            //Given
            dynamic value = "42";
            var input = new DynamicDictionaryValue(value);

            //When
            var actual = SimpleJson.SerializeObject(input, new NancySerializationStrategy());

            //Then
            actual.ShouldEqual(@"""42""");
        }
示例#38
0
        public void Should_return_default_value_of_float_when_calling_default_given_null()
        {
            //Given
            const float expected = 9.343f;
            dynamic     value    = new DynamicDictionaryValue(null);

            //When
            float actual = value.Default(expected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#39
0
        public void Should_be_able_to_call_ConvertToString()
        {
            //Given
            const string expected = "Forty two";
            object       value    = new DynamicDictionaryValue(expected);

            //When
            var actual = Convert.ToString(value);

            //Then
            Assert.Equal(expected, actual);
        }
示例#40
0
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_int()
        {
            //Given
            const int expected = 42;
            dynamic   value    = new DynamicDictionaryValue("42");

            //When
            int actual = value.TryParse <int>();

            //Then
            Assert.Equal(expected, actual);
        }
示例#41
0
        public void Should_be_able_to_cast_to_arbitrary_object()
        {
            //Given
            dynamic value = new DynamicDictionaryValue(new EventArgs());

            //When
            //Then
            Assert.DoesNotThrow(() =>
            {
                EventArgs e = (EventArgs)value;
            });
        }
        public void Should_implicitly_convert_from_datetime_based_on_given_parameter_type_of_nullable_datetime()
        {
            //Given
            DateTime expected    = DateTime.Parse("13 December 2012");
            DateTime?notExpected = expected.AddDays(10);
            dynamic  value       = new DynamicDictionaryValue(expected);

            //When
            DateTime actual = (DateTime)value.TryParse <DateTime?> (notExpected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#43
0
        public void Should_implicitly_convert_from_double_based_on_given_type_of_string()
        {
            //Given
            const string expected    = "134.22";
            const string notExpected = "187.34";
            dynamic      value       = new DynamicDictionaryValue(134.22d);

            //When
            string actual = value.TryParse(notExpected);

            //Then
            Assert.Equal(expected, actual);
        }
示例#44
0
        public void Should_implicitly_convert_from_decimal_based_on_given_type_of_string()
        {
            //Given
            const string expected    = "88.53234423";
            const string notExpected = "76.3422";
            dynamic      value       = new DynamicDictionaryValue(88.53234423m);

            //When
            string actual = value.TryParse(notExpected);

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_datetime_based_on_given_type_of_string()
        {
            //This test is unrealistic in my opinion, but it should still call ToString on the datetime value

            //Given
            string expected = DateTime.Parse("22 Nov, 2012").ToString(CultureInfo.InvariantCulture);
            string notExpected = DateTime.Parse("18 Jun, 2011").ToString(CultureInfo.InvariantCulture);
            dynamic value = new DynamicDictionaryValue(DateTime.Parse("22 Nov, 2012"));

            //When
            string actual = value.TryParse(notExpected);

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_decimal_based_on_given_type_of_string()
        {
            //Given
            const string expected = "88.53234423";
            const string notExpected = "76.3422";
            dynamic value = new DynamicDictionaryValue(88.53234423m);

            //When
            string actual = value.TryParse(notExpected);

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_double_based_on_given_type_of_string()
        {
            //Given
            const string expected = "134.22";
            const string notExpected = "187.34";
            dynamic value = new DynamicDictionaryValue(134.22d);

            //When
            string actual = value.TryParse(notExpected);

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_return_default_value_if_implicit_convert_fails_on_datetime()
        {
            //Given
            DateTime expected = DateTime.Parse("13 December 2012");
            dynamic value = new DynamicDictionaryValue("Rawrrrr");

            //When
            DateTime actual = value.TryParse(expected);

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_datetime()
        {
            //Given
            DateTime expected = DateTime.Parse("13 Dec, 2012");
            dynamic value = new DynamicDictionaryValue("13 December 2012");

            //When
            DateTime actual = value.TryParse<DateTime>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_still_return_default_bool_type_when_no_default_value_given()
        {
            //Given
            const bool expected = false;
            dynamic value = new DynamicDictionaryValue(null);

            //When
            bool actual = value.Default<bool>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_decimal()
        {
            //Given
            const decimal expected = 55.23m;
            dynamic value = new DynamicDictionaryValue("55.23");

            //When
            decimal actual = value.TryParse<decimal>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_return_default_when_given_string_that_is_not_a_number()
        {
            //Given
            const int expected = 100;
            dynamic value = new DynamicDictionaryValue("4abc2");

            //When
            int actual = value.TryParse<int>(expected);

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_int()
        {
            //Given
            const int expected = 42;
            dynamic value = new DynamicDictionaryValue("42");

            //When
            int actual = value.TryParse<int>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_throw_if_unable_to_explicitly_cast()
        {
            //Given
            dynamic value = new DynamicDictionaryValue(12.25);

            //When
            Exception exception = Assert.Throws<InvalidCastException>(() => value.Default<int>());

            //Then
            Assert.Equal("Cannot convert value of type 'Double' to type 'Int32'", exception.Message);
        }
        public void Should_still_return_default_int_datetime_when_no_default_value_given()
        {
            //Given
            DateTime expected = DateTime.MinValue;
            dynamic value = new DynamicDictionaryValue(null);

            //When
            DateTime actual = value.Default<DateTime>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_be_able_to_cast_to_arbitrary_object()
        {
            //Given
            dynamic value = new DynamicDictionaryValue(new EventArgs());

            //When
            //Then
            Assert.DoesNotThrow(() =>
            {
                EventArgs e = (EventArgs)value;
            });
        }
        public void Should_return_false_when_converting_enums_of_different_types()
        {
            // Given
            var binder = A.Fake<ConvertBinder>(o => o.WithArgumentsForConstructor(new object[] { typeof(IntEnum), false }));
            var value = new DynamicDictionaryValue(ByteEnum.Value1);

            // When
            object valueResult;
            var result = value.TryConvert(binder, out valueResult);

            // Then
            result.ShouldBeFalse();
            valueResult.ShouldBeNull();
        }
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_double()
        {
            //Given
            const double expected = 37.48d;
            dynamic value = new DynamicDictionaryValue("37.48");

            //When
            double actual = value.TryParse<double>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_implicitly_convert_from_string_based_on_given_generic_type_of_short()
        {
            //Given
            const short expected = (short)13;
            dynamic value = new DynamicDictionaryValue("13");

            //When
            short actual = value.TryParse<short>();

            //Then
            Assert.Equal(expected, actual);
        }
        public void Should_still_return_default_long_type_when_no_default_value_given()
        {
            //Given
            const long expected = 0L;
            dynamic value = new DynamicDictionaryValue(null);

            //When
            long actual = value.Default<long>();

            //Then
            Assert.Equal(expected, actual);
        }