Exemplo n.º 1
0
        public void AttachRejectsMismatchedEntities()
        {
            var connection = TestConfiguration.GetConnection();
            var tenantId   = TestConfiguration.GetTenantId();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <DbSetModel>(context);

            var entities = new[] {
                new DbSetModel
                {
                    Id = "abcd"
                },
                new DbSetModel
                {
                    Id = "efgh"
                }
            };

            dbSet.AddRange(entities);

            context.SaveChanges();

            ResetMongoDb();

            context = new MongoDbTenantContext(connection, tenantId);
            dbSet   = new MongoDbTenantSet <DbSetModel>(context);

            var result = dbSet.AsNoTracking().ToList();

            result[0].TenantId = tenantId + "a";

            Assert.ThrowsException <MultiTenantException>(() => context.AttachRange(result));
        }
Exemplo n.º 2
0
        public void AttachRejectsMismatchedEntity()
        {
            var connection = TestConfiguration.GetConnection();
            var tenantId   = TestConfiguration.GetTenantId();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <DbSetModel>(context);

            var model = new DbSetModel
            {
                Id = "abcd"
            };

            dbSet.Add(model);

            context.SaveChanges();

            ResetMongoDb();

            context = new MongoDbTenantContext(connection, tenantId);
            dbSet   = new MongoDbTenantSet <DbSetModel>(context);

            var result = dbSet.AsNoTracking().FirstOrDefault();

            result.TenantId = tenantId + "a";

            Assert.ThrowsException <MultiTenantException>(() => context.Attach(result));
        }
Exemplo n.º 3
0
        public void SuccessfullyAttachUntrackedEntity()
        {
            var connection = TestConfiguration.GetConnection();
            var tenantId   = TestConfiguration.GetTenantId();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <DbSetModel>(context);

            var model = new DbSetModel
            {
                Id = "abcd"
            };

            dbSet.Add(model);

            context.SaveChanges();

            ResetMongoDb();

            context = new MongoDbTenantContext(connection, tenantId);
            dbSet   = new MongoDbTenantSet <DbSetModel>(context);

            var result = dbSet.AsNoTracking().FirstOrDefault();

            context.Attach(result);

            Assert.AreEqual(MongoFramework.Infrastructure.EntityEntryState.NoChanges, context.ChangeTracker.GetEntry(result).State);
        }
Exemplo n.º 4
0
        public void SuccessfullyAttachUntrackedEntities()
        {
            var connection = TestConfiguration.GetConnection();
            var tenantId   = TestConfiguration.GetTenantId();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <DbSetModel>(context);

            var entities = new[] {
                new DbSetModel
                {
                    Id = "abcd"
                },
                new DbSetModel
                {
                    Id = "efgh"
                }
            };

            dbSet.AddRange(entities);

            context.SaveChanges();

            ResetMongoDb();

            context = new MongoDbTenantContext(connection, tenantId);
            dbSet   = new MongoDbTenantSet <DbSetModel>(context);

            var result = dbSet.AsNoTracking().ToList();

            context.AttachRange(result);

            Assert.AreEqual(MongoFramework.Infrastructure.EntityEntryState.NoChanges, context.ChangeTracker.GetEntry(result[0]).State);
            Assert.AreEqual(MongoFramework.Infrastructure.EntityEntryState.NoChanges, context.ChangeTracker.GetEntry(result[1]).State);
        }
        public async Task SuccessfullyLinqFindNoTrackingAsync()
        {
            var connection = TestConfiguration.GetConnection();
            var tenantId   = TestConfiguration.GetTenantId();
            var context    = new MongoDbTenantContext(connection, tenantId);
            var dbSet      = new MongoDbTenantSet <TestModel>(context);

            var model = new TestModel
            {
                Id          = "abcd",
                Description = "SuccessfullyFindTracked.1"
            };

            dbSet.Add(model);

            context.SaveChanges();

            ResetMongoDb();

            context = new MongoDbTenantContext(connection, tenantId);
            dbSet   = new MongoDbTenantSet <TestModel>(context);

            var result = await dbSet.AsNoTracking().FirstOrDefaultAsync();

            Assert.IsNull(context.ChangeTracker.GetEntry(result));
        }