public void MakeNameMatchCase_NameIsMcdonald_Should_UpdateToMcDonald() { // // Arrange // var service = new LocalCrmDatabaseOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>()); var id = service.Create(new Contact { LastName = "Mcdonald" }); // // Act // MakeNameMatchCase(service, "McDonald"); // // Assert // Assert.AreEqual("McDonald", service.GetEntity <Contact>(id).LastName); }
/// <summary> /// Creates all foreign references that don't exist. This is usally due to the serialization grabbing more values than actually needed. /// </summary> /// <param name="service"></param> /// <param name="entity"></param> private bool CreateForeignReferences(LocalCrmDatabaseOrganizationService service, Entity entity) { var isSelfReferencing = false; var toRemove = new List <string>(); foreach (var attribute in entity.Attributes) { var foreign = attribute.Value as EntityReference; if (foreign == null) { continue; } // Check to makes sure the type has been defined. Don't create the Foreign Reference, and remove the attribute from the collection. if (!service.Info.IsTypeDefined(foreign.LogicalName)) { toRemove.Add(attribute.Key); continue; } if (foreign.Id == entity.Id) { isSelfReferencing = true; } if (service.GetEntitiesById(foreign.LogicalName, foreign.Id).Count == 0) { service.Create(new Entity { Id = foreign.Id, LogicalName = foreign.LogicalName }); } } foreach (var key in toRemove) { entity.Attributes.Remove(key); } return(isSelfReferencing); }
public void CrmEnvironmentBuilder_Create_WithMyOtherBuilder_Should_UseBuilder() { // // Arrange // var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())); var id = new Id <Lead>(Guid.NewGuid()); var email = "*****@*****.**"; // // Act // new DLaBCrmEnvironmentBuilder(). WithBuilder <MyOtherBuilder>(id, b => b.WithEmail(email)).Create(service); // // Assert // var lead = service.GetEntity(id); Assert.AreEqual(email, lead.EMailAddress1); }
public void CrmEnvironmentBuilder_WithEntities_GivenIdStruct_Should_CreateAll() { // // Arrange // var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())); // // Act // var builder = new CrmEnvironmentBuilder().WithEntities <Ids>(); builder.Create(service); // // Assert // AssertCrm.Exists(service, Ids.Value1); AssertCrm.Exists(service, Ids.Value2); AssertCrm.Exists(service, Ids.Nested.Value1); AssertCrm.Exists(service, Ids.Nested.Value2); }
public void CrmEnvironmentBuilder_Create_ConnectionAssociation_Should_CreateAssociationBeforeConnection() { var to = new Id <ConnectionRole>("D588F8F5-9276-471E-9A73-C62217C29FD1"); var from = new Id <ConnectionRole>("29E71A5B-692D-4777-846D-FD1687D7DDB7"); var association = new Id <ConnectionRoleAssociation>("C1B93E89-F070-4FE7-81B4-94BA123222CA"); var connection = new Id <Connection>("AC56E429-452F-49F5-A463-894E8CA8E17C"); connection.Inject(new Connection { Record1RoleId = to, Record2RoleId = from }); association.Inject(new ConnectionRoleAssociation { ConnectionRoleId = to, AssociatedConnectionRoleId = from }); var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())); var containsFailure = false; try { new CrmEnvironmentBuilder() .WithEntities(to, from, connection) .Create(service); } catch (Exception ex) { containsFailure = ex.ToString().Contains("The connection roles are not related"); } Assert.IsTrue(containsFailure, "CRM does not allow connection roles to be used on a connection without being associated."); service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())); new CrmEnvironmentBuilder() .WithEntities(to, from, association, connection) .Create(service); }
public void CrmEnvironmentBuilder_Create_WithBuilderSelfReferencingEntity_Should_CreateThenUpdate() { // // Arrange // var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())); var id = new Id <Lead>(Guid.NewGuid()); // // Act // new DLaBCrmEnvironmentBuilder(). WithBuilder <MyLeadBuilder>(id, b => b.WithAttributeValue(Lead.Fields.MasterId, id.EntityReference)). Create(service); // // Assert // AssertCrm.Exists(service, id); var lead = service.GetEntity(id); Assert.AreEqual(lead.MasterId, id.EntityReference); }
public void CrmEnvironmentBuilder_Create_WithSelfReferencingEntity_Should_CreateThenUpdate() { // // Arrange // var service = LocalCrmDatabaseOrganizationService.CreateOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())); var id = Guid.NewGuid(); var account = new Account { Id = id, ParentAccountId = new EntityReference(Account.EntityLogicalName, id) }; // // Act // new DLaBCrmEnvironmentBuilder().WithEntities(account).Create(service); // // Assert // AssertCrm.Exists(service, account); }
private static IOrganizationService GetService(bool createUnique = true) { return(createUnique ? new LocalCrmDatabaseOrganizationService(LocalCrmDatabaseInfo.Create <CrmContext>(Guid.NewGuid().ToString())) : LocalCrmDatabaseOrganizationService.CreateOrganizationService <CrmContext>()); }