public void NullableDouble_InvalidJsonValue_Throws(double?input)
        {
            var dto = new TestDto <double?> {
                Value = input
            };

            Assert.That(() => dto.ToJson(), Throws.InstanceOf <ArgumentException>()
                        .With.Property("ParamName").Contains("value"));
        }
        public void NullableDouble_RoundTrip_ReturnsExpectedValue(double?input, string ignore, double?expected)
        {
            var dto = new TestDto <double?> {
                Value = input
            };
            var serialized   = dto.ToJson();
            var deserialized = serialized.FromJson <TestDto <double?> >();
            var actual       = deserialized.Value;

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void NullableDouble_SerializesToExpectedText(double?input, string valueString)
        {
            var dto = new TestDto <double?> {
                Value = input
            };
            var actual = dto.ToJson();

            var expected = GetJsonForDtoWithValue(valueString);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Double_RoundTrip_ReturnsSameValue(double input, string ignore)
        {
            var dto = new TestDto <double> {
                Value = input
            };
            var serialized   = dto.ToJson();
            var deserialized = serialized.FromJson <TestDto <double> >();
            var actual       = deserialized.Value;

            Assert.That(actual, Is.EqualTo(input));
        }
        public void NodaTimeNullableDuration_UsingJsConfigThatOverridesDefaultIncludeNullValues_RoundTripsDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                var dto = new TestDto <Duration?> {
                    Value = default(Duration?)
                };
                var serialized   = dto.ToJson();
                var deserialized = serialized.FromJson <TestDto <Duration?> >();
                var actual       = deserialized.Value;

                Assert.That(actual, Is.Null);
            }
        }
        public void NodaTimeNullableDuration_UsingJsConfigThatOverridesDefaultIncludeNullValues_DoesNotSerializeDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                const string expected = "{}";

                var dto = new TestDto <Duration?> {
                    Value = default(Duration?)
                };
                var actual = dto.ToJson();

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void NodaTimeOffset_UsingJsConfigThatOverridesDefaultIncludeNullValues_RoundTripsDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                var expected = default(Offset);
                var dto      = new TestDto <Offset> {
                    Value = default(Offset)
                };
                var serialized   = dto.ToJson();
                var deserialized = serialized.FromJson <TestDto <Offset> >();
                var actual       = deserialized.Value;

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void NodaTimeOffset_UsingJsConfigThatOverridesDefaultIncludeNullValues_SerializesDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                var defaultValue = default(Offset);
                var expected     = GetJsonForDtoWithValue("\"PT0S\"");

                var dto = new TestDto <Offset> {
                    Value = defaultValue
                };
                var actual = dto.ToJson();

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void NodaTimeInterval_UsingJsConfigThatOverridesDefaultIncludeNullValues_SerializesDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                var defaultValue = default(Interval);
                var expected     = GetJsonForDtoWithValue("{\"Start\":\"1970-01-01T00:00:00Z\",\"End\":\"1970-01-01T00:00:00Z\"}");

                var dto = new TestDto <Interval> {
                    Value = defaultValue
                };
                var actual = dto.ToJson();

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void NodaTimeNullableInstant_UsingJsConfigThatOverridesDefaultIncludeNullValues_SerializesValueTypeDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                var defaultValue = default(Instant);
                var expected     = GetJsonForDtoWithValue("\"1970-01-01T00:00:00Z\"");

                var dto = new TestDto <Instant?> {
                    Value = defaultValue
                };
                var actual = dto.ToJson();

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void DateTime_UsingJsConfigThatOverridesDefaultIncludeNullValues_SerializesDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                var defaultValue = default(DateTime);
                var expected     = GetJsonForDtoWithValue("\"0001-01-01T00:00:00Z\"");

                var dto = new TestDto <DateTime> {
                    Value = defaultValue
                };
                var actual = dto.ToJson();

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void NullableDouble_UsingJsConfigThatOverridesDefaultIncludeNullValues_RoundTripsValueTypeDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                const double expected = default(double);
                var          dto      = new TestDto <double?> {
                    Value = default(double)
                };
                var serialized   = dto.ToJson();
                var deserialized = serialized.FromJson <TestDto <double?> >();
                var actual       = deserialized.Value;

                Assert.That(actual, Is.EqualTo(expected));
            }
        }
        public void NullableDouble_UsingJsConfigThatOverridesDefaultIncludeNullValues_SerializesValueTypeDefaultValue()
        {
            using (CreateJsConfigThatOverridesDefaultIncludeNullValuesSetting())
            {
                const double defaultValue = default(double);
                var          expected     = GetJsonForDtoWithValue(defaultValue.ToString(CultureInfo.InvariantCulture));

                var dto = new TestDto <double?> {
                    Value = defaultValue
                };
                var actual = dto.ToJson();

                Assert.That(actual, Is.EqualTo(expected));
            }
        }