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 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 PreCaseLinePlugin_CaseLineServiceTypeNotEqualToAccommodation() { context.CreateQueryFromEntityName(caseLineEntity.LogicalName).FirstOrDefault().Attributes["tc_servicetype"] = new OptionSetValue(950000001); var target = context.CreateQueryFromEntityName(caseLineEntity.LogicalName).FirstOrDefault(); var fakedPlugin = context.ExecutePluginWithTarget <Crm.Plugins.PreCaseLine>(target); var incident = context.CreateQueryFromEntityName(incidentEntity.LogicalName).FirstOrDefault(); Assert.IsTrue((incident.Attributes["tc_24hourpromise"] as OptionSetValue).Value != 950000000); Assert.IsTrue(context.GetFakeTracingService().DumpTrace().Contains(string.Format("Case Line Service Type is not equal to 'Accommodation'"))); context.CreateQueryFromEntityName(caseLineEntity.LogicalName).FirstOrDefault().Attributes["tc_servicetype"] = new OptionSetValue(950000000); }
public void CreateNoteWithAttachmentRegardingCaseNoDocumentLocationWithBaseDocumentLocation() { var context = new XrmFakedContext(); context.Initialize(new List <Entity>() { incidentEntity, sdlEntityBase }); var target = new Microsoft.Xrm.Sdk.Entity("annotation") { Id = annotationId, }; target.Attributes.Add("objectid", new EntityReference("incident", incidentId)); target.Attributes.Add("filename", "spam.txt"); var fakedPlugin = context.ExecutePluginWithTarget <Crm.Plugins.CreateSharePointDocumentLocation>(target); var documentLocations = (from t in context.CreateQuery("sharepointdocumentlocation") where t.Id != sdlEntityBase.Id select t) .ToList(); Assert.IsTrue(documentLocations.Count == 1); Assert.IsTrue(documentLocations[0].Attributes["relativeurl"].ToString() == "TC-XX-XXXX"); Assert.IsTrue(documentLocations[0].Attributes["name"].ToString() == "TC-XX-XXXX"); Assert.IsTrue((documentLocations[0].Attributes["parentsiteorlocation"] as EntityReference) .Id == sdlEntityBase.Id); Assert.IsTrue((documentLocations[0].Attributes["regardingobjectid"] as EntityReference) .Id == incidentId); }
/// <summary> /// Imitation of work through the UI /// </summary> /// <param name="context"></param> /// <param name="timeEntry"></param> private void PreOperationAndThenCreate(XrmFakedContext context, Entity timeEntry) { var plugin = new TimeEntryUniqueDatePlugin(); context.ExecutePluginWithTarget(plugin, timeEntry, "Create", 20); context.GetOrganizationService().Create(timeEntry); }
public void TestEncryptionPluginCreateUpdateContact(string targetType, int stage, bool isEncryptionExpected) { var context = new XrmFakedContext(); var target = new Entity("contact") { Id = Guid.NewGuid(), ["deb_idnumber"] = "123456", ["firstname"] = "Bob", // ["birthdate"] = new DateTime(1964,8,16), }; context.Initialize(target); var plugin = new CRM.Plugins.PIIEncryption("", _key); var pluginResult = context.ExecutePluginWithTarget(plugin, target, targetType, stage); if (isEncryptionExpected) { Assert.IsTrue(target.Attributes.ContainsKey("deb_idnumber_encrypted")); Assert.IsFalse(String.IsNullOrWhiteSpace(target.GetAttributeValue <string>("deb_idnumber_encrypted"))); Assert.AreEqual("******", target.GetAttributeValue <string>("deb_idnumber")); } else { Assert.IsFalse(target.Attributes.ContainsKey("deb_idnumber_encrypted")); Assert.AreEqual("123456", target.GetAttributeValue <string>("deb_idnumber")); } Assert.IsTrue(target.Attributes.ContainsKey("firstname")); Assert.AreEqual("Bob", target.GetAttributeValue <string>("firstname")); }
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 AllowOnlyOneEntity() { // Arrange var context = new XrmFakedContext() { ProxyTypesAssembly = Assembly.GetAssembly(typeof(scan_scantegrasettings)) }; var executionContext = context.GetDefaultPluginContext(); // Create a stub entity var existing = new scan_scantegrasettings { Id = Guid.NewGuid() }; context.Initialize(new List <scan_scantegrasettings>() { existing }); var target = new scan_scantegrasettings(); // Act Exception ex = Assert.Throws <InvalidPluginExecutionException>(() => context.ExecutePluginWithTarget <ScantegraSettingsPreCreate>(target)); // Assert Assert.Equal("Only one finance settings entity allowed", ex.Message); }
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 Error_Thrown_If_City_Is_Null() { // Create the fake context. This allows us to setup a mocked version of Dynamics for use later in the test XrmFakedContext context = new XrmFakedContext(); // Generate a GUID which will be assigned to the fake record. It is done here to allow the record to be retrieved // later during the test Guid accountGuid = Guid.NewGuid(); // Create an account record which has no address1_city filled in. This will be used during the plugin execution Entity account = new Entity("account") { Id = accountGuid, Attributes = { ["name"] = "Acme", ["address1_city"] = "", ["new_nameandcity"] = "" } }; // This will setup the context with the entities created. This is the set of entities we will be able to access // during the test. context.Initialize(new List <Entity> { account }); PreOperationaccountCreate plugin = new PreOperationaccountCreate("dev", null); // Execute the plugin. I have added the MessageName & stage as this plugin executes PreOperation context.ExecutePluginWithTarget(plugin, account, "Create", 20); // I am not asserting anything here as the plugin only needs to throw an exception. If no exception is thrown // then the unit test would fail }
public void WhenICreateANewAccount() { Entity account = new Entity("account"); account.Attributes["name"] = "Wael"; account["telephone1"] = "123456789"; ctx.ExecutePluginWithTarget <AccountPostCreate>(account); }
public void CreateNewContact() { var ctx = new XrmFakedContext(); var contact = new Entity("contact") { Id = Guid.NewGuid() }; ctx.ExecutePluginWithTarget <ContactPreOperation>(contact); }
public void CreateNewContact() { var ctx = new XrmFakedContext(); var contact = new Entity("contact") { Id = Guid.NewGuid() }; ContactPreOperation p = new ContactPreOperation("unsecure", "secure"); ctx.ExecutePluginWithTarget(p, contact); }
public void CreateNoteNoAttachment() { var context = new XrmFakedContext(); var target = new Microsoft.Xrm.Sdk.Entity("annotation") { Id = annotationId }; var fakedPlugin = context.ExecutePluginWithTarget <Crm.Plugins.CreateSharePointDocumentLocation>(target); var documentLocations = (from t in context.CreateQuery("sharepointdocumentlocation") select t).ToList(); Assert.IsTrue(documentLocations.Count == 0); }
public void CreateNoteWithAttachmentRegardingNull() { var context = new XrmFakedContext(); var target = new Microsoft.Xrm.Sdk.Entity("annotation") { Id = annotationId, }; target.Attributes.Add("filename", "spam.txt"); var fakedPlugin = context.ExecutePluginWithTarget <Crm.Plugins.CreateSharePointDocumentLocation>(target); var documentLocations = (from t in context.CreateQuery("sharepointdocumentlocation") select t).ToList(); Assert.IsTrue(documentLocations.Count == 0); }
public void When_the_account_number_plugin_is_executed_for_an_account_that_already_has_a_number_exception_is_thrown() { var fakedContext = new XrmFakedContext(); var guid1 = Guid.NewGuid(); var target = new Entity("account") { Id = guid1 }; target["accountnumber"] = 69; //Execute our plugin against a target thatcontains the accountnumber attribute will throw exception Assert.Throws <InvalidPluginExecutionException>(() => fakedContext.ExecutePluginWithTarget <AccountNumberPlugin>(target)); }
public void When_the_account_number_plugin_is_executed_it_adds_a_random_number_to_an_account_entity() { var fakedContext = new XrmFakedContext(); var guid1 = Guid.NewGuid(); var target = new Entity("account") { Id = guid1 }; //Execute our plugin against a target that doesn't contains the accountnumber attribute var fakedPlugin = fakedContext.ExecutePluginWithTarget <AccountNumberPlugin>(target); //Assert that the target contains a new attribute Assert.True(target.Attributes.ContainsKey("accountnumber")); }
public void When_a_plugin_with_target_is_executed_the_inherent_plugin_was_also_executed_without_exceptions() { var fakedContext = new XrmFakedContext(); var guid1 = Guid.NewGuid(); var target = new Entity("contact") { Id = guid1 }; //Execute our plugin against the selected target var fakedPlugin = fakedContext.ExecutePluginWithTarget <RetrieveServicesPlugin>(target); //Assert that the plugin was executed A.CallTo(() => fakedPlugin.Execute(A <IServiceProvider> ._)) .MustHaveHappened(); }
public void DataDublicationIsNotAllowedTest() { XrmFakedContext context = new XrmFakedContext(); var plugin = new TimeEntryUniqueDatePlugin(); Guid resourseId = Guid.NewGuid(); DateTime startDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan duration = TimeSpan.FromDays(1); context.Initialize(new List <Entity> { EntityFactory.CreateTimeEntry(startDate, TimeSpan.FromHours(2), resourseId), EntityFactory.CreateTimeEntry(startDate.AddDays(1), TimeSpan.FromHours(2), resourseId) }); var timeEntry = EntityFactory.CreateTimeEntry(startDate, duration, resourseId); Assert.ThrowsException <InvalidPluginExecutionException>(() => context.ExecutePluginWithTarget(plugin, timeEntry, "Create", 20), "Duplicates creation is canceled"); }
public void CreateNoteWithAttachmentRegardingCaseNoDocumentLocationNoBaseDocumentLocation() { var context = new XrmFakedContext(); context.Initialize(new List <Entity>() { incidentEntity }); var target = new Microsoft.Xrm.Sdk.Entity("annotation") { Id = annotationId, }; target.Attributes.Add("objectid", new EntityReference("incident", incidentId)); target.Attributes.Add("filename", "spam.txt"); Assert.ThrowsException <InvalidPluginExecutionException>(() => context.ExecutePluginWithTarget <Crm.Plugins.CreateSharePointDocumentLocation>(target)); }
public void Example_about_retrieving_traces_written_by_plugin() { var fakedContext = new XrmFakedContext(); var guid1 = Guid.NewGuid(); var target = new Entity("account") { Id = guid1 }; //Execute our plugin against a target that doesn't contains the accountnumber attribute var fakedPlugin = fakedContext.ExecutePluginWithTarget <AccountNumberPlugin>(target); //Get tracing service var fakeTracingService = fakedContext.GetFakeTracingService(); var log = fakeTracingService.DumpTrace(); //Assert that the target contains a new attribute Assert.Equal(log, "Contains target\r\nIs Account\r\n"); }
public void translated_fields_should_contain_data() { // Arrange var context = new XrmFakedContext(); var metadata = GetMockedMultiLanguageMetadata(); context.InitializeMetadata(metadata); var theme = new opc_theme { opc_islocalizable = true, opc_nameenglish = "Technology", opc_namefrench = "Technologie" }; // Act context.ExecutePluginWithTarget <MultiLanguagePlugin>(theme); // Assert var expected = $"{Prefix}{string.Join(Separator, new[] { theme.opc_nameenglish, theme.opc_namefrench })}"; theme.opc_name.Should().Be(expected); }
public void When_the_followup_plugin_is_executed_for_an_account_it_should_create_a_new_task() { 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 }; fakedContext.ExecutePluginWithTarget <FollowupPlugin>(target); //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.")); }
public void AccountPostCreateTest() { var fakedContext = new XrmFakedContext(); Entity account = new Entity("account"); account.Attributes.Add("name", "ABC Ltd"); account.Id = Guid.NewGuid(); var fakedService = fakedContext.GetOrganizationService(); fakedContext.ExecutePluginWithTarget <AccountPostCreate>(account, "Create", 40); // Retrive the task record QueryExpression query = new QueryExpression("task"); query.ColumnSet.AddColumn("subject"); EntityCollection collection = fakedService.RetrieveMultiple(query); Assert.IsTrue(collection.Entities.Count == 1); }
public void DuplicteTest() { var fakedContext = new XrmFakedContext(); Entity existingcontact = new Entity("contact"); //contact.Id = Guid.NewGuid(); existingcontact.Attributes.Add("emailaddress1", "*****@*****.**"); IOrganizationService fakedService = fakedContext.GetOrganizationService(); fakedService.Create(existingcontact); Entity newcontact = new Entity("contact"); //contact.Id = Guid.NewGuid(); newcontact.Attributes.Add("emailaddress1", "*****@*****.**"); Assert.ThrowsException <InvalidPluginExecutionException>(() => fakedContext.ExecutePluginWithTarget <ContactDuplicateCheck>(newcontact, "Create", 10), "Failed"); }
public void CreateNoteWithAttachmentRegardingCaseWithExistingDocumentLocation() { var context = new XrmFakedContext(); context.Initialize(new List <Entity> { sdlEntity }); var target = new Microsoft.Xrm.Sdk.Entity("annotation") { Id = annotationId, }; target.Attributes.Add("objectid", new EntityReference("incident", incidentId)); target.Attributes.Add("filename", "spam.txt"); var fakedPlugin = context.ExecutePluginWithTarget <Crm.Plugins.CreateSharePointDocumentLocation>(target); var documentLocations = (from t in context.CreateQuery("sharepointdocumentlocation") where t.Id != sdlEntity.Id select t) .ToList(); Assert.IsTrue(documentLocations.Count == 0); }
public void Field_Updated_When_Account_Created() { // Create the fake context. This allows us to setup a mocked version of Dynamics for use later in the test XrmFakedContext context = new XrmFakedContext(); // Generate a GUID which will be assigned to the fake record. It is done here to allow the record to be retrieved // later during the test Guid accountGuid = Guid.NewGuid(); // Create the entity record which will be the target. In this case I have set the name & address1_city // field to have a value, and assigned the new_nameandcity field to have no value Entity account = new Entity("account") { Id = accountGuid, Attributes = { ["name"] = "Acme", ["address1_city"] = "America", ["new_nameandcity"] = "" } }; // This will setup the context with the entities created. This is the set of entities we will be able to access // during the test. context.Initialize(new List <Entity> { account }); PreOperationaccountCreate plugin = new PreOperationaccountCreate("dev", null); // Execute the plugin. I have added the MessageName & stage as this plugin executes PreOperation context.ExecutePluginWithTarget(plugin, account, "Create", 20); // Retrieve the update account from the fake context Entity updatedAccount = context.GetOrganizationService() .Retrieve("account", accountGuid, new ColumnSet(new string[] { "new_nameandcity" })); // Assert that the value meets our expected value Assert.AreEqual("Acme - America", updatedAccount.GetAttributeValue <string>("new_nameandcity")); }
public void Should_create_phone_call_history_on_create_of_a_phonecall_with_its_details() { //var ctx = new XrmFakedContext(); //Assert.True(false); //Arrange ==> //Act //Assert ==> var ctx = new XrmFakedContext(); var service = ctx.GetOrganizationService(); 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.Single(historyRecords); 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 TestEncryptionPluginCreateUpdateAnnotation(string targetType, int stage, string filename, bool isEncryptionExpected) { var context = new XrmFakedContext(); var target = new Entity("annotation") { Id = Guid.NewGuid(), ["deb_idnumber"] = "123456", ["documentbody"] = "This is the document body and it isn't very long", ["filename"] = filename, }; context.Initialize(target); var original = target.Clone(); var plugin = new CRM.Plugins.PIIEncryption("", _key); var pluginResult = context.ExecutePluginWithTarget(plugin, target, targetType, stage); if (isEncryptionExpected) { Assert.AreNotEqual(original.GetAttributeValue <string>("documentbody"), target.GetAttributeValue <string>("documentbody")); } else { Assert.AreEqual(original.GetAttributeValue <string>("documentbody"), target.GetAttributeValue <string>("documentbody")); } Assert.IsFalse(target.Attributes.ContainsKey("documentbody_encrypted")); Assert.AreEqual("123456", target.GetAttributeValue <string>("deb_idnumber")); Assert.IsFalse(target.Attributes.ContainsKey("deb_idnumber_encrypted")); Assert.IsTrue(target.Attributes.ContainsKey("filename")); Assert.AreEqual(filename, target.GetAttributeValue <string>("filename")); }
public void CreatePhonecall() { //Setup var ctx = new XrmFakedContext(); var contact = new Entity("contact") { Id = Guid.NewGuid() }; ContactPostCreateAsync p = new ContactPostCreateAsync(); //Act ctx.ExecutePluginWithTarget(p, contact); //Verify var calls = ctx.CreateQuery("phonecall").ToList <Entity>(); Assert.AreEqual(calls.Count, 1); EntityReference regarding = (EntityReference)(calls[0]["regardingobjectid"]); Assert.AreEqual(regarding.Id, contact.Id); //Clean Up }