public void ValidateNotSpecifiedFieldAreNullProperties() { string rawResponse = @" { total_rows: 123, offset: 40, rows: [ { id: ""1"", key: ""ido.ran"", value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject.View <UserModel>("fake_not_used").SingleOrDefault(); Assert.IsNull(user.FirstName); }
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 ValidateFieldNamesWithTwoWords() { string rawResponse = @" { total_rows: 248, offset: 0, rows: [ { id: ""20130722094352-TenantA"", key: [ ""1"", 1 ], value: null, doc: { _id: ""20130722094352-TenantA"", _rev: ""1-9aa586de15bb6784b48600741a8bf841"", defaultLanguage: ""he-IL"", name: ""Tenant-A"", planID: ""Free30"", users: [ ""1"" ], $type: ""tenant"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); TenantModel tenant = subject.View <TenantModel>("fake_not_used").SingleOrDefault(); Assert.AreEqual("he-IL", tenant.DefaultLanguage); }
public void LoadUserWithSingleAssociateTenant() { string rawResponse = @" { total_rows: 248, offset: 0, rows: [ { id: ""1"", key: [ ""1"", 0 ], value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", roles: [ ""Admin"" ], username: ""ido.ran"", $type: ""user"" } }, { id: ""20130722094352-TenantA"", key: [ ""1"", 1 ], value: null, doc: { _id: ""20130722094352-TenantA"", _rev: ""1-9aa586de15bb6784b48600741a8bf841"", defaultLanguage: ""he-IL"", name: ""Tenant-A"", planID: ""Free30"", users: [ ""1"" ], $type: ""tenant"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject .View <UserModel>("fake_not_used") .AssociatedCollection(x => x.Tenants, 1) .SingleOrDefault(); TenantModel tenant = user.Tenants.Single(); Assert.IsNotNull(tenant); }
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); }
public static CouchDBContextImpl BuildContextForTest(CouchDBClientAdapterMock couchDBClientMock) { var context = new CouchDBContextImpl(couchDBClientMock); context.Mapping.MapDocTypeToEntity("user", typeof(UserModel)); context.Mapping.MapDocTypeToEntity("tenant", typeof(TenantModel)); context.Mapping.MapDocTypeToEntity("plan", typeof(PlanModel)); return(context); }
public void LoadExistMultipleResults_SingleItemFromView_Exception() { string rawResponse = @" { total_rows: 123, offset: 40, rows: [ { id: ""1"", key: ""ido.ran"", value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } }, { id: ""2"", key: ""ido.ran"", value: null, doc: { _id: ""2"", _rev: ""1-2edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject.View <UserModel>("fake_not_used").SingleOrDefault(); Assert.IsNull(user); }
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 DeleteEntityMarkItForDeletion() { var couchDBClientMock = new CouchDBClientAdapterMock(SingleUserRawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject.View <UserModel>("fake_not_used").SingleOrDefault(); subject.Delete(user); DocumentState actual = subject.DocumentManager.DocInfo(user.UserModelID).State; DocumentState expected = DocumentState.Delete; Assert.AreEqual(expected, actual); }
public void LoadNotExistSingleItemFromView() { string rawResponse = @" { total_rows: 123, offset: 40, rows: [] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject.View <UserModel>("fake_not_used").Key("yoval.b").SingleOrDefault(); Assert.IsNull(user); }
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 LoadReduceViewToEntities() { string rawResponse = @" { rows: [ { key: ""20121010170328-מבנה-ארגוני"", value: { yes: 49, no: 3, count: 52 } }, { key: ""20120821121948-Test2"", value: { yes: 4, no: 4, count: 8 } }, { key: ""20120814132737-שאלון-לבדיקה-1"", value: { yes: 14, no: 66, count: 80 } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); ReduceEntity[] results = subject.ReduceView <ReduceEntity>("fake_not_used").ToArray(); Assert.IsNotNull(results); Assert.AreEqual(3, results.Length); }
private static CouchDocInfo GetCleanDocInfo() { string rawResponse = @" { total_rows: 123, offset: 40, rows: [ { id: ""1"", key: ""ido.ran"", value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel userToUpdate = subject.View <UserModel>("fake_not_used").SingleOrDefault(); CouchDocInfo docInfo = subject.DocumentManager.DocInfo("1"); return(docInfo); }
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)"); }
public void LoadMultipleUserWithSingleAssociateTenant() { string rawResponse = @" { total_rows: 248, offset: 0, rows: [ { id: ""1"", key: [ ""1"", 0 ], value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } }, { id: ""20130722094352-TenantA"", key: [ ""1"", 1 ], value: null, doc: { _id: ""20130722094352-TenantA"", _rev: ""1-9aa586de15bb6784b48600741a8bf841"", defaultLanguage: ""he-IL"", name: ""Tenant-A"", planID: ""Free30"", users: [ ""1"" ], $type: ""tenant"" } }, { id: ""10"", key: [ ""10"", 0 ], value: null, doc: { _id: ""10"", _rev: ""1-a24d2f93d829d6a4901ea2767cf6b67c"", email: ""*****@*****.**"", password: ""9AC256B12CD5000CBCA395EB15B7872E5C8C3F4E"", passwordSalt: ""CS0KHNC0ukhG9LzJDh+WI0WZzoyRC5GCwWA6UGJOAbY="", tenants: [ ""20121224110842-shakira"" ], username: ""*****@*****.**"", $type: ""user"" } }, { id: ""20121224110842-shakira"", key: [ ""10"", 1 ], value: null, doc: { _id: ""20121224110842-shakira"", _rev: ""1-d786ce65b8694a4c2d3a3b77b43be131"", defaultLanguage: ""he"", name: ""shakira"", planID: ""Free30"", users: [ ""10"", ""26"" ], $type: ""tenant"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); IEnumerable <UserModel> users = subject.View <UserModel>("fake_not_used"); Assert.AreEqual(2, users.Count()); }
public void ReadToOneRelatedEntitiesOfSingleSourceEntity() { string rawResponse = @" { total_rows: 123, offset: 40, rows: [ { id: ""1"", key: ""ido.ran"", value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", planID: ""Plan20"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); couchDBClientMock.AddGetDocumentResponse( @" { total_rows: 241, offset: 0, rows: [ { id: ""Plan20"", key: ""Plan20"", value: { rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6"" }, doc: { _id: ""Plan20"", _rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6"", currency: ""USD"", maxEmployees: 30, name: ""Plan20"", price: 20, $type: ""plan"" } } ] } "); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel user = subject.View <UserModel>("fake_not_used").SingleOrDefault(); Assert.IsNull(user.Plan); subject.LoadRelated(user, cfg => cfg.One(x => x.Plan)); Assert.IsNotNull(user.Plan); }
public void ReadToOneRelatedEntitiesOfMultipleSourceEntity() { string rawResponse = @" { total_rows: 123, offset: 40, rows: [ { id: ""1"", key: ""ido.ran"", value: null, doc: { _id: ""1"", _rev: ""1-1edc9b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", planID: ""Plan20"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" }, id: ""2"", key: ""doron.shavit"", value: null, doc: { _id: ""2"", _rev: ""2-2eb16b67751f21e58895635c4eb47456"", email: ""*****@*****.**"", password: ""AAABBBCCC"", passwordSalt: ""123123123"", planID: ""Free30"", roles: [ ""Admin"" ], tenants: [ ""20130722094352-TenantA"" ], username: ""ido.ran"", $type: ""user"" } } ] }"; var couchDBClientMock = new CouchDBClientAdapterMock(rawResponse); couchDBClientMock.AddGetDocumentResponse( @" { total_rows: 241, offset: 0, rows: [ { id: ""Plan20"", key: ""Plan20"", value: { rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6"" }, doc: { _id: ""Plan20"", _rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6"", currency: ""USD"", maxEmployees: 30, name: ""Plan20"", price: 20, $type: ""plan"" } }, { id: ""Free30"", key: ""Free30"", value: { rev: ""1-86604726db035c16d8bc32ec6762377c"" }, doc: { _id: ""Free30"", _rev: ""1-86604726db035c16d8bc32ec6762377c"", currency: ""USD"", maxEmployees: 30, name: ""Free"", price: 0, $type: ""plan"" } } ] } "); CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock); UserModel[] users = subject.View <UserModel>("fake_not_used").ToArray(); subject.LoadRelated(users, cfg => cfg.One(x => x.Plan)); Assert.IsTrue(users.All(x => x.Plan != null)); }