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); }
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"); }