private static void TestForPhoneNumber(IOrganizationService service, QueryExpression qe, FilterExpression accountFilter, string telephone) { accountFilter.WhereEqual( Account.Fields.Telephone1, telephone, LogicalOperator.Or, Account.Fields.Telephone2, telephone, LogicalOperator.Or, Account.Fields.Telephone3, telephone ); var entity = service.GetFirstOrDefault(qe); Assert.IsNotNull(entity, $"{qe.EntityName} should have been found with matching telephone 1 number."); var account = service.GetFirst <Account>(); account.Telephone2 = telephone; account.Telephone1 = telephone + "1"; service.Update(account); entity = service.GetFirstOrDefault(qe); Assert.IsNotNull(entity, $"{qe.EntityName} should have been found with matching telephone 2 number."); account.Telephone3 = telephone; account.Telephone2 = telephone + "2"; service.Update(account); entity = service.GetFirstOrDefault(qe); Assert.IsNotNull(entity, $"{qe.EntityName} should have been found with matching telephone 3 number."); service = new OrganizationServiceBuilder(service) .WithEntityFilter <Account>(account.Id).Build(); entity = service.GetFirstOrDefault(qe); Assert.IsNotNull(entity, $"{qe.EntityName} should have been found with matching telephone 3 number and Id."); account.Telephone3 += "A"; service.Update(account); entity = service.GetFirstOrDefault(qe); Assert.IsNull(entity, $"{qe.EntityName} should have not have been found with a non-matching telephone 3 number and Id."); }
/// <summary> /// Causes the Build Service provider to have an IOrganizationServiceFactory that returns the given service. /// </summary> /// <param name="service">The service.</param> /// <param name="userId">The user identifier.</param> /// <param name="setWhoAmIUserId">if set to <c>true</c> wraps service with a WhoAmI of the current user.</param> /// <returns></returns> public TDerived WithService(IOrganizationService service, Guid userId, bool setWhoAmIUserId = true) { if (setWhoAmIUserId) { var builder = new OrganizationServiceBuilder(service); builder.WithFakeExecute((s, r) => { if (r is WhoAmIRequest) { var result = (WhoAmIResponse)s.Execute(r); result.Results["UserId"] = userId; return(result); } return(s.Execute(r)); }); service = builder.Build(); } ((FakeOrganizationServiceFactory)ServiceProvider.GetService <IOrganizationServiceFactory>()).SetService(userId, service); return(This); }