예제 #1
0
        public void WithRestrictDeleteDependenciesAndDependentRecords_RecordsDeleted()
        {
            var mockOrganizationService = new Mock <IExtendedOrganizationService>(MockBehavior.Strict);

            mockOrganizationService.Setup(o => o.GetOneToManyRelationships(entityName)).Returns(GetOneToManyRelationshipMetadata()).Verifiable();
            mockOrganizationService.Setup(o => o.GetOneToManyRelationships(relatedEntityName)).Returns(new OneToManyRelationshipMetadata[] { }).Verifiable();

            mockOrganizationService.Setup(
                o => o.RetrieveAllRecords(It.IsAny <string>()))
            .Returns(DependentRecordIds.Select(d => new Entity {
                Id = d
            }).ToList())
            .Verifiable();

            mockOrganizationService.Setup(o => o.ExecuteMultipleReturnAdapter(It.Is <ExecuteMultipleRequest>(r => r.Requests.Count == 4)))
            .Returns(GetExecuteMultipleResponseAdapter(DependentRecordIds).Object).Verifiable();
            mockOrganizationService.Setup(o => o.ExecuteMultipleReturnAdapter(It.Is <ExecuteMultipleRequest>(r => r.Requests.Count == 3)))
            .Returns(GetExecuteMultipleResponseAdapter(RecordsToDelete).Object).Verifiable();

            var cascadeDeleter = new CascadeDeleter(mockOrganizationService.Object);
            var results        = cascadeDeleter.CascadeDeleteRecords(entityName, RecordsToDelete);

            mockOrganizationService.Verify();
            Assert.IsTrue(DependentRecordIds.Concat(RecordsToDelete).SequenceEqual(results.Select(r => new Guid(r.RecordID))));
        }
예제 #2
0
        public void CascadeDeleteWithNoDependencies_DeletesRecords()
        {
            var mockOrganizationService = new Mock <IExtendedOrganizationService>(MockBehavior.Strict);

            mockOrganizationService.Setup(o => o.GetOneToManyRelationships(entityName)).Returns(new OneToManyRelationshipMetadata[] { }).Verifiable();

            var executeMultipleResponse = GetExecuteMultipleResponseAdapter(RecordsToDelete);

            mockOrganizationService.Setup(o => o.ExecuteMultipleReturnAdapter(It.Is <ExecuteMultipleRequest>(r => r.Requests.Count == 3)))
            .Returns(executeMultipleResponse.Object)
            .Verifiable();

            var cascadeDeleter = new CascadeDeleter(mockOrganizationService.Object);
            var results        = cascadeDeleter.CascadeDeleteRecords(entityName, RecordsToDelete);

            mockOrganizationService.Verify();

            Assert.IsTrue(RecordsToDelete.SequenceEqual(results.Select(r => new Guid(r.RecordID))));
        }