public void AddRelationshipsToExistingEntity()
        {
            var connection = TestConfiguration.GetConnection();
            var dbSet      = new MongoDbSet <CollectionIntegrationModel>();

            dbSet.SetConnection(connection);

            var entity = dbSet.Create();

            entity.Description = "AddRelationshipsToExistingEntity";

            dbSet.SaveChanges();

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

            dbEntity.StringModelEntities.Add(new StringIdModel
            {
                Description = "AddRelationshipsToExistingEntity-StringIdModel-1"
            });
            dbEntity.StringModelEntities.Add(new StringIdModel
            {
                Description = "AddRelationshipsToExistingEntity-StringIdModel-2"
            });

            dbSet.SaveChanges();

            Assert.AreEqual(2, dbEntity.StringModelEntities.Count);
            Assert.IsTrue(dbEntity.StringModelEntities.All(e => e.Id != null));
        }
        public void ForceLoadEntities()
        {
            var connection = TestConfiguration.GetConnection();
            var dbSet      = new MongoDbSet <CollectionIntegrationModel>();

            dbSet.SetConnection(connection);

            var entity = dbSet.Create();

            entity.Description = "ForceLoadEntities";

            entity.StringModelEntities.Add(new StringIdModel
            {
                Description = "ForceLoadEntities-StringIdModel-1"
            });
            entity.StringModelEntities.Add(new StringIdModel
            {
                Description = "ForceLoadEntities-StringIdModel-2"
            });

            dbSet.SaveChanges();

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

            var navigationCollection = dbEntity.StringModelEntities as EntityNavigationCollection <StringIdModel>;

            Assert.AreEqual(2, navigationCollection.UnloadedCount);

            navigationCollection.LoadEntities();

            Assert.AreEqual(2, navigationCollection.LoadedCount);
            Assert.AreEqual(0, navigationCollection.UnloadedCount);
        }
        public async Task AddRelationshipsToNewEntityAsync()
        {
            var connection = TestConfiguration.GetConnection();
            var dbSet      = new MongoDbSet <CollectionIntegrationModel>();

            dbSet.SetConnection(connection);

            var entity = dbSet.Create();

            entity.Description = "AddRelationshipsToNewEntityAsync";

            entity.ObjectIdModelEntities.Add(new ObjectIdIdModel
            {
                Description = "AddRelationshipsToNewEntityAsync-ObjectIdIdModel-1"
            });
            entity.ObjectIdModelEntities.Add(new ObjectIdIdModel
            {
                Description = "AddRelationshipsToNewEntityAsync-ObjectIdIdModel-2"
            });

            await dbSet.SaveChangesAsync().ConfigureAwait(false);

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

            Assert.AreEqual(2, dbEntity.ObjectIdModelEntities.Count);
            Assert.IsTrue(dbEntity.ObjectIdModelEntities.All(e => e.Id != ObjectId.Empty));
        }
        public void RemoveRelationshipToEntity()
        {
            var connection = TestConfiguration.GetConnection();
            var dbSet      = new MongoDbSet <CollectionIntegrationModel>();

            dbSet.SetConnection(connection);

            var entity = dbSet.Create();

            entity.Description = "RemoveRelationshipToEntity";

            var item = new StringIdModel
            {
                Description = "RemoveRelationshipToEntity-StringIdModel-1"
            };

            entity.StringModelEntities.Add(item);

            dbSet.SaveChanges();

            entity.StringModelEntities.Remove(item);

            dbSet.SaveChanges();

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

            Assert.AreEqual(0, dbEntity.StringModelEntities.Count);

            var collectionDbSet = new MongoDbSet <StringIdModel>();

            collectionDbSet.SetConnection(connection);
            var itemDbEntity = collectionDbSet.Where(e => e.Id == item.Id).FirstOrDefault();

            Assert.IsNotNull(itemDbEntity);
        }