コード例 #1
0
        public void LocalCrmTests_AdvancedCrud()
        {
            // Verify that linked items exist upon create
            var service = GetService();
            var contact = new Contact {Id = Guid.NewGuid()};
            var opp = new Opportunity {ParentContactId = contact.ToEntityReference()};

            try
            {
                service.Create(opp);
                Assert.Fail("Opportunity Creation should have failed since the Contact Doesn't exist");
            }
            catch (System.ServiceModel.FaultException<OrganizationServiceFault> ex)
            {
                Assert.IsTrue(ex.Message.Contains(String.Format("With Id = {0} Does Not Exist", contact.Id)), "Exception type is different than expected");
            }
            catch (AssertFailedException)
            {
                throw;
            }
            catch (Exception)
            {
                Assert.Fail("Exception type is different than expected");
            }

            service.Create(contact);
            AssertCrm.Exists(service, contact);
            opp.Id = service.Create(opp);
            AssertCrm.Exists(service, opp);
        }
コード例 #2
0
        public void RemovePhoneNumberFormatting_ContactHasFormatting_Should_RemoveFormatting()
        {
            //
            // Arrange
            //
            TestInitializer.InitializeTestSettings();
            var contact = new Contact { MobilePhone = "A-1-B-2-C-3" }; // Create Contact to use as target
            var plugin = new RemovePhoneNumberFormatting();
            var context = new PluginExecutionContextBuilder(). // Create Context Which is required by the service provider, which is required by the plugin
                WithRegisteredEvent(plugin.RegisteredEvents.First(e => e.EntityLogicalName == Contact.EntityLogicalName)). // Specifies the plugin event to use in the context
                WithTarget(contact).Build(); // Sets the Target
            var provider = new ServiceProviderBuilder().
                WithContext(context).Build();
            //
            // Act
            //
            plugin.Execute(provider); // Executes the Plugin

            //
            // Assert
            //

            Assert.AreEqual("123", contact.MobilePhone);
        }
コード例 #3
0
        public void LocalCrmTests_RetrieveOuterJoinedColumn()
        {
            var service = GetService();
            var contact = new Contact {FirstName = "Joe"};
            contact.Id = service.Create(contact);

            // Create 2 opportunities
            service.Create(new Opportunity {CustomerId = contact.ToEntityReference()});
            service.Create(new Opportunity());

            var qe = QueryExpressionFactory.Create<Opportunity>();
            qe.AddLink<Contact>(Opportunity.Fields.ParentContactId, Contact.Fields.ContactId, JoinOperator.LeftOuter, c => new {c.FirstName});

            var entities = service.GetEntities(qe);
            Assert.AreEqual(2, entities.Count, "Two opportunities should have been returned!");
            Assert.AreEqual(contact.FirstName, entities.First(o => o.ParentContactId != null).GetAliasedEntity<Contact>().FirstName, "First Name wasn't returned!");
            Assert.IsNull(entities.First(o => o.ParentContactId == null).GetAliasedEntity<Contact>().FirstName, "Second Opportunity some how has a contact!");
        }
コード例 #4
0
        public void LocalCrmTests_RetrieveFilterOnOuterJoinedColumn()
        {
            var service = GetService();
            var contact1 = new Contact {FirstName = "Joe"};
            contact1.Id = service.Create(contact1);
            var contact2 = new Contact {FirstName = "Jim"};
            contact2.Id = service.Create(contact2);
            var contact3 = new Contact {FirstName = "Jake"};
            contact3.Id = service.Create(contact3);

            service.Create(new Opportunity {CustomerId = contact1.ToEntityReference()});
            service.Create(new Opportunity {CustomerId = contact2.ToEntityReference()});
            service.Create(new Opportunity {CustomerId = contact3.ToEntityReference()});
            service.Create(new Opportunity());

            var qe = QueryExpressionFactory.Create<Opportunity>();
            qe.AddLink<Contact>(Opportunity.Fields.ParentContactId, Contact.Fields.ContactId, JoinOperator.LeftOuter, c => new {c.FirstName}).EntityAlias = "MyAlias";
            qe.Criteria.AddCondition("MyAlias", Contact.Fields.FirstName, ConditionOperator.Equal, "Joe");
            var entities = service.GetEntities(qe);

            Assert.AreEqual(1, entities.Count, "Only Joe opportunities should have been returned!");
            Assert.AreEqual(contact1.FirstName, entities[0].GetAliasedEntity<Contact>().FirstName);

            qe.Criteria.AddCondition("MyAlias", Contact.Fields.FirstName, ConditionOperator.Equal, "Jim");
            qe.Criteria.FilterOperator = LogicalOperator.Or;
            entities = service.GetEntities(qe);

            Assert.AreEqual(2, entities.Count, "Joe and Jim opportunities should have been returned!");
        }
コード例 #5
0
        public void LocalCrmTests_LateBoundCrud()
        {
            var contact = new Contact();
            var lateContact = new Entity {LogicalName = Contact.EntityLogicalName};

            var service = GetService();
            contact.Id = service.Create(contact);
            lateContact.Id = service.Create(lateContact);

            Assert.IsNotNull(service.Retrieve(contact.LogicalName, contact.Id, new ColumnSet()), "Failed Create or Read");
            Assert.IsNotNull(service.Retrieve(lateContact.LogicalName, lateContact.Id, new ColumnSet()), "Failed Create or Read");
            Assert.AreEqual(2, service.GetEntities<Contact>().Count, "Failed Create or Read");

            contact.FirstName = "Early";
            lateContact["firstname"] = "Late";

            service.Update(contact);
            service.Update(lateContact);

            Assert.IsNotNull(service.Retrieve(contact.LogicalName, contact.Id, new ColumnSet("firstname")), "Failed Update or Read");
            Assert.IsNotNull(service.Retrieve(lateContact.LogicalName, lateContact.Id, new ColumnSet("firstname")), "Failed Update or Read");

            service.Delete(contact);
            service.Delete(lateContact);

            Assert.AreEqual(0, service.GetEntities<Contact>().Count, "Failed Delete or Read");
        }
コード例 #6
0
 public void LocalCrmTests_ColumnSetLookups()
 {
     var service = GetService();
     const string firstName = "Joe";
     const string lastName = "Plumber";
     var contact = new Contact {FirstName = firstName, LastName = lastName};
     contact.Id = service.Create(contact);
     var cs = new ColumnSet("firstname");
     Assert.AreEqual(firstName, service.GetEntity<Contact>(contact.Id, cs).FirstName, "Failed to retrieve first name correctly");
     Assert.IsNull(service.GetEntity<Contact>(contact.Id, cs).LastName, "Last name was not requested, but was returned");
     Assert.AreEqual(firstName + " " + lastName, service.GetEntity<Contact>(contact.Id).FullName, "Full Name not populated correctly");
 }
コード例 #7
0
        public void LocalCrmTests_BasicCrud()
        {
            var c1 = new Contact {Id = Guid.NewGuid(), FirstName = "Joe", LastName = "Plumber"};
            var c2 = new Contact {Id = Guid.NewGuid(), FirstName = "Bill", LastName = "Carpenter"};
            var opp = new Opportunity {Id = Guid.NewGuid(), CustomerId = c1.ToEntityReference() };

            var service = GetService();
            service.Create(c1);
            service.Create(c2);
            service.Create(opp);

            Assert.IsNotNull(service.GetFirstOrDefault<Opportunity>(Opportunity.Fields.ParentContactId, c1.Id), "Failed Simple Lookup by Attribute Entity Reference");
            Assert.AreEqual(1, service.GetEntitiesById<Contact>(c1.Id).Count, "Failed Simple Where In Lookup by Id");

            var qe = QueryExpressionFactory.Create<Opportunity>();
            qe.AddLink<Contact>(Opportunity.Fields.ParentContactId, "contactid", c => new {c.FirstName});

            var otherC = service.GetFirstOrDefault(qe);

            Assert.IsNotNull(otherC, "Failed Simple Lookup with Linked Entity on Entity Reference");
            Assert.AreEqual(c1.FirstName, otherC.GetAliasedEntity<Contact>().FirstName, "Failed Simple Lookup retrieving Linked Entity columns");
        }