public JsonMemberValueConverter(bool canRead, bool canWrite, IMemberValueConverter valueConverter) { CanRead = canRead; CanWrite = canWrite; _valueConverter = valueConverter; }
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"]); }
public MongoMemberValueConverter(MemberInfo memberInfo, IMemberValueConverter converter) : base(GetMemberType(memberInfo)) { _converter = converter; }