/// <summary> /// Causes the Organization Service to throw an exception if an attempt is made to create an entity /// </summary> /// <returns></returns> public TDerived WithNoCreates() { CreateFuncs.Add((s, e) => { TestSettings.TestFrameworkProvider.AssertFail($"An attempt was made to Create a(n) {e.LogicalName} Entity with a ReadOnly Service{Environment.NewLine + Environment.NewLine}Entity Attributes:{e.ToStringAttributes()}"); throw new Exception("AssertFail Failed to through an Exception"); }); return(This); }
/// <summary> /// Defaults the Parent Businessunit Id of all business units to the root BU if not already populated /// </summary> /// <returns></returns> public TDerived WithDefaultParentBu() { CreateFuncs.Add((s, e) => { if (e.LogicalName == BusinessUnit.EntityLogicalName && e.GetAttributeValue <EntityReference>(BusinessUnit.Fields.ParentBusinessUnitId) == null) { var qe = QueryExpressionFactory.Create(BusinessUnit.EntityLogicalName, new ColumnSet(BusinessUnit.Fields.BusinessUnitId), BusinessUnit.Fields.ParentBusinessUnitId, null); e[BusinessUnit.Fields.ParentBusinessUnitId] = s.GetFirst <Entity>(qe).ToEntityReference(); } return(s.Create(e)); }); return(This); }
/// <summary> /// Defaults the entity name of all created entitites. /// </summary> /// <param name="getName">function to call to get the name for the given Entity and it's Primary Field Info</param> /// <returns></returns> public TDerived WithEntityNameDefaulted(Func <Entity, PrimaryFieldInfo, string> getName) { CreateFuncs.Add((s, e) => { var logicalName = e.LogicalName; if (!string.IsNullOrWhiteSpace(logicalName)) { var info = GetPrimaryFieldInfo(logicalName); SetName(e, info, getName); } return(s.Create(e)); }); return(This); }
/// <summary> /// Builds this IOrganizationService. /// </summary> /// <returns></returns> public IOrganizationService Build() { ApplyNewEntityDefaultIds(); ApplyEntityFilter(); return(new FakeIOrganizationService(Service) { AssociateActions = AssociateActions.ToArray(), CreateFuncs = CreateFuncs.ToArray(), DeleteActions = DeleteActions.ToArray(), DisassociateActions = DisassociateActions.ToArray(), ExecuteFuncs = ExecuteFuncs.ToArray(), RetrieveMultipleFuncs = RetrieveMultipleFuncs.ToArray(), RetrieveFuncs = RetrieveFuncs.ToArray(), UpdateActions = UpdateActions.ToArray() }); }
/// <summary> /// Defaults the entity name of all created entitites. /// </summary> /// <param name="getName">Name of the get.</param> /// <returns></returns> public TDerived WithEntityNameDefaulted(Func <Entity, EntityHelper.PrimaryFieldInfo, string> getName) { CreateFuncs.Add((s, e) => { var logicalName = e.LogicalName; if (!string.IsNullOrWhiteSpace(logicalName)) { var info = EntityHelper.GetPrimaryFieldInfo(logicalName); if (info.AttributeName != null && !e.Attributes.ContainsKey(info.AttributeName)) { var name = getName(e, info); e[info.AttributeName] = name.PadRight(info.MaximumLength).Substring(0, info.MaximumLength).TrimEnd(); } } return(s.Create(e)); }); return(This); }
private void ApplyNewEntityDefaultIds() { if (!NewEntityDefaultIds.Any()) { return; } CreateFuncs.Add((s, e) => { DefaultIdForEntity(e); return(s.Create(e)); }); ExecuteFuncs.Add((s, r) => { if (r is SendEmailFromTemplateRequest email) { DefaultIdForEntity(email.Target); } return(s.Execute(r)); }); }
/// <summary> /// Asserts that any create of an entity has the id popualted. Useful to ensure that all entities can be deleted after they have been created since the id is known. /// </summary> /// <returns></returns> public TDerived AssertIdNonEmptyOnCreate() { CreateFuncs.Add(AssertIdNonEmptyOnCreate); return(This); }
/// <summary> /// Adds the fake create. /// </summary> /// <param name="func">The function.</param> /// <returns></returns> public TDerived WithFakeCreate(params Func <IOrganizationService, Entity, Guid>[] func) { CreateFuncs.AddRange(func); return(This); }