/// <summary> /// Defines the entities that will be returned when the particular entity type is queried for /// </summary> /// <param name="entities">The entities.</param> /// <returns></returns> public TDerived WithReturnedEntities(Dictionary <string, List <Entity> > entities) { RetrieveMultipleFuncs.Add((s, q) => { var qe = q as QueryExpression; if (qe == null || !entities.ContainsKey(qe.EntityName)) { return(s.RetrieveMultiple(q)); } return(new EntityCollection(entities[qe.EntityName])); }); RetrieveFuncs.Add((s, name, id, cs) => { List <Entity> list; if (entities.TryGetValue(name, out list)) { var entity = list.FirstOrDefault(e => e.Id == id); if (entity != null) { return(entity); } } return(s.Retrieve(name, id, cs)); }); 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> /// Adds the fake retrieve. /// </summary> /// <param name="func">The function.</param> /// <returns></returns> public TDerived WithFakeRetrieve(params Func <IOrganizationService, string, Guid, ColumnSet, Entity>[] func) { RetrieveFuncs.AddRange(func); return(This); }