public void UpdateEntity()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <EntityWriterModel>();
            var writer          = new DbEntityWriter <EntityWriterModel>(database);
            var reader          = new DbEntityReader <EntityWriterModel>(database);

            //Get entity initially into the DB so we can update it
            var entity = new EntityWriterModel
            {
                Title = "DbEntityWriterTests.UpdateEntity"
            };

            entityContainer.Update(entity, DbEntityEntryState.Added);
            writer.Write(entityContainer);
            entityContainer.Clear();

            //Our updated entity with the same ID
            var updatedEntity = new EntityWriterModel
            {
                Id    = entity.Id,
                Title = "DbEntityWriterTests.UpdateEntity-Updated"
            };

            entityContainer.Update(updatedEntity, DbEntityEntryState.Updated);
            writer.Write(entityContainer);

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

            Assert.AreEqual("DbEntityWriterTests.UpdateEntity-Updated", dbEntity.Title);
        }
Ejemplo n.º 2
0
        public void ReadMixedEntities()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <A>();
            var reader          = new DbEntityReader <A>(database);
            var writer          = new DbEntityWriter <A>(database);

            entityContainer.Update(new A
            {
                Description = "DbEntityReaderTests.ReadMixedEntities"
            }, DbEntityEntryState.Added);

            entityContainer.Update(new B
            {
                BIsForBoolean = true,
                Description   = "DbEntityReaderTests.ReadMixedEntities"
            }, DbEntityEntryState.Added);


            writer.Write(entityContainer);

            var readMixedEntitiesQuery =
                reader.AsQueryable().Where(e => e.Description == "DbEntityReaderTests.ReadMixedEntities");

            Assert.AreEqual(2, readMixedEntitiesQuery.Count());
            Assert.AreEqual(2, readMixedEntitiesQuery.OfType <A>().Count());
            Assert.AreEqual(1, readMixedEntitiesQuery.OfType <B>().Count());
        }
Ejemplo n.º 3
0
        public void UpdateExistingEntryInstanceMatch()
        {
            var entityCollection = new DbEntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Title = "DbEntityCollectionTests.UpdateExistingEntryWithoutId"
            };

            entityCollection.Update(entity, DbEntityEntryState.Added);
            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == DbEntityEntryState.Added));

            entityCollection.Update(entity, DbEntityEntryState.NoChanges);
            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == DbEntityEntryState.NoChanges));
        }
        public void AddMixedTypeEntities()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <EntityWriterModel>();
            var writer          = new DbEntityWriter <EntityWriterModel>(database);
            var entities        = new[]
            {
                new EntityWriterModel
                {
                    Title = "DbEntityWriterTests.AddMixedTypeEntities"
                },
                new ExtendedEntityWriterModel
                {
                    Title           = "DbEntityWriterTests.AddMixedTypeEntities",
                    AdditionalField = "AdditionalFieldSet"
                }
            };

            foreach (var entity in entities)
            {
                entityContainer.Update(entity, DbEntityEntryState.Added);
            }

            writer.Write(entityContainer);

            Assert.IsTrue(entities.OfType <EntityWriterModel>().Any(e => e.Title == "DbEntityWriterTests.AddMixedTypeEntities"));
            Assert.IsTrue(entities.OfType <ExtendedEntityWriterModel>().Any(e => e.AdditionalField == "AdditionalFieldSet"));
        }
Ejemplo n.º 5
0
        public void RemoveRange()
        {
            var entityCollection = new DbEntityCollection <EntityCollectionModel>();
            var entities         = new[]
            {
                new EntityCollectionModel
                {
                    Title = "DbEntityCollectionTests.RemoveRange-1"
                },
                new EntityCollectionModel
                {
                    Title = "DbEntityCollectionTests.RemoveRange-2"
                },
                new EntityCollectionModel
                {
                    Id    = "123",
                    Title = "DbEntityCollectionTests.RemoveRange-3"
                }
            };

            foreach (var entity in entities)
            {
                entityCollection.Update(entity, DbEntityEntryState.Added);
                entityCollection.Remove(entity);
            }

            Assert.IsFalse(entityCollection.GetEntries().Any());
        }
Ejemplo n.º 6
0
        public void EntityProcessorsNotFiredWhenNotTEntity()
        {
            var database = TestConfiguration.GetDatabase();

            new EntityMapper <MongoFrameworkQueryableModel>();
            var collection          = database.GetCollection <MongoFrameworkQueryableModel>("MongoFrameworkQueryableModel");
            var underlyingQueryable = collection.AsQueryable();
            var queryable           = new MongoFrameworkQueryable <MongoFrameworkQueryableModel, MongoFrameworkQueryableModel>(underlyingQueryable);

            var processor = new TestProcessor <MongoFrameworkQueryableModel>();

            queryable.EntityProcessors.Add(processor);

            var entityContainer = new DbEntityCollection <MongoFrameworkQueryableModel>();
            var writer          = new DbEntityWriter <MongoFrameworkQueryableModel>(database);

            entityContainer.Update(new MongoFrameworkQueryableModel {
                Title = "EntityProcessorNoFireTest"
            }, DbEntityEntryState.Added);
            writer.Write(entityContainer);

            foreach (var titles in queryable.Select(e => e.Title))
            {
                //Do nothing
            }

            Assert.IsFalse(processor.EntityProcessed);
        }
Ejemplo n.º 7
0
        public void AddNewEntry()
        {
            var entityCollection = new DbEntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Title = "DbEntityCollectionTests.AddNewEntry"
            };

            entityCollection.Update(entity, DbEntityEntryState.Added);

            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == DbEntityEntryState.Added));
        }
        public async Task MixedActionWriteAsync()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <EntityWriterModel>();
            var writer          = new DbEntityWriter <EntityWriterModel>(database);
            var reader          = new DbEntityReader <EntityWriterModel>(database);

            var updateEntity = new EntityWriterModel
            {
                Title = "DbEntityWriterTests.MixedActionWriteAsync-UpdateEntity"
            };
            var deleteEntity = new EntityWriterModel
            {
                Title = "DbEntityWriterTests.MixedActionWriteAsync-DeleteEntity"
            };

            entityContainer.Update(updateEntity, DbEntityEntryState.Added);
            entityContainer.Update(deleteEntity, DbEntityEntryState.Added);
            await writer.WriteAsync(entityContainer).ConfigureAwait(false);

            entityContainer.Clear();

            var addedEntity = new EntityWriterModel
            {
                Title = "DbEntityWriterTests.MixedActionWriteAsync-AddEntity"
            };

            updateEntity.Title = "DbEntityWriterTests.MixedActionWriteAsync-UpdateEntity-Updated";
            entityContainer.Update(addedEntity, DbEntityEntryState.Added);
            entityContainer.Update(updateEntity, DbEntityEntryState.Updated);
            entityContainer.Update(deleteEntity, DbEntityEntryState.Deleted);
            await writer.WriteAsync(entityContainer).ConfigureAwait(false);

            Assert.IsTrue(reader.AsQueryable().Where(e => e.Id == addedEntity.Id).Any());
            Assert.IsFalse(reader.AsQueryable().Where(e => e.Id == deleteEntity.Id).Any());

            var dbEntity = reader.AsQueryable().Where(e => e.Id == updateEntity.Id).FirstOrDefault();

            Assert.AreEqual("DbEntityWriterTests.MixedActionWriteAsync-UpdateEntity-Updated", dbEntity.Title);
        }
        public void ValidObjectId()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <MongoDbUtilityModel>();
            var writer          = new DbEntityWriter <MongoDbUtilityModel>(database);

            var entity = new MongoDbUtilityModel();

            entityContainer.Update(entity, DbEntityEntryState.Added);
            writer.Write(entityContainer);

            Assert.IsTrue(MongoDbUtility.IsValidObjectId(entity.Id));
        }
        public void RemoveEntity()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <EntityWriterModel>();
            var writer          = new DbEntityWriter <EntityWriterModel>(database);
            var reader          = new DbEntityReader <EntityWriterModel>(database);

            //Get entity initially into the DB so we can remove it
            var entity = new EntityWriterModel
            {
                Title = "DbEntityWriterTests.RemoveEntity"
            };

            entityContainer.Update(entity, DbEntityEntryState.Added);
            writer.Write(entityContainer);
            entityContainer.Clear();

            //Remove the entity
            entityContainer.Update(entity, DbEntityEntryState.Deleted);
            writer.Write(entityContainer);

            Assert.IsFalse(reader.AsQueryable().Any(e => e.Id == entity.Id));
        }
Ejemplo n.º 11
0
        public void UpdateExistingEntryIdMatch()
        {
            var entityCollection = new DbEntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Id    = "123",
                Title = "DbEntityCollectionTests.UpdateExistingEntryWithId-1"
            };

            entityCollection.Update(entity, DbEntityEntryState.Added);
            Assert.IsTrue(entityCollection.GetEntries().All(e => e.Entity == entity && e.State == DbEntityEntryState.Added));

            var updatedEntity = new EntityCollectionModel
            {
                Id    = "123",
                Title = "DbEntityCollectionTests.UpdateExistingEntryWithId-2"
            };

            entityCollection.Update(updatedEntity, DbEntityEntryState.Updated);
            Assert.IsFalse(entityCollection.GetEntries().Any(e => e.Entity == entity));
            Assert.IsTrue(entityCollection.GetEntries()
                          .Any(e => e.Entity == updatedEntity && e.Entity.Title == "DbEntityCollectionTests.UpdateExistingEntryWithId-2"));
        }
Ejemplo n.º 12
0
        public void ClearTracker()
        {
            var entityCollection = new DbEntityCollection <EntityCollectionModel>();
            var entity           = new EntityCollectionModel
            {
                Title = "DbEntityCollectionTests.ClearTracker"
            };

            entityCollection.Update(entity, DbEntityEntryState.NoChanges);

            entityCollection.Clear();

            Assert.IsFalse(entityCollection.GetEntries().Any());
        }
        public void AddEntity()
        {
            var database        = TestConfiguration.GetDatabase();
            var entityContainer = new DbEntityCollection <EntityWriterModel>();
            var writer          = new DbEntityWriter <EntityWriterModel>(database);

            var entity = new EntityWriterModel
            {
                Title = "DbEntityWriterTests.AddEntity"
            };

            entityContainer.Update(entity, DbEntityEntryState.Added);
            writer.Write(entityContainer);

            Assert.IsNotNull(entity.Id);
        }
Ejemplo n.º 14
0
        public void EnumerateQueryable()
        {
            var database = TestConfiguration.GetDatabase();

            new EntityMapper <MongoFrameworkQueryableModel>();
            var collection          = database.GetCollection <MongoFrameworkQueryableModel>("MongoFrameworkQueryableModel");
            var underlyingQueryable = collection.AsQueryable();
            var queryable           = new MongoFrameworkQueryable <MongoFrameworkQueryableModel, MongoFrameworkQueryableModel>(underlyingQueryable);

            var entityContainer = new DbEntityCollection <MongoFrameworkQueryableModel>();
            var writer          = new DbEntityWriter <MongoFrameworkQueryableModel>(database);

            entityContainer.Update(new MongoFrameworkQueryableModel {
                Title = "EnumerateQueryable"
            }, DbEntityEntryState.Added);
            writer.Write(entityContainer);

            foreach (var entity in queryable)
            {
                Assert.AreEqual("EnumerateQueryable", entity.Title);
            }
        }