예제 #1
0
        public void ShouldSaveDynamicWrapperWithXmlDate()
        {
            // Given

            var date1 = DateTime.Today.AddDays(1);
            var date2 = DateTime.Today.AddDays(2);
            var date3 = DateTime.Today.AddDays(3);

            var instance = new DynamicWrapper
            {
                { "_id", 1 },
                { "DateProperty", (Date)date1 },
                { "NullableDateProperty", (Date)date2 },
                {
                    "ComplexProperty", new DynamicWrapper
                    {
                        { "DateProperty", (Date)date3 }
                    }
                }
            };

            var converters     = new IMemberValueConverter[] { new XmlDateMemberValueConverter() };
            var classStorage   = MongoTestHelpers.GetEmptyStorageProvider <XmlDateClass>(nameof(ShouldSaveDynamicWrapperWithXmlDate), converters);
            var dynamicStorage = MongoTestHelpers.GetStorageProvider(nameof(ShouldSaveDynamicWrapperWithXmlDate), converters);

            // When

            dynamicStorage.InsertOne(instance);

            var classInstance   = classStorage.Find().FirstOrDefault();
            var dynamicInstance = dynamicStorage.Find().FirstOrDefault();

            // Then

            Assert.IsNotNull(classInstance);
            Assert.AreEqual(date1, classInstance.DateProperty);
            Assert.AreEqual(date2, classInstance.NullableDateProperty);
            Assert.IsNotNull(classInstance.ComplexProperty);
            Assert.AreEqual(date3, classInstance.ComplexProperty.DateProperty);
            Assert.IsNull(classInstance.ComplexProperty.NullableDateProperty);

            Assert.IsNotNull(dynamicInstance);
            Assert.AreEqual(((Date)date1).UnixTime, dynamicInstance["DateProperty"]);
            Assert.AreEqual(((Date)date2).UnixTime, dynamicInstance["NullableDateProperty"]);
            Assert.IsNotNull(dynamicInstance["ComplexProperty"]);
            Assert.AreEqual(((Date)date3).UnixTime, ((DynamicWrapper)dynamicInstance["ComplexProperty"])["DateProperty"]);
            Assert.IsNull(((DynamicWrapper)dynamicInstance["ComplexProperty"])["NullableDateProperty"]);
        }
예제 #2
0
        public void ShouldSaveDynamicWrapperWithDate()
        {
            // Given

            var date1 = Date.Now.AddDays(1);
            var date2 = Date.Now.AddDays(2);
            var date3 = Date.Now.AddDays(3);

            var instance = new DynamicWrapper
            {
                { "_id", 1 },
                { "DateProperty", date1 },
                { "NullableDateProperty", date2 },
                {
                    "ComplexProperty", new DynamicWrapper
                    {
                        { "DateProperty", date3 }
                    }
                }
            };

            var classStorage   = MongoTestHelpers.GetEmptyStorageProvider <DateClassExample>(nameof(ShouldSaveDynamicWrapperWithDate));
            var dynamicStorage = MongoTestHelpers.GetStorageProvider(nameof(ShouldSaveDynamicWrapperWithDate));

            // When

            dynamicStorage.InsertOne(instance);

            var classInstance   = classStorage.Find().FirstOrDefault();
            var dynamicInstance = dynamicStorage.Find().FirstOrDefault();

            // Then

            Assert.IsNotNull(classInstance);
            Assert.AreEqual(date1, classInstance.DateProperty);
            Assert.AreEqual(date2, classInstance.NullableDateProperty);
            Assert.IsNotNull(classInstance.ComplexProperty);
            Assert.AreEqual(date3, classInstance.ComplexProperty.DateProperty);
            Assert.IsNull(classInstance.ComplexProperty.NullableDateProperty);

            Assert.IsNotNull(dynamicInstance);
            Assert.AreEqual(date1.UnixTime, dynamicInstance["DateProperty"]);
            Assert.AreEqual(date2.UnixTime, dynamicInstance["NullableDateProperty"]);
            Assert.IsNotNull(dynamicInstance["ComplexProperty"]);
            Assert.AreEqual(date3.UnixTime, ((DynamicWrapper)dynamicInstance["ComplexProperty"])["DateProperty"]);
            Assert.IsNull(((DynamicWrapper)dynamicInstance["ComplexProperty"])["NullableDateProperty"]);
        }
        public void ShouldSaveDynamicWrapperWithTime()
        {
            // Given

            var time1 = Time.Now.AddDays(1);
            var time2 = Time.Now.AddDays(2);
            var time3 = Time.Now.AddDays(3);

            var instance = new DynamicWrapper
            {
                { "_id", 1 },
                { "TimeProperty", time1 },
                { "NullableTimeProperty", time2 },
                {
                    "ComplexProperty", new DynamicWrapper
                    {
                        { "TimeProperty", time3 }
                    }
                }
            };

            var classStorage   = MongoTestHelpers.GetEmptyStorageProvider <TimeClassExample>(nameof(ShouldSaveDynamicWrapperWithTime));
            var dynamicStorage = MongoTestHelpers.GetStorageProvider(nameof(ShouldSaveDynamicWrapperWithTime));

            // When

            dynamicStorage.InsertOne(instance);

            var classInstance   = classStorage.Find().FirstOrDefault();
            var dynamicInstance = dynamicStorage.Find().FirstOrDefault();

            // Then

            Assert.IsNotNull(classInstance);
            Assert.AreEqual(time1, classInstance.TimeProperty);
            Assert.AreEqual(time2, classInstance.NullableTimeProperty);
            Assert.IsNotNull(classInstance.ComplexProperty);
            Assert.AreEqual(time3, classInstance.ComplexProperty.TimeProperty);
            Assert.IsNull(classInstance.ComplexProperty.NullableTimeProperty);

            Assert.IsNotNull(dynamicInstance);
            Assert.AreEqual(time1.TotalSeconds, dynamicInstance["TimeProperty"]);
            Assert.AreEqual(time2.TotalSeconds, dynamicInstance["NullableTimeProperty"]);
            Assert.IsNotNull(dynamicInstance["ComplexProperty"]);
            Assert.AreEqual(time3.TotalSeconds, ((DynamicWrapper)dynamicInstance["ComplexProperty"])["TimeProperty"]);
            Assert.IsNull(((DynamicWrapper)dynamicInstance["ComplexProperty"])["NullableTimeProperty"]);
        }