public void ExtraElementsSerializationIntegrationTest()
        {
            EntityMapping.AddMappingProcessor(new CollectionNameProcessor());
            EntityMapping.AddMappingProcessor(new ExtraElementsProcessor());
            EntityMapping.RegisterType(typeof(ExtraElementsAttrModel));
            EntityMapping.RegisterType(typeof(ModelWithExtraElements));

            var connection = TestConfiguration.GetConnection();
            var modelWithExtraPropertiesDbSet = new MongoDbSet <ModelWithExtraElements>();

            modelWithExtraPropertiesDbSet.SetConnection(connection);

            var entity = new ModelWithExtraElements
            {
                PropertyOne = "ModelWithExtraElements",
                PropertyTwo = 123
            };

            modelWithExtraPropertiesDbSet.Add(entity);
            modelWithExtraPropertiesDbSet.SaveChanges();

            var extraElementsAttrModelDbSet = new MongoDbSet <ExtraElementsAttrModel>();

            extraElementsAttrModelDbSet.SetConnection(connection);

            var dbEntity = extraElementsAttrModelDbSet.Where(e => e.Id == entity.Id).FirstOrDefault();

            Assert.AreEqual("ModelWithExtraElements", dbEntity.AdditionalElements[nameof(ModelWithExtraElements.PropertyOne)]);
            Assert.AreEqual(123, dbEntity.AdditionalElements[nameof(ModelWithExtraElements.PropertyTwo)]);
        }
Пример #2
0
        public void ExtraElementsSerializationIntegrationTest()
        {
            EntityMapping.AddMappingProcessor(new CollectionNameProcessor());
            EntityMapping.AddMappingProcessor(new PropertyMappingProcessor());
            EntityMapping.AddMappingProcessor(new ExtraElementsProcessor());
            EntityMapping.RegisterType(typeof(ExtraElementsAttrModel));
            EntityMapping.RegisterType(typeof(ModelWithExtraElements));

            var connection = TestConfiguration.GetConnection();
            var context    = new MongoDbContext(connection);

            var entity = new ModelWithExtraElements
            {
                PropertyOne = "ModelWithExtraElements",
                PropertyTwo = 123
            };

            context.ChangeTracker.SetEntityState(entity, EntityEntryState.Added);
            context.SaveChanges();

            var dbEntity = context.Query <ExtraElementsAttrModel>().Where(e => e.Id == entity.Id).FirstOrDefault();

            Assert.AreEqual("ModelWithExtraElements", dbEntity.AdditionalElements[nameof(ModelWithExtraElements.PropertyOne)]);
            Assert.AreEqual(123, dbEntity.AdditionalElements[nameof(ModelWithExtraElements.PropertyTwo)]);
        }