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"); }
public void InsertEntityThatIsNotMappedWithoutIDField() { var bulkUpdaterMock = new BulkUpdaterMock(); var couchDBClientMock = new CouchDBClientAdapterMock(null, bulkUpdaterMock); var subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); var entityInstance = new UnmappedWithoutIDEntity(); subject.Update(entityInstance); }
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 DeleteEntityAddedToBulkUpdater() { var bulkUpdaterMock = new BulkUpdaterMock(); var couchDBClientMock = new CouchDBClientAdapterMock(SingleUserRawResponse, bulkUpdaterMock); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject.View <UserModel>("fake_not_used").SingleOrDefault(); subject.Delete(user); subject.SaveChanges(); Assert.AreEqual(1, bulkUpdaterMock.EntitiesToDelete.Count); Assert.AreEqual("1", bulkUpdaterMock.EntitiesToDelete[0]); }
public void InsertTenantEntity_ValidateModifiedDocumentsCount() { var bulkUpdaterMock = new BulkUpdaterMock(); var couchDBClientMock = new CouchDBClientAdapterMock(null, bulkUpdaterMock); var subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); TenantModel newTenant = new TenantModel { TenantModelID = "2001", Name = "Tin-Tenant" }; subject.Update(newTenant); CouchPotatoAssert.ModifiedDocumentsCount(subject, 1); }
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 InsertTenantEntity_ValidateSaveChanges() { var bulkUpdaterMock = new BulkUpdaterMock(); var couchDBClientMock = new CouchDBClientAdapterMock(null, bulkUpdaterMock); var subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); TenantModel newTenant = new TenantModel { TenantModelID = "2001", Name = "Tin-Tenant" }; subject.Update(newTenant); subject.SaveChanges(); Assert.AreEqual(1, bulkUpdaterMock.EntitiesToUpdate.Count); Assert.AreEqual("2001", bulkUpdaterMock.EntitiesToUpdate[0].Value <string>("_id")); }
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)"); }