Ejemplo n.º 1
0
        public void ser_deser_a_datetimeoffset()
        {
            var obj = new ADateTimeOffset()
            {
                Id = "my_id",
                TheDateTimeOffset = DateTimeOffset.Parse("30 Oct 2013 4:12:02 PM -07:00")
            };

            var truth = new Datum
            {
                type = Datum.DatumType.R_OBJECT
            };

            truth.r_object.Add(new Datum.AssocPair
            {
                key = "Id",
                val = new Datum
                {
                    type  = Datum.DatumType.R_STR,
                    r_str = "my_id"
                }
            });
            truth.r_object.Add(new Datum.AssocPair
            {
                key = "TheDateTimeOffset",
                val = new Datum
                {
                    type     = Datum.DatumType.R_OBJECT,
                    r_object =
                    {
                        new Datum.AssocPair {
                            key = "$reql_type$", val = new Datum{
                                type = Datum.DatumType.R_STR, r_str = "TIME"
                            }
                        },
                        new Datum.AssocPair {
                            key = "epoch_time", val = new Datum{
                                type = Datum.DatumType.R_NUM, r_num = 1383174722
                            }
                        },
                        new Datum.AssocPair {
                            key = "timezone", val = new Datum{
                                type = Datum.DatumType.R_STR, r_str = "-07:00"
                            }
                        },
                    }
                }
            });

            //ser test
            var ser = DatumConvert.SerializeObject(obj);

            ser.ShouldBeEquivalentTo(truth);

            //deser test
            var newtonObj = DatumConvert.DeserializeObject <ADateTimeOffset>(truth);

            newtonObj.ShouldBeEquivalentTo(obj);
        }
Ejemplo n.º 2
0
        public void JsonSerializationUsesKnownFormat()
        {
            var now    = DateTimeOffset.Now;
            var output = new ADateTimeOffset {
                Date = now
            };
            var json = output.ToJson(lowerCase: true);

            Assert.AreEqual($@"{{""date"":""{ now.ToUniversalTime().ToString(Constants.Iso8601Format, CultureInfo.InvariantCulture) }""}}", json);
        }
Ejemplo n.º 3
0
        public void EqualToTest()
        {
            var dateTime = new DateTimeOffset(new DateTime(1984, 1, 1), TimeSpan.FromHours(11));

            AssertPasses(dateTime, ADateTimeOffset.EqualTo(dateTime));
            AssertPasses(dateTime, ADateTimeOffset.EqualTo(new DateTimeOffset(new DateTime(1984, 1, 1), TimeSpan.FromHours(11))));
            AssertPasses(null, ADateTimeOffset.EqualTo(null));

            AssertFails(null, ADateTimeOffset.EqualTo(dateTime));
            AssertFails(DateTimeOffset.Now, ADateTimeOffset.EqualTo(dateTime));
        }
Ejemplo n.º 4
0
        public void EqualToPlusOrMinusTest()
        {
            var now     = DateTimeOffset.Now;
            var matcher = ADateTimeOffset.EqualTo(now).Within(2).Minutes();

            AssertPasses(now.AddMinutes(-2), matcher);
            AssertPasses(now, matcher);
            AssertPasses(now.AddMinutes(2), matcher);

            AssertFails(now.AddMinutes(-3), matcher);
            AssertFails(now.AddMinutes(3), matcher);
        }
Ejemplo n.º 5
0
        public void BeforeTest()
        {
            var dateTime = new DateTime(1984, 1, 1);

            var matcher = ADateTimeOffset.Before(dateTime);

            AssertPasses(dateTime.AddDays(-1), matcher);
            AssertPasses(dateTime.AddMilliseconds(-1), matcher);

            AssertFails(dateTime, matcher);
            AssertFails(dateTime.AddMilliseconds(1), matcher);
            AssertFails(dateTime.AddDays(1), matcher);
        }
Ejemplo n.º 6
0
        public void EqualToMinusMaxTest()
        {
            var now     = DateTimeOffset.Now;
            var matcher = ADateTimeOffset.EqualTo(now).MinusMax(2).Minutes();

            AssertPasses(now, matcher);
            AssertPasses(now.AddMinutes(-1), matcher);
            AssertPasses(now.AddMinutes(-2), matcher);

            AssertFails(now.AddMinutes(1), matcher);
            AssertFails(now.AddMinutes(2), matcher);
            AssertFails(now.AddMinutes(3), matcher);

            AssertFails(now.AddMinutes(-3), matcher);

            AssertPasses(null, ADateTimeOffset.EqualTo(null).MinusMax(1).Minutes());
        }
Ejemplo n.º 7
0
        public void NotNullTest()
        {
            AssertPasses(DateTimeOffset.Now, ADateTimeOffset.NotNull());

            AssertFails(null, ADateTimeOffset.NotNull());
        }