public void UpdateAssoicatedCollection_ClearAndReAddOneOfTwoEntities_SlaveSide_ValidateOtherEntityIsUpdated()
        {
            var bulkUpdaterMock = new BulkUpdaterMock();

            bulkUpdaterMock.AddMockResponse(new BulkResponseRow("1", "2-123-Updated", null, null));

            var couchDBClientMock = new CouchDBClientAdapterMock(RawResponseWithTwoTenants, bulkUpdaterMock);
            var subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            var userToUpdate      = subject.View <UserModel>("fake_not_used")
                                    .AssociatedCollection(x => x.Tenants, 1)
                                    .SingleOrDefault();

            var firstTenant  = userToUpdate.Tenants.First();
            var secondTenant = userToUpdate.Tenants.Skip(1).First();

            // Clear and readd the first tenant
            userToUpdate.Tenants.Clear();
            userToUpdate.Tenants.Add(firstTenant);

            // Update the user even though it should have no effect
            subject.Update(userToUpdate);

            // TODO: it realy should be 1 because only TenantB is modified
            // by removing User 1 from it users array.
            int expectedModifiedDocuments = 3;

            CouchPotatoAssert.ModifiedDocumentsCount(subject, expectedModifiedDocuments, "Only the second tenant should be updated");
        }
        private static void PrepareForUpdate(out CouchDBContextImpl subject, out UserModel userToUpdate)
        {
            var bulkUpdaterMock = new BulkUpdaterMock();

            bulkUpdaterMock.AddMockResponse(new BulkResponseRow("1", "2-123-Updated", null, null));

            var couchDBClientMock = new CouchDBClientAdapterMock(RawResponseWithOneTenant, bulkUpdaterMock);

            subject      = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            userToUpdate = subject.View <UserModel>("fake_not_used").SingleOrDefault();
        }
        public void UpdateAssoicatedCollection_ClearCollection_SlaveSide_ValidateOtherEntityIsUpdated()
        {
            var bulkUpdaterMock = new BulkUpdaterMock();

            bulkUpdaterMock.AddMockResponse(new BulkResponseRow("1", "2-123-Updated", null, null));

            var couchDBClientMock = new CouchDBClientAdapterMock(RawResponseWithOneTenant, bulkUpdaterMock);
            var subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            var userToUpdate      = subject.View <UserModel>("fake_not_used")
                                    .AssociatedCollection(x => x.Tenants, 1)
                                    .SingleOrDefault();

            TenantModel tenantToRemove = userToUpdate.Tenants.Single();

            userToUpdate.Tenants.Clear();

            CouchPotatoAssert.ModifiedDocumentsCount(subject, 1);
        }
        public void UpdateAssoicatedCollection_RemoveEntityFromCollection_SlaveSide_ValidateOtherCollectionUpdated()
        {
            var bulkUpdaterMock = new BulkUpdaterMock();

            bulkUpdaterMock.AddMockResponse(new BulkResponseRow("1", "2-123-Updated", null, null));

            var couchDBClientMock = new CouchDBClientAdapterMock(RawResponseWithOneTenant, bulkUpdaterMock);
            var subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            var userToUpdate      = subject.View <UserModel>("fake_not_used")
                                    .AssociatedCollection(x => x.Tenants, 1)
                                    .SingleOrDefault();

            TenantModel tenantToRemove = userToUpdate.Tenants.Single();

            userToUpdate.Tenants.Remove(tenantToRemove);

            subject.SaveChanges();

            Assert.AreEqual(1, tenantToRemove.Users.Count);
        }
        public void UpdateAssoicatedCollection_AddNewEntity_SlaveSide_ValidateOtherEntityIsUpdated()
        {
            var bulkUpdaterMock = new BulkUpdaterMock();

            bulkUpdaterMock.AddMockResponse(new BulkResponseRow("1", "2-123-Updated", null, null));

            var couchDBClientMock = new CouchDBClientAdapterMock(RawResponseWithOneTenant, bulkUpdaterMock);
            var subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            var userToUpdate      = subject.View <UserModel>("fake_not_used")
                                    .AssociatedCollection(x => x.Tenants, 1)
                                    .SingleOrDefault();

            TenantModel newTenant = new TenantModel
            {
                TenantModelID = "2001",
                Name          = "Tin-Tenant",
                Users         = new HashSet <UserModel>()
            };

            subject.Update(newTenant);
            userToUpdate.Tenants.Add(newTenant);

            CouchPotatoAssert.ModifiedDocumentsCount(subject, 1, "Only the new tenant document should be updated (created)");
        }