Esempio n. 1
0
 public void coerces_integer_to_null()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue(0).ShouldBe(null);
     });
 }
Esempio n. 2
0
 public void coerces_long_to_timespan()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue(12345678L).ShouldBe(new TimeSpan(0, 3, 25, 45, 678));
     });
 }
Esempio n. 3
0
 public void coerces_invalid_string_to_exception()
 {
     CultureTestHelper.UseCultures(() =>
     {
         Should.Throw <FormatException>(() => _type.ParseValue("some unknown date"));
     });
 }
Esempio n. 4
0
 public void coerces_invalidly_formatted_date_to_exception()
 {
     CultureTestHelper.UseCultures(() =>
     {
         Should.Throw <FormatException>(() => _type.ParseValue("Dec 32 2012"));
     });
 }
Esempio n. 5
0
        public void can_use_DateTimeOffset_type()
        {
            CultureTestHelper.UseCultures(() =>
            {
                var schema = Schema.For(@"
                input DateTimeOffsetInput{
                    value: Date
                }
                type Query {
                  five(model: DateTimeOffsetInput): Date
                }
                ", _ =>
                {
                    _.Types.Include <ParametersType>();
                });

                var utcNow        = DateTimeOffset.UtcNow;
                var value         = utcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFF'Z'", DateTimeFormatInfo.InvariantInfo);
                var expectedValue = utcNow.AddDays(1).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFF'Z'", DateTimeFormatInfo.InvariantInfo);

                var result = schema.Execute(_ =>
                {
                    _.Query = $"{{ five(model:{{ value:\"{value}\"}}) }}";
                });

                var expectedResult           = CreateQueryResult($"{{ 'five': \"{expectedValue}\" }}");
                var serializedExpectedResult = Writer.Write(expectedResult);

                result.ShouldBe(serializedExpectedResult);
            });
        }
Esempio n. 6
0
 public void coerces_long_to_timespan()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue(123456789L).ShouldBe(new TimeSpan(1428, 21, 33, 9));
     });
 }
Esempio n. 7
0
 public void coerces_iso8601_string_with_tzone_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         Should.Throw <FormatException>(() => _type.ParseValue("2015-11-21T19:59:32.987+0200"));
     });
 }
Esempio n. 8
0
 public void coerces_iso8601_string_with_tzone_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue("2015-11-21T19:59:32.987+0200").ShouldBe(
             new DateTime(2015, 11, 21, 17, 59, 32) + TimeSpan.FromMilliseconds(987));
     });
 }
Esempio n. 9
0
 public void serialize_string_returns_null()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var actual = _type.Serialize("foo");
         actual.ShouldBeNull();
     });
 }
 public void coerces_iso8601_formatted_string_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue("2015-12-01").ShouldBe(
             new DateTime(2015, 12, 01, 0, 0, 0));
     });
 }
 public void coerces_iso8601_string_with_tzone_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue("2015-11-21T19:59:32.987+0200").ShouldBe(
             new DateTimeOffset(2015, 11, 21, 19, 59, 32, 987, TimeSpan.FromHours(2)));
     });
 }
 public void coerces_iso8601_utc_formatted_string_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue("2015-12-01T14:15:07.123Z").ShouldBe(
             new DateTimeOffset(2015, 12, 01, 14, 15, 7, 123, TimeSpan.Zero));
     });
 }
 public void coerces_datetimes_to_utc()
 {
     CultureTestHelper.UseCultures(() =>
     {
         ((DateTime)_type.ParseValue("2015-11-21")).Kind.ShouldBe(
             DateTimeKind.Utc);
     });
 }
Esempio n. 14
0
 public void coerces_iso8601_formatted_string_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         _type.ParseValue("2015-12-01T14:15:07.123Z").ShouldBe(
             new DateTime(2015, 12, 01, 14, 15, 7) + TimeSpan.FromMilliseconds(123));
     });
 }
Esempio n. 15
0
 public void serialize_string_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var actual = _type.Serialize("2018-07-24");
         actual.ShouldBe("2018-07-24");
     });
 }
 public void serialize_utc_date_time_throws()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var date = new DateTime(2000, 1, 2, 3, 4, 5, 6, DateTimeKind.Utc);
         Should.Throw <FormatException>(() => _type.Serialize(date));
     });
 }
 public void serialize_timespan_returns_total_seconds_as_long()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var expected = (long)new TimeSpan(1, 2, 3, 4, 5).TotalMilliseconds;
         var actual   = _type.Serialize(new TimeSpan(1, 2, 3, 4, 5));
         actual.ShouldBe(expected);
     });
 }
 public void serialize_int()
 {
     CultureTestHelper.UseCultures(() =>
     {
         int input  = 1;
         var actual = _type.Serialize(input);
         actual.ShouldBe(input);
     });
 }
 public void o_format_throws()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var expected = DateTime.UtcNow;
         var input    = expected.ToLocalTime().ToString("O", DateTimeFormatInfo.InvariantInfo);
         Should.Throw <FormatException>(() => _type.ParseValue(input));
     });
 }
 public void coerces_iso8601_string_with_tzone_to_date()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var dateTimeOffset = (DateTimeOffset)_type.ParseValue("2015-11-21T19:59:32.987+0200");
         dateTimeOffset.Date.ShouldBe(new DateTime(2015, 11, 21));
         dateTimeOffset.TimeOfDay.ShouldBe(new TimeSpan(0, 19, 59, 32, 987));
         dateTimeOffset.Offset.ShouldBe(TimeSpan.FromHours(2));
     });
 }
Esempio n. 21
0
        public void serialize_utc_date_returns_date_only()
        {
            CultureTestHelper.UseCultures(() =>
            {
                var date = new DateTime(2000, 1, 2, 3, 4, 5, 6, DateTimeKind.Utc);

                var actual = _type.Serialize(date);

                actual.ShouldBe("2000-01-02");
            });
        }
Esempio n. 22
0
 public void Should_Print_Default_Values_Of_Arguments()
 {
     CultureTestHelper.UseCultures(() =>
     {
         var printer = new SchemaPrinter(new Bug2194Schema(), new SchemaPrinterOptions {
             IncludeDeprecationReasons = false, IncludeDescriptions = false
         });
         var printed = printer.Print();
         printed.ShouldBe("Bug2194".ReadSDL());
     });
 }
        public void parsevalue_to_timespan(object value)
        {
            CultureTestHelper.UseCultures(() =>
            {
                var expected = TimeSpan.FromMilliseconds(Convert.ToDouble(value));

                var actual = _type.ParseValue(value);

                actual.ShouldBe(expected);
            });
        }
        public void coerces_TimeSpan_to_timespan()
        {
            CultureTestHelper.UseCultures(() =>
            {
                var expected = new TimeSpan(1, 2, 3, 4, 5);

                var actual = _type.ParseValue(expected);

                actual.ShouldBe(expected);
            });
        }
        public void coerces_valid_date()
        {
            CultureTestHelper.UseCultures(() =>
            {
                var expected = DateTimeOffset.UtcNow;
                var input    = expected.ToString("O", DateTimeFormatInfo.InvariantInfo);

                var actual = _type.ParseValue(input);

                actual.ShouldBe(expected);
            });
        }
        public void coerces_int_to_timespan()
        {
            CultureTestHelper.UseCultures(() =>
            {
                var expected = new TimeSpan(1, 2, 3, 4);
                var input    = (int)new TimeSpan(1, 2, 3, 4).TotalMilliseconds;

                var actual = _type.ParseValue(input);

                actual.ShouldBe(expected);
            });
        }
Esempio n. 27
0
 public void prints_float_value_using_cultures()
 {
     CultureTestHelper.UseCultures(prints_float_value);
 }
 public void float_into_string_using_cultures()
 {
     CultureTestHelper.UseCultures(float_into_string);
 }
 public void serialize_string_throws()
 {
     CultureTestHelper.UseCultures(() => Should.Throw <InvalidOperationException>(() => _type.Serialize("foo")));
 }
 public void float_into_enum_with_cultures()
 {
     CultureTestHelper.UseCultures(float_into_enum);
 }