Beispiel #1
0
        public void CommitAddedObject()
        {
            int callCount = 0;
            int exptectedCallCount = 1;

            var organisationService = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
            organisationService.ExecuteOrganizationRequest = (request) =>
            {
                callCount++;
                var results = new OrganizationResponse();

                return results;
            };

            var crmUnitOfWork = new CrmUnitOfWork(organisationService);
            var contactRepository = new
                Xrm.Infrastructure.DataAccess.Crm.Fakes.StubContactRepository(organisationService, crmUnitOfWork);

            contactRepository.PersistAddedEntityBase = (contact) =>
            {
                var sdkContact = new Contact();
                sdkContact.ContactId = contact.Id;
                sdkContact.FirstName = "test";
                var createRequest = new CreateRequest()
                {
                    Target = sdkContact
                };
                crmUnitOfWork.Requests.Add(createRequest);
            };

            contactRepository.Add(new Xrm.Domain.Contact.Contact());
            crmUnitOfWork.Commit();

            Assert.AreEqual(exptectedCallCount, callCount);
        }
Beispiel #2
0
        public void CommitRemovedObject()
        {
            int callCount = 0;
            int exptectedCallCount = 1;

            var organisationService = new Microsoft.Xrm.Sdk.Fakes.StubIOrganizationService();
            organisationService.ExecuteOrganizationRequest = (request) =>
            {
                callCount++;
                var results = new OrganizationResponse();

                return results;
            };

            var crmUnitOfWork = new CrmUnitOfWork(organisationService);
            var contactRepository = new
                Xrm.Infrastructure.DataAccess.Crm.Fakes.StubContactRepository(organisationService, crmUnitOfWork);

            contactRepository.PersistRemovedEntityBase = (contact) =>
            {
                var deleteRequest = new DeleteRequest()
                {
                    Target = new EntityReference(Contact.EntityLogicalName, Guid.NewGuid())
                };
                crmUnitOfWork.Requests.Add(deleteRequest);
            };

            contactRepository.Remove(new Xrm.Domain.Contact.Contact());
            crmUnitOfWork.Commit();

            Assert.AreEqual(exptectedCallCount, callCount);
        }