public void CrmEnvironmentBuilder_WithChildEntities_IncidentAndAccountButAccountAddedIncidentFirst_Should_CreateAccountFirst()
        {
            //
            // Arrange
            //
            var service  = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString()));
            var account  = new Id <Account>(Guid.NewGuid());
            var incident = new Id <Incident>(Guid.NewGuid());

            // The Account and Incident will be added as Account first, and Incident second.
            // The Lead will force an reorder and the Account incident would normally get placed after the Incident
            var builder = new DLaBCrmEnvironmentBuilder().
                          WithEntities(new Id <PhoneCall>(Guid.NewGuid()), incident, account).
                          WithChildEntities(account, incident);

            //
            // Act
            //
            builder.Create(service);


            //
            // Assert
            //

            AssertCrm.Exists(service, account);
            AssertCrm.Exists(service, incident);
            Assert.AreEqual(account.EntityReference, service.GetEntity(incident).CustomerId);
            Assert.AreEqual(account.EntityReference, incident.Entity.CustomerId);
        }
        public void CrmEnvironmentBuilder_WithChildEntities_BiDirectionalRelationship_Should_PopulateBothIds()
        {
            //
            // Arrange
            //
            var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString()));
            var contact = new Id <Contact>(Guid.NewGuid());
            var account = new Id <Account>(Guid.NewGuid());

            // The Account and Incident will be added as Account first, and Incident second.
            // The Lead will force a reorder and the Account incident would normally get placed after the Incident
            var builder = new DLaBCrmEnvironmentBuilder().
                          WithChildEntities(contact, account).
                          WithChildEntities(account, contact);

            //
            // Act
            //
            builder.Create(service);


            //
            // Assert
            //

            AssertCrm.Exists(service, account);
            AssertCrm.Exists(service, contact);
            Assert.AreEqual(contact.EntityReference, service.GetEntity(account).PrimaryContactId);
            Assert.AreEqual(contact.EntityReference, account.Entity.PrimaryContactId);
            Assert.AreEqual(account.EntityReference, service.GetEntity(contact).ParentCustomerId);
            Assert.AreEqual(account.EntityReference, contact.Entity.ParentCustomerId);
        }
        public void CrmEnvironmentBuilder_WithChildEntities_ContactAndAccountAdded_Should_AddedViaCustomerId()
        {
            //
            // Arrange
            //
            var service         = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString()));
            var account         = new Id <Account>(Guid.NewGuid());
            var contact         = new Id <Contact>(Guid.NewGuid());
            var accountIncident = new Id <Incident>(Guid.NewGuid());
            var contactIncident = new Id <Incident>(Guid.NewGuid());

            // The Account and Incident will be added as Account first, and Incident second.
            // The Lead will force an reorder and the Account incident would normally get placed after the Incident
            var builder = new DLaBCrmEnvironmentBuilder()
                          .WithChildEntities(contact, contactIncident)
                          .WithChildEntities(account, accountIncident);


            //
            // Act
            //
            builder.Create(service);


            //
            // Assert
            //

            AssertCrm.Exists(service, account);
            AssertCrm.Exists(service, accountIncident);
            AssertCrm.Exists(service, contact);
            AssertCrm.Exists(service, contactIncident);
        }
        public void CrmEnvironmentBuilder_ExceptEntities_GivenIdStruct_Should_CreateAllExceptExcluded()
        {
            //
            // Arrange
            //
            var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString()));

            //
            // Act
            //
            var builder = new DLaBCrmEnvironmentBuilder().
                          WithEntities <Ids>().
                          ExceptEntities <Ids.Nested>();

            builder.Create(service);

            //
            // Assert
            //

            AssertCrm.Exists(service, Ids.Value1);
            AssertCrm.Exists(service, Ids.Value2);
            AssertCrm.NotExists(service, Ids.Nested.Value1.EntityReference);
            AssertCrm.NotExists(service, Ids.Nested.Value2.EntityReference);
        }
예제 #5
0
        public void LocalCrmTests_Crud_NestedJoins()
        {
            TestInitializer.InitializeTestSettings();
            var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString()));

            var user1 = new Id <SystemUser>(Guid.NewGuid())
            {
                Entity = { FirstName = "Stan", }
            };
            var user2 = new Id <SystemUser>(Guid.NewGuid())
            {
                Entity = { FirstName = "Steve" }
            };
            var account = new Id <Account>(Guid.NewGuid())
            {
                Entity = { Name = "Marvel Comics" }
            };
            var contact1 = new Id <Contact>(Guid.NewGuid())
            {
                Entity = { FirstName = "Bruce", CreatedOnBehalfBy = user1, ModifiedOnBehalfBy = user2 }
            };
            var contact2 = new Id <Contact>(Guid.NewGuid())
            {
                Entity = { FirstName = "Peter", CreatedOnBehalfBy = user2, ModifiedOnBehalfBy = user1 }
            };

            var builder = new DLaBCrmEnvironmentBuilder().
                          WithChildEntities(account, contact1, contact2).
                          WithEntities(user1, user2);

            builder.Create(service);

            var temp = service.GetEntity(contact1);

            Assert.AreEqual(account.EntityReference, temp.ParentCustomerId);
            Assert.AreEqual(user1.EntityReference, temp.CreatedOnBehalfBy);
            Assert.AreEqual(user2.EntityReference, temp.ModifiedOnBehalfBy);
            temp = service.GetEntity(contact2);
            Assert.AreEqual(account.EntityReference, temp.ParentCustomerId);
            Assert.AreEqual(user1.EntityReference, temp.ModifiedOnBehalfBy);
            Assert.AreEqual(user2.EntityReference, temp.CreatedOnBehalfBy);

            var qe           = QueryExpressionFactory.Create <Account>(a => new { a.Name });
            var contactLink  = qe.AddLink <Contact>(Account.Fields.Id, Contact.Fields.ParentCustomerId, c => new { c.FirstName, c.Id });
            var createdLink  = contactLink.AddLink <SystemUser>(Contact.Fields.CreatedOnBehalfBy, SystemUser.Fields.Id, u => new { u.FirstName, u.Id });
            var modifiedLink = contactLink.AddLink <SystemUser>(Contact.Fields.ModifiedOnBehalfBy, SystemUser.Fields.Id, u => new { u.FirstName, u.Id });

            contactLink.EntityAlias  = "ContactLink";
            createdLink.EntityAlias  = "CreatedLink";
            modifiedLink.EntityAlias = "ModifiedLink";
            var results = service.RetrieveMultiple(qe);

            Assert.AreEqual(2, results.Entities.Count);
            foreach (var entity in results.Entities)
            {
                Assert.IsTrue(entity.Attributes.ContainsKey("CreatedLink.firstname"));
                Assert.IsTrue(entity.Attributes.ContainsKey("ModifiedLink.firstname"));
            }
        }