/// <summary> /// Creates the activity pointer if the Entity is an Activty Type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="service">The service.</param> /// <param name="entity">The entity.</param> private static void CreateActivityPointer <T>(LocalCrmDatabaseOrganizationService service, T entity) where T : Entity { if (EntityHelper.GetEntityLogicalName <T>() == ActivityPointer.EntityLogicalName) { return; // Type is already an activity pointer, no need to recreated } if (!PropertiesCache.For <T>().IsActivityType) { return; // Type is not an activity type } // Copy over matching values and create service.Create(GetActivtyPointerForActivityEntity(entity)); }
/// <summary> /// Creates the activity pointer if the Entity is an Activty Type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="service">The service.</param> /// <param name="entity">The entity.</param> private static void CreateActivityPointer <T>(LocalCrmDatabaseOrganizationService service, T entity) where T : Entity { if (EntityHelper.GetEntityLogicalName <T>() == ActivityPointer.EntityLogicalName) { return; // Type is already an activity pointer, no need to recreated } var properties = typeof(T).GetProperties().ToDictionary(p => p.Name); if (!IsActivityType <T>(properties)) { return; // Type is not an activity type } // Copy over matching values and create service.Create(GetActivtyPointerForActivityEntity(entity, properties)); }
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); }
private static IClientSideOrganizationService GetLocalCrmDatabaseOrganizationService(string organizationName, Guid impersonationUserId) { // Create a unique Database for each Unit Test by looking up the first method in the stack trace that has a TestMethodAttribute, // and using it's method handle, combined with the OrganizationName, as a unqiue Key var method = GetUnitTestMethod() ?? MethodBase.GetCurrentMethod(); string databaseKey = String.Format("UnitTest {0}:{1}:{2}", method.Name, organizationName, method.MethodHandle); var info = LocalCrmDatabaseInfo.Create(TestSettings.EarlyBound.Assembly, TestSettings.EarlyBound.Namespace, databaseKey, impersonationUserId); var service = new LocalCrmDatabaseOrganizationService(info); // Create BU and SystemUser for currently executing user var bu = new Entity(BusinessUnit.EntityLogicalName) { [BusinessUnit.Fields.Name] = "Currently Executing BusinessUnit" }; bu.Id = service.Create(bu); var id = service.Create(new Entity(SystemUser.EntityLogicalName) { [SystemUser.Fields.FirstName] = Environment.UserDomainName.Split('/').First(), [SystemUser.Fields.LastName] = Environment.UserName, [SystemUser.Fields.BusinessUnitId] = bu.ToEntityReference(), }.ToSdkEntity()); info = LocalCrmDatabaseInfo.Create(TestSettings.EarlyBound.Assembly, TestSettings.EarlyBound.Namespace, databaseKey, id, impersonationUserId, bu.Id); return new LocalCrmDatabaseOrganizationService(info); }