public void DeleteAllHappyPath() { var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { JohnContact, JamieContact, JacobContact, JeremyContact, JamesContact // James isn't in London }); var preContacts = (from a in context.CreateQuery <Contact>() where a.Address1_City == "London" select a).ToList(); Assert.AreEqual(4, preContacts.Count); Assert.DoesNotThrow(() => SampleLondonContactsQueryByAttribute.DeleteAllResults(orgService)); var postContacts = (from a in context.CreateQuery <Contact>() where a.Address1_City == "London" select a).ToList(); Assert.AreEqual(0, postContacts.Count); }
public void ServiceEndpointAlreadyExistsWithNoClobber() { var manifestPath = $"{PluginManifestFolderPath}/plugin-manifest.xml"; var manifest = SerialisationWrapper.DeserialiseFromFile <PluginManifest>(manifestPath); var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { ExistingTesterQueueEndpoint, UpdateSdkMessage, UpdateContactMessageFilter, UpdateAccountMessageFilter }); manifest.Clobber = false; var pluginWrapper = new PluginWrapper(); pluginWrapper.RegisterServiceEndpoints(manifest, orgService); var postRegisteredEndpoints = (from e in context.CreateQuery <ServiceEndpoint>() where e.Name == "TesterQueue" select e).ToList(); var postRegisteredEndpointSteps = (from s in context.CreateQuery <SdkMessageProcessingStep>() where Equals(s.EventHandler, postRegisteredEndpoints.FirstOrDefault().ToEntityReference()) select s).ToList(); Assert.AreEqual(1, postRegisteredEndpoints.Count); Assert.AreEqual(2, postRegisteredEndpointSteps.Count); }
public void When_updating_an_entity_Modified_On_Should_Also_Be_Updated() { var context = new XrmFakedContext(); var service = context.GetFakedOrganizationService(); var e = new Entity("account") { Id = Guid.NewGuid() }; context.Initialize(new List <Entity>() { e }); var oldModifiedOn = context.CreateQuery <Account>() .FirstOrDefault() .ModifiedOn; Thread.Sleep(1000); service.Update(e); var newModifiedOn = context.CreateQuery <Account>() .FirstOrDefault() .ModifiedOn; Assert.NotEqual(oldModifiedOn, newModifiedOn); }
public void Register_Assembly_With_Higher_Version_Number_Should_Create_New() { var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { ExistingPluginAssembly }); _pluginAssemblyInfo.Version = "2.0.0.0"; _unitTestPluginAssembly.Register(orgService, _pluginAssemblyInfo); var updatedAssembly = (from a in context.CreateQuery <PluginAssembly>() where a.Name == _unitTestPluginAssembly.Name select a).ToList(); Assert.AreEqual(2, updatedAssembly.Count); var updatedAssemblyV2 = (from a in context.CreateQuery <PluginAssembly>() where a.Name == _unitTestPluginAssembly.Name && a.Version == "2.0.0.0" select a).ToList(); updatedAssemblyV2.Should().HaveCount(1); }
public void Plugin_registration_should_exit_after_assembly_reg_if_update_only() { var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { UpdateSdkMessage, CreateSdkMessage, UpdateContactMessageFilter, UpdateAccountMessageFilter, CreateContactMessageFilter }); SampleFullPluginManifest.UpdateAssemblyOnly = true; var pluginWrapper = new PluginWrapper(); pluginWrapper.RegisterPlugins(SampleFullPluginManifest, orgService); var postRegisteredAssemblies = (from a in context.CreateQuery <PluginAssembly>() where a.Name == "SamplePluginAssembly" select a).ToList(); var postRegistrationPlugins = (from p in context.CreateQuery <PluginType>() select p).ToList(); postRegisteredAssemblies.Should().HaveCount(1, "assembly should always be registered"); postRegistrationPlugins.Should().HaveCount(0, "would be 2 if UpdateAssemblyOnly == false"); }
public void ExpectedNumberOfResultsAreReturnedAllAreDeleted() { var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { JohnContact, JamieContact, JamesContact // James isn't in London }); var preContacts = (from a in context.CreateQuery <Contact>() where a.Address1_City == "London" select a).ToList(); Assert.AreEqual(2, preContacts.Count); Assert.DoesNotThrow( () => SampleLondonContactsQueryByAttribute.DeleteAllResults(orgService, expectedResultsToDelete: 2)); var postContacts = (from a in context.CreateQuery <Contact>() where a.Address1_City == "London" select a).ToList(); Assert.AreEqual(0, postContacts.Count); }
public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) { var req = (RemoveMembersTeamRequest)request; if (req.TeamId == null || req.TeamId == Guid.Empty) { throw new FaultException <OrganizationServiceFault>(new OrganizationServiceFault(), "TeamId parameter is required"); } if (req.MemberIds == null) { throw new FaultException <OrganizationServiceFault>(new OrganizationServiceFault(), "MemberIds parameter is required"); } var service = ctx.GetOrganizationService(); // Find the list var team = ctx.CreateQuery("team").FirstOrDefault(e => e.Id == req.TeamId); if (team == null) { throw new FaultException <OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("Team with Id {0} wasn't found", req.TeamId.ToString())); } foreach (var memberId in req.MemberIds) { var user = ctx.CreateQuery("systemuser").FirstOrDefault(e => e.Id == memberId); if (user == null) { throw new FaultException <OrganizationServiceFault>(new OrganizationServiceFault(), string.Format("SystemUser with Id {0} wasn't found", memberId.ToString())); } var queryTeamMember = new QueryExpression("teammembership") { TopCount = 1, ColumnSet = new ColumnSet("teammembershipid"), Criteria = { Conditions = { new ConditionExpression("teamid", ConditionOperator.Equal, req.TeamId), new ConditionExpression("systemuserid", ConditionOperator.Equal, user.Id) } } }; var teamMember = ctx.Service.RetrieveMultiple(queryTeamMember).Entities.FirstOrDefault(); if (teamMember != null) { service.Delete("teammembership", teamMember.Id); } } return(new RemoveMembersTeamResponse()); }
public void Should_create_phonecall_history_record_for_contact_and_phonenumber() { _context.ExecutePluginWithTarget <PhoneCallCreatePlugin>(_phoneCall); var phoneCallHistory = _context.CreateQuery <ultra_phonecallhistory>().FirstOrDefault(); Assert.NotNull(phoneCallHistory); Assert.Equal(_contact.Id, phoneCallHistory.ultra_contactid.Id); Assert.Equal(_phoneCall.PhoneNumber, phoneCallHistory.ultra_phonenumber); }
public void DoesNotHaveOldEntity() { _doubleUpdater.UpdateWithTwoNumbers(FirstUpdatedNumber, SecondUpdatedNumber); var returnedInitialEntitiesAfterUpdate = from thing in _fakeContext.CreateQuery(DoubleUpdater.EntityLogicalName) where thing[DoubleUpdater.AttributeName] as int? == InitialNumber select thing; Assert.Equal(0, returnedInitialEntitiesAfterUpdate.Count()); }
public void When_a_request_is_called_User_Is_Added_To_Record_Team() { var context = new XrmFakedContext(); var teamTemplate = new TeamTemplate { Id = Guid.NewGuid(), DefaultAccessRightsMask = (int)AccessRights.ReadAccess }; var user = new SystemUser { Id = Guid.NewGuid() }; var account = new Account { Id = Guid.NewGuid() }; context.Initialize(new Entity[] { teamTemplate, user, account }); var executor = new AddUserToRecordTeamRequestExecutor(); var req = new AddUserToRecordTeamRequest { Record = account.ToEntityReference(), SystemUserId = user.Id, TeamTemplateId = teamTemplate.Id }; executor.Execute(req, context); var team = context.CreateQuery <Team>().FirstOrDefault(p => p.TeamTemplateId.Id == teamTemplate.Id); Assert.NotNull(team); var teamMembership = context.CreateQuery <TeamMembership>().FirstOrDefault(p => p.SystemUserId == user.Id && p.TeamId == team.Id); Assert.NotNull(teamMembership); var poa = context.CreateQuery("principalobjectaccess").FirstOrDefault(p => (Guid)p["objectid"] == account.Id && (Guid)p["principalid"] == team.Id); Assert.NotNull(poa); var response = context.AccessRightsRepository.RetrievePrincipalAccess(account.ToEntityReference(), user.ToEntityReference()); Assert.Equal((AccessRights)teamTemplate.DefaultAccessRightsMask, response.AccessRights); }
public void Given_When_PluginExecutesCreateAccount_Then_CreateDummyContact() { //Arrange - can use testData from constructor or specific data defined her under arrange //Act _context.ExecutePluginWithTarget <Account>(_account); var contact = _context.CreateQuery("contact").FirstOrDefault(); //Assert Assert.NotNull(contact); Assert.Equal(_account.Id, ((EntityReference)contact["parentaccount"]).Id); }
public void When_set_state_request_is_called_an_entity_is_updated() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var service = context.GetFakedOrganizationService(); var c = new Contact() { Id = Guid.NewGuid() }; context.Initialize(new[] { c }); var request = new SetStateRequest { EntityMoniker = c.ToEntityReference(), State = new OptionSetValue(69), Status = new OptionSetValue(6969), }; var response = service.Execute(request); //Retrieve record after update var contact = (from con in context.CreateQuery<Contact>() where con.Id == c.Id select con).FirstOrDefault(); Assert.Equal((int) contact.StateCode.Value, 69); Assert.Equal((int) contact.StatusCode.Value, 6969); }
public void When_using_typed_entities_ProxyTypesAssembly_is_not_mandatory() { var context = new XrmFakedContext(); var service = context.GetFakedOrganizationService(); var c = new Contact() { Id = Guid.NewGuid(), FirstName = "Jordi" }; context.Initialize(new List <Entity>() { c }); //Linq 2 Query Expression using (var ctx = new XrmServiceContext(service)) { var contacts = (from con in ctx.CreateQuery <Contact>() select con).ToList(); Assert.Equal(contacts.Count, 1); } //Query faked context directly var ex = Record.Exception(() => context.CreateQuery <Contact>()); Assert.Null(ex); }
public void Created_Acconts_Should_Set_Primary_Contacts_Parent_Customer() { //Arrange var context = new XrmFakedContext(); var contact = new Contact() { Id = Guid.NewGuid(), FirstName = "Betim", LastName = "Beja" }; context.Initialize(contact); var target = new Account() { Id = Guid.NewGuid(), Name = "AlbanianXrm", PrimaryContactId = contact.ToEntityReference() }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters.Add(PluginBase.Target, target); //Act context.ExecutePluginWith <SetContactsCustomer>(pluginContext); //Assert var updatedContact = context.CreateQuery <Contact>().FirstOrDefault(); Assert.NotNull(updatedContact); Assert.NotNull(updatedContact.ParentCustomerId); Assert.Equal(target.Id, updatedContact.ParentCustomerId.Id); }
public void Should_create_phone_call_history_on_create_of_a_phonecall_with_its_details() { var ctx = new XrmFakedContext(); var contact = new Contact() { Id = Guid.NewGuid() }; var phoneCall = new PhoneCall() { Id = Guid.NewGuid(), RegardingObjectId = contact.ToEntityReference(), PhoneNumber = "+34666666666" }; ctx.ExecutePluginWithTarget <PhoneCallCreatePlugin>(phoneCall); var historyRecords = ctx.CreateQuery <ultra_phonecallhistory>().ToList(); Assert.Equal(1, historyRecords.Count); var historyRecord = historyRecords.First(); Assert.Equal(phoneCall.PhoneNumber, historyRecord.ultra_phonenumber); Assert.Equal(phoneCall.RegardingObjectId.Id, historyRecord.ultra_contactid.Id); Assert.Equal(historyRecord.Id, phoneCall.ultra_phonecallhistoryid.Id); }
public void Check_if_Opportunity_status_is_Win_after_set() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var service = context.GetFakedOrganizationService(); var opportunity = new Opportunity() { Id = Guid.NewGuid() }; context.Initialize(new[] { opportunity }); var request = new WinOpportunityRequest() { OpportunityClose = new OpportunityClose { OpportunityId = new EntityReference(Opportunity.EntityLogicalName, opportunity.Id) }, Status = new OptionSetValue((int)OpportunityState.Won) }; service.Execute(request); var opp = (from op in context.CreateQuery <Opportunity>() where op.Id == opportunity.Id select op).FirstOrDefault(); Assert.Equal(opp.StatusCode.Value, (int)OpportunityState.Won); }
public void RecordCountThresholdPassedExceptionThrown() { var expectedExceptionMessage = $"DeleteAllResults query returned too many results to proceed. " + $"Threshold was set to 2"; var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { JohnContact, JamieContact, JacobContact, JeremyContact }); Assert.Throws(Is.TypeOf <QueryBaseException>().And.Message.EqualTo(expectedExceptionMessage), () => SampleLondonContactsQueryByAttribute.DeleteAllResults(orgService, 2) ); // Assert that nothing's been deleted var postContacts = (from a in context.CreateQuery <Contact>() where a.Address1_City == "London" select a).ToList(); Assert.AreEqual(4, postContacts.Count); }
public void When_updating_an_entity_an_unchanged_attribute_remains_the_same() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)); var existingAccount = new Account() { Id = Guid.NewGuid(), Name = "Super Great Customer", AccountNumber = "69" }; context.Initialize(new List <Entity>() { existingAccount }); var service = context.GetFakedOrganizationService(); //Create a new entity class to update the name var accountToUpdate = new Account() { Id = existingAccount.Id }; accountToUpdate.Name = "Super Great Customer Name Updated!"; //Update the entity in the context service.Update(accountToUpdate); //Make sure existing entity still maintains AccountNumber property var account = context.CreateQuery <Account>().FirstOrDefault(); Assert.Equal(account.AccountNumber, "69"); }
public void When_updating_an_entity_using_organization_context_changes_should_be_saved() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)); var existingAccount = new Account() { Id = Guid.NewGuid(), Name = "Super Great Customer", AccountNumber = "69" }; context.Initialize(new List <Entity>() { existingAccount }); var service = context.GetFakedOrganizationService(); using (var ctx = new OrganizationServiceContext(service)) { existingAccount.Name = "Super Great Customer Name Updated!"; ctx.Attach(existingAccount); ctx.UpdateObject(existingAccount); ctx.SaveChanges(); } //Make other account wasn't updated var account = context.CreateQuery <Account>().Where(e => e.Id == existingAccount.Id).FirstOrDefault(); Assert.Equal(account.Name, "Super Great Customer Name Updated!"); }
public void When_execute_is_called_all_requests_are_executed_with_responses() { var context = new XrmFakedContext(); var executor = new ExecuteTransactionExecutor(); var req = new ExecuteTransactionRequest() { ReturnResponses = true, Requests = new OrganizationRequestCollection() { new CreateRequest() { Target = new Entity("contact") }, new CreateRequest() { Target = new Entity("contact") }, new CreateRequest() { Target = new Entity("contact") } } }; var response = executor.Execute(req, context) as ExecuteTransactionResponse; var contacts = context.CreateQuery("contact").ToList(); Assert.Equal(3, response.Responses.Count); Assert.Equal(3, contacts.Count); }
public void When_the_followup_plugin_is_executed_for_an_account_after_create_it_should_create_a_new_task_with_a_regardingid() { var fakedContext = new XrmFakedContext(); fakedContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); //Needed to be able to return early bound entities var guid1 = Guid.NewGuid(); var target = new Entity("account") { Id = guid1 }; ParameterCollection inputParameters = new ParameterCollection(); inputParameters.Add("Target", target); ParameterCollection outputParameters = new ParameterCollection(); outputParameters.Add("id", guid1); fakedContext.ExecutePluginWith <FollowupPlugin>(inputParameters, outputParameters, null, null); //The plugin creates a followup activity, check that that one exists var tasks = (from t in fakedContext.CreateQuery <Task>() select t).ToList(); Assert.True(tasks.Count == 1); Assert.True(tasks[0].Subject.Equals("Send e-mail to the new customer.")); Assert.True(tasks[0].RegardingObjectId != null && tasks[0].RegardingObjectId.Id.Equals(guid1)); }
public void When_Executing_Assign_Request_New_Owner_Should_Be_Assigned() { var oldOwner = new EntityReference("systemuser", Guid.NewGuid()); var newOwner = new EntityReference("systemuser", Guid.NewGuid()); var account = new Account { Id = Guid.NewGuid(), OwnerId = oldOwner }; var context = new XrmFakedContext(); var service = context.GetOrganizationService(); context.Initialize(new [] { account }); var assignRequest = new AssignRequest { Target = account.ToEntityReference(), Assignee = newOwner }; service.Execute(assignRequest); //retrieve account updated var updatedAccount = context.CreateQuery <Account>().FirstOrDefault(); Assert.Equal(newOwner.Id, updatedAccount.OwnerId.Id); }
public void Should_Not_Raise_An_Exception_When_Updating_Status() { var entityId = Guid.NewGuid(); var context = new XrmFakedContext(); var service = context.GetOrganizationService(); context.Initialize(new[] { new Account() { Id = entityId, Attributes = new AttributeCollection { { "statecode", 0 } //0 = Active, anything else: Inactive } } }); var accountToUpdate = new Account() { Id = entityId, Name = "FC Barcelona", ["statecode"] = new OptionSetValue(1) }; service.Update(accountToUpdate); var updatedAccount = context.CreateQuery <Account>().FirstOrDefault(); Assert.Equal(1, (int)updatedAccount.StateCode.Value); }
public void Shouldnt_create_a_duplicate_phone_call_history_record() { var ctx = new XrmFakedContext(); var contact = new Contact() { Id = Guid.NewGuid() }; var phoneCall = new PhoneCall() { Id = Guid.NewGuid(), RegardingObjectId = contact.ToEntityReference(), PhoneNumber = "+34666666666" }; var existingPhoneCallHistory = new ultra_phonecallhistory() { Id = Guid.NewGuid(), ultra_contactid = contact.ToEntityReference(), ultra_phonenumber = phoneCall.PhoneNumber }; ctx.Initialize(existingPhoneCallHistory); ctx.ExecutePluginWithTarget <PhoneCallCreatePlugin>(phoneCall); var historyRecords = ctx.CreateQuery <ultra_phonecallhistory>().ToList(); Assert.Equal(1, historyRecords.Count); }
public void Check_if_Opportunity_was_created_after_sending_request() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var service = context.GetFakedOrganizationService(); var lead = new Lead() { Id = Guid.NewGuid() }; context.Initialize(new[] { lead }); var request = new QualifyLeadRequest() { CreateAccount = false, CreateContact = false, CreateOpportunity = true, LeadId = lead.ToEntityReference(), Status = new OptionSetValue((int)LeadState.Qualified) }; service.Execute(request); var opportunity = (from opp in context.CreateQuery <Opportunity>() where opp.OriginatingLeadId.Id == lead.Id select opp).First(); Assert.NotNull(opportunity); }
public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) { var req = request as WhoAmIRequest; var callerId = ctx.CallerId.Id; var results = new ParameterCollection { { "UserId", callerId } }; var user = ctx.CreateQuery("systemuser") .Where(u => u.Id == callerId) .SingleOrDefault(); if (user != null) { var buId = GetBusinessUnitId(user); results.Add("BusinessUnitId", buId); var orgId = GetOrganizationId(ctx, user, buId); results.Add("OrganizationId", orgId); } var response = new WhoAmIResponse { Results = results }; return(response); }
public void ExpectedNumberOfResultsNotReturnedNoneAreDeleted() { var expectedExceptionMessage = $"Could not safely delete results of query. " + $"Expected 2 but actual was 3"; var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { JohnContact, JamieContact, JacobContact, JamesContact // James isn't in London }); Assert.Throws(Is.TypeOf <OperationPreventedException>().And.Message.EqualTo(expectedExceptionMessage), () => SampleLondonContactsQueryByAttribute.DeleteAllResults(orgService, expectedResultsToDelete: 2) ); // Assert that nothing's been deleted var postContacts = (from a in context.CreateQuery <Contact>() where a.Address1_City == "London" select a).ToList(); Assert.AreEqual(3, postContacts.Count); }
public void ServiceEndPointDoeNotExist() { var manifestPath = $"{PluginManifestFolderPath}/plugin-manifest.xml"; var manifest = SerialisationWrapper.DeserialiseFromFile <PluginManifest>(manifestPath); var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); context.Initialize(new List <Entity>() { UpdateSdkMessage, UpdateContactMessageFilter, UpdateAccountMessageFilter }); var pluginWrapper = new PluginWrapper(); pluginWrapper.RegisterServiceEndpoints(manifest, orgService); var postRegisteredEndpoints = (from e in context.CreateQuery <ServiceEndpoint>() where e.Name == "TesterQueue" select e).ToList(); Assert.AreEqual(1, postRegisteredEndpoints.Count); Assert.IsNotNull(postRegisteredEndpoints[0].Id); }
public void TestWithoutSurveyId() { var context = new XrmFakedContext(); var surveyId = Guid.NewGuid(); var survey = new Entity("tc_surveyresponse", surveyId); survey["regardingobjectid"] = null; survey["statecode"] = new OptionSetValue(0); survey["statuscode"] = new OptionSetValue(1); context.Initialize(new List <Entity> { survey }); var cntxt = GetPluginContext(""); context.ExecutePluginWith <Tc.Crm.Plugins.Case.PostCaseCreationUpdateRegardingOfSurvey>(cntxt); var surveyUpdated = (from t in context.CreateQuery("tc_surveyresponse") where t.Id == surveyId select t).ToList(); Assert.IsTrue(surveyUpdated.Count == 1); var surveyUpdated1 = surveyUpdated[0]; Assert.IsNull(surveyUpdated1["regardingobjectid"]); Assert.AreEqual(((OptionSetValue)surveyUpdated1["statecode"]).Value, 0); Assert.AreEqual(((OptionSetValue)surveyUpdated1["statuscode"]).Value, 1); }
public void When_set_state_request_is_called_an_entity_is_updated() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var service = context.GetFakedOrganizationService(); var c = new Contact() { Id = Guid.NewGuid() }; context.Initialize(new[] { c }); var request = new SetStateRequest { EntityMoniker = c.ToEntityReference(), State = new OptionSetValue(69), Status = new OptionSetValue(6969), }; var response = service.Execute(request); //Retrieve record after update var contact = (from con in context.CreateQuery <Contact>() where con.Id == c.Id select con).FirstOrDefault(); Assert.Equal((int)contact.StateCode.Value, 69); Assert.Equal((int)contact.StatusCode.Value, 6969); }
public void InputFilterAttributesOnAnExistingStepShouldBeMergedAndUpdate() { var context = new XrmFakedContext(); var orgService = context.GetOrganizationService(); ExistingPluginStep.FilteringAttributes = "one,two,three,four"; context.Initialize(new List <Entity>() { ExistingContactPluginType, UpdateSdkMessage, UpdateContactMessageFilter, ExistingPluginStep }); UnitTestPluginStep.FilteringAttributes = new[] { "one", "two" }; UnitTestPluginStep.Register(orgService, ExistingContactPluginType.ToEntityReference(), UpdateSdkMessage.ToEntityReference(), UpdateContactMessageFilter.ToEntityReference()); var registeredStep = (from e in context.CreateQuery <SdkMessageProcessingStep>() where e.Name == UnitTestPluginStep.Name select e).ToList(); Assert.AreEqual(1, registeredStep.Count); Assert.AreEqual("one,two", registeredStep[0].FilteringAttributes); }
public void Should_set_a_statecode_by_default_when_an_entity_record_is_added_to_the_context() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var service = context.GetFakedOrganizationService(); var c = new Contact() { Id = Guid.NewGuid() }; context.Initialize(new[] { c }); //Retrieve record after update var contact = (from con in context.CreateQuery<Contact>() where con.Id == c.Id select con).FirstOrDefault(); Assert.Equal((int)contact.StateCode.Value, 0); //Active }
public void When_execute_is_called_all_requests_are_executed() { var context = new XrmFakedContext(); var executor = new ExecuteTransactionExecutor(); var req = new ExecuteTransactionRequest() { Requests = new OrganizationRequestCollection() { new CreateRequest() { Target = new Entity("contact") }, new CreateRequest() { Target = new Entity("contact") }, new CreateRequest() { Target = new Entity("contact") } } }; var response = executor.Execute(req, context) as ExecuteTransactionResponse; var contacts = context.CreateQuery("contact").ToList(); Assert.Equal(0, response.Responses.Count); Assert.Equal(3, contacts.Count); }
public void Should_not_override_a_statecode_already_initialized() { var context = new XrmFakedContext(); context.ProxyTypesAssembly = Assembly.GetExecutingAssembly(); var service = context.GetFakedOrganizationService(); var c = new Contact() { Id = Guid.NewGuid(), }; c["statecode"] = new OptionSetValue(69); //As the StateCode is read only in the early bound entity, this is the only way of updating it context.Initialize(new[] { c }); //Retrieve record after update var contact = (from con in context.CreateQuery<Contact>() where con.Id == c.Id select con).FirstOrDefault(); Assert.Equal((int)contact.StateCode.Value, 69); //Set }