public void It_Should_Send_Organization_Service_Update_If_Value_Identical_And_Force_Flag_Set() { var context = new XrmFakedContext(); var service = context.GetFakedOrganizationService(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "subject", "Demo" }, { "description", "Hello Demo" } } }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"", ""triggerUpdate"": true, ""forceUpdate"": true }"; context.Initialize(email); context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty); email = service.Retrieve(email.LogicalName, email.Id, new ColumnSet(true)); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo("Hello Demo")); A.CallTo(() => service.Update(A <Entity> ._)).MustHaveHappened(Repeated.Exactly.Once); }
public void It_Should_Proceed_If_Execution_Criteria_Set_And_Matches() { var context = new XrmFakedContext(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "subject", "Demo" }, { "description", "Hello ${{Value(\"subject\")}}" } } }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"", ""executionCriteria"": ""Not(IsNull(Value(\""subject\"")))"" }"; context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo("Hello Demo")); }
public void It_Should_Send_Organization_Service_Update_With_Trigger_Update_Flag() { var context = new XrmFakedContext(); var service = context.GetFakedOrganizationService(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "subject", "Demo" }, { "description", "Hello ${{Value(\"subject\")}}" } } }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"", ""triggerUpdate"": true }"; context.Initialize(email); context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty); email = service.Retrieve(email.LogicalName, email.Id, new ColumnSet(true)); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo("Hello Demo")); }
public void ActionTraceTest() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext(); Guid userId = Guid.Parse("9e7ec57b-3a08-4a41-a4d4-354d66f19b65"); xrmFakedPluginExecution.InitiatingUserId = userId; xrmFakedPluginExecution.UserId = userId; xrmFakedPluginExecution.CorrelationId = Guid.Parse("15cc775b-9ebc-48d1-93a6-b0ce9c920b66"); xrmFakedPluginExecution.MessageName = "Update"; xrmFakedPluginExecution.Mode = 1; xrmFakedPluginExecution.Depth = 1; xrmFakedPluginExecution.OrganizationName = "test.crm.dynamics.com"; xrmFakedPluginExecution.Stage = 40; xrmFakedPluginExecution.OperationCreatedOn = DateTime.Now; xrmFakedPluginExecution.InputParameters = GetInputParameters(); xrmFakedPluginExecution.OutputParameters = new ParameterCollection(); context.ExecutePluginWithConfigurations <LogTrace>(xrmFakedPluginExecution, unsecureConfig, null); Assert.IsTrue((bool)xrmFakedPluginExecution.OutputParameters["logsuccess"]); }
public void It_Should_Preserve_Whitespace() { var context = new XrmFakedContext(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "name", "Demo" }, { "description", "Hi Tester,\n\n${{\nValue(\"name\")}}" } } }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"" }"; context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo("Hi Tester,\n\nDemo")); }
public void It_Should_Not_Throw_But_Replace_By_Empty_String_On_Error() { var context = new XrmFakedContext(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "subject", "Demo" }, { "description", "Hello ${{Text \"subject\"}} ${{Value(\"subject\")}}" } } }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"" }"; Assert.That(() => context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty), Throws.Nothing); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo("Hello Demo")); }
public void When_A_Plugin_Is_Executed_Configurations_Can_Be_Used() { var fakedContext = new XrmFakedContext(); var guid1 = Guid.NewGuid(); var target = new Entity("contact") { Id = guid1 }; var inputParams = new ParameterCollection { new KeyValuePair <string, object>("Target", target) }; var unsecureConfiguration = "Unsecure Configuration"; var secureConfiguration = "Secure Configuration"; //Execute our plugin against the selected target var plugCtx = fakedContext.GetDefaultPluginContext(); plugCtx.InputParameters = inputParams; fakedContext.ExecutePluginWithConfigurations <ConfigurationPlugin>(plugCtx, unsecureConfiguration, secureConfiguration); Assert.True(target.Contains("unsecure")); Assert.True(target.Contains("secure")); Assert.Equal((string)target["unsecure"], unsecureConfiguration); Assert.Equal((string)target["secure"], secureConfiguration); }
public void It_Should_Fail_If_No_Template_Passed() { var context = new XrmFakedContext(); var contact = new Entity { Id = Guid.NewGuid(), LogicalName = "contact", Attributes = { { "firstname", "Frodo" } } }; context.Initialize(new Entity[] { contact }); var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", contact } }; var config = @"{ ""targetField"": ""description"" }"; Assert.That(() => context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty), Throws.Exception.With.Message.EqualTo("Both template and template field were null, please set one of them in the unsecure config!")); }
public void It_Should_Not_Create_Notification_If_Xtl_Condition_False() { var context = new XrmFakedContext(); var service = context.GetOrganizationService(); var userId = Guid.NewGuid(); var incident = new Entity { LogicalName = "incident", Id = Guid.NewGuid(), ["description"] = "NaNaNaNaNaNaNaNa Batman", ["test"] = "This should be filtered out", ["oss_condition"] = 0 }; var subscription = new Entity { LogicalName = "oss_subscription", Id = Guid.NewGuid(), ["oss_incidentid"] = incident.ToEntityReference(), ["statecode"] = new OptionSetValue(0), ["ownerid"] = new EntityReference("systemuser", userId) }; context.Initialize(new Entity[] { incident, subscription }); var pluginCtx = context.GetDefaultPluginContext(); pluginCtx.UserId = userId; pluginCtx.InputParameters = new ParameterCollection { ["Target"] = incident }; pluginCtx.MessageName = "Update"; var config = new CreateNotificationConfig { CapturedFields = new List <string> { "description" }, NotificationLookupName = "oss_incidentid", NotifyCurrentUser = true, SubscriptionLookupName = "oss_incidentid", XtlCondition = "IsEqual(Value('oss_condition'), 1)" }; Assert.That(() => context.ExecutePluginWithConfigurations <CreateNotification>(pluginCtx, JsonSerializer.Serialize(config), string.Empty), Throws.Nothing); Assert.That(context.Data, !Contains.Key("oss_notification")); }
public void TestMethod1() { var contactId = Guid.NewGuid(); var fakedContext = new XrmFakedContext(); //setup ctx to look like an update of parentcustomerid on the contact var plugCtx = fakedContext.GetDefaultPluginContext(); plugCtx.MessageName = "Create"; plugCtx.PrimaryEntityName = "contact"; plugCtx.Stage = 20; plugCtx.PrimaryEntityId = contactId; plugCtx.InputParameters["Target"] = new Entity { Id = contactId, LogicalName = "contact" }; fakedContext.ExecutePluginWithConfigurations <InstrumentedPlugin>(plugCtx, null, null); }
public void ActionEvent_Null_Measurement_Value_Test() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext { InputParameters = GetInputParameters() }; xrmFakedPluginExecution.InputParameters["measurementvalue"] = null; xrmFakedPluginExecution.OutputParameters = new ParameterCollection(); context.ExecutePluginWithConfigurations <LogEvent>(xrmFakedPluginExecution, unsecureConfig, null); }
public void Should_post_plugin_context_to_service_endpoint() { var endpointId = Guid.NewGuid(); var fakedContext = new XrmFakedContext(); var fakedServiceEndpointNotificationService = fakedContext.GetFakedServiceEndpointNotificationService(); A.CallTo(() => fakedServiceEndpointNotificationService.Execute(A <EntityReference> ._, A <IExecutionContext> ._)) .Returns("response"); var plugCtx = fakedContext.GetDefaultPluginContext(); var fakedPlugin = fakedContext .ExecutePluginWithConfigurations <ServiceEndpointNotificationPlugin>(plugCtx, endpointId.ToString(), null); A.CallTo(() => fakedServiceEndpointNotificationService.Execute(A <EntityReference> ._, A <IExecutionContext> ._)) .MustHaveHappened(); }
public void My_First_Test() { var context = new XrmFakedContext(); var account = new Entity("account"); account["name"] = "Hello World"; account["address1_postcode"] = "1234"; ParameterCollection inputParameters = new ParameterCollection(); inputParameters.Add("Target", account); var pluginCtx = context.GetDefaultPluginContext(); pluginCtx.Stage = 20; pluginCtx.MessageName = "Create"; pluginCtx.InputParameters = inputParameters; Assert.DoesNotThrow(() => context.ExecutePluginWithConfigurations <AccountSetTerritories>(pluginCtx, null, null)); }
public void It_Should_Not_Fail_On_Empty_Valued_Template_Field() { var context = new XrmFakedContext(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email" }; context.Initialize(new Entity[] { email }); var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"" }"; Assert.That(() => context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty), Throws.Nothing); }
public void ActionTrace_Null_Severity_Test() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext { InputParameters = GetInputParameters() }; xrmFakedPluginExecution.InputParameters["severity"] = null; xrmFakedPluginExecution.OutputParameters = new ParameterCollection(); context.ExecutePluginWithConfigurations <LogTrace>(xrmFakedPluginExecution, unsecureConfig, null); Assert.IsFalse((bool)xrmFakedPluginExecution.OutputParameters["logsuccess"]); Assert.IsTrue(xrmFakedPluginExecution.OutputParameters["errormessage"].ToString() == "Severity cannot be null"); }
public void It_Should_Allow_Expressions_Inside_Template_Fields() { var context = new XrmFakedContext(); var account = new Entity { Id = Guid.NewGuid(), LogicalName = "account", Attributes = { { "oss_template", "AccountTemplate - ${{Value(\"firstname\")}}" } } }; var contact = new Entity { Id = Guid.NewGuid(), LogicalName = "contact", Attributes = { { "firstname", "Frodo" }, { "parentcustomerid", account.ToEntityReference() } } }; context.Initialize(new Entity[] { account, contact }); var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", contact } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""Value(\""parentcustomerid.oss_template\"")"" }"; context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty); Assert.That(contact.GetAttributeValue <string>("description"), Is.EqualTo("AccountTemplate - Frodo")); }
public void TestApplicationInsightsTrackCustomEvent() { string unsecureConfig = @"<Settings><setting name=""instrumentationKey""><value>" + _instrumentationKey + "</value></setting></Settings>"; string secureConfig = null; var fakedContext = new XrmFakedContext(); var wfContext = fakedContext.GetDefaultPluginContext(); wfContext.MessageName = "Create"; wfContext.Stage = 40; wfContext.CorrelationId = new Guid("b374239d-4233-41a9-8b17-a86cb4f737b5"); Entity accountEntity = new Entity(); accountEntity.Attributes = new AttributeCollection(); accountEntity.Attributes.Add(new KeyValuePair <string, object>("branch", "Some Branch")); accountEntity.Attributes.Add(new KeyValuePair <string, object>("parentaccountid", new EntityReference("parentaccount", null))); //((EntityReference)accountEntity.Attributes["parentaccountid"]).Id = null; wfContext.InputParameters = new ParameterCollection(); wfContext.InputParameters.Add(new KeyValuePair <string, object>("Target", accountEntity)); var result = fakedContext.ExecutePluginWithConfigurations <ApplicationInsightsTrackCustomEvent>(wfContext, unsecureConfig, secureConfig); }
public void ActionTrace_Invalid_Severity_Test() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext { InputParameters = GetInputParameters() }; xrmFakedPluginExecution.InputParameters["severity"] = "test"; xrmFakedPluginExecution.OutputParameters = new ParameterCollection(); context.ExecutePluginWithConfigurations <LogTrace>(xrmFakedPluginExecution, unsecureConfig, null); Assert.IsFalse((bool)xrmFakedPluginExecution.OutputParameters["logsuccess"]); Assert.IsTrue(xrmFakedPluginExecution.OutputParameters["errormessage"].ToString() == "Invalid Severity: valid values: Verbose, Information, Warning, Error, Critical"); }
public void ActionMetric_Measurement_Missing_Value_Test() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext { InputParameters = GetInputParameters() }; xrmFakedPluginExecution.InputParameters.Remove("value"); xrmFakedPluginExecution.OutputParameters = new ParameterCollection(); context.ExecutePluginWithConfigurations <LogMetric>(xrmFakedPluginExecution, unsecureConfig, null); Assert.IsFalse((bool)xrmFakedPluginExecution.OutputParameters["logsuccess"]); Assert.IsTrue(xrmFakedPluginExecution.OutputParameters["errormessage"].ToString() == "Value must be populated"); }
public void ActionEvent_Invalid_Measurement_Name_Test() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext { InputParameters = GetInputParameters() }; xrmFakedPluginExecution.InputParameters["measurementname"] = "sisznxevfkzibsdtsvfwijucumzedrzauyzzyzqmrrmdwwdqugtiprgvgkmpokcoldnxcmlwywcuernvoobnfogzgjkbnsteycrvafpharlnylyvyigsnskjuwwqjeiudwkibztwzwwotfbaijxcqwwk"; xrmFakedPluginExecution.OutputParameters = new ParameterCollection(); context.ExecutePluginWithConfigurations <LogEvent>(xrmFakedPluginExecution, unsecureConfig, null); Assert.IsFalse((bool)xrmFakedPluginExecution.OutputParameters["logsuccess"]); Assert.IsTrue(xrmFakedPluginExecution.OutputParameters["errormessage"].ToString() == "Invalid Measurement: name cannot exceed 150 characters"); }
public void It_Should_Parse_Organization_Config() { var context = new XrmFakedContext(); var contact = new Entity { LogicalName = "contact", Id = Guid.NewGuid() }; var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "subject", "Demo" }, { "description", "Hello ${{RecordUrl(Value(\"regardingobjectid\"))}}" }, { "regardingobjectid", contact.ToEntityReference() } } }; context.Initialize(new[] { contact, email }); var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"" }"; var orgConfig = @"{ ""organizationUrl"": ""https://someUrl/"" }"; context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, orgConfig); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo($"Hello <a href=\"https://someUrl/main.aspx?etn={contact.LogicalName}&id={contact.Id}&newWindow=true&pagetype=entityrecord\">https://someUrl/main.aspx?etn={contact.LogicalName}&id={contact.Id}&newWindow=true&pagetype=entityrecord</a>")); }
public void IServiceProvider_should_has_IEntityDataSourceRetrieverService_in_v9() { var context = new XrmFakedContext(); context.EntityDataSourceRetriever = new Entity("abc_customdatasource") { ["abc_crmurl"] = "https://...", ["abc_username"] = "******", ["abc_password"] = "******" }; var pluginContext = context.GetDefaultPluginContext(); var entity = new Entity(); var query = new QueryExpression(); pluginContext.InputParameters["Query"] = query; context.ExecutePluginWithConfigurations <RetrieveMultipleDataProvider>(pluginContext, null, null); var outputParameters = pluginContext.OutputParameters["BusinessEntityCollection"] as EntityCollection; Assert.Equal(2, outputParameters.Entities.Count); Assert.Equal("abc_dataprovider", outputParameters.EntityName); }
// ReSharper disable once InconsistentNaming public void When_AccountNameIsNotShort_Expect_PluginNotToFail() { var ctx = new XrmFakedContext { ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)) }; const string AccountName = "AAAA"; var target = new Account { Name = AccountName }; var pluginCtx = new CreatePreValidationSyncBase(ctx) { TargetEntity = target }; var exc = Record.Exception( () => ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Account.Create>( pluginCtx, string.Empty, string.Empty)); Assert.Null(exc); }
public void It_Should_Retrieve_Values_From_Preimages() { var context = new XrmFakedContext(); var email = new Entity { Id = Guid.NewGuid(), LogicalName = "email", Attributes = { { "description", "Hello ${{Value(\"subject\")}}" } } }; var pluginContext = context.GetDefaultPluginContext(); pluginContext.InputParameters = new ParameterCollection { { "Target", email } }; pluginContext.PreEntityImages = new EntityImageCollection { { "preimg", new Entity { Attributes = { { "subject", "Demo Pre" } } } } }; var config = @"{ ""targetField"": ""description"", ""templateField"": ""description"" }"; context.ExecutePluginWithConfigurations <XTLProcessor>(pluginContext, config, string.Empty); Assert.That(email.GetAttributeValue <string>("description"), Is.EqualTo("Hello Demo Pre")); }
public void When_A_Plugin_Is_Executed_With_Configurations_And_Instance_That_one_is_executed() { var fakedContext = new XrmFakedContext(); var guid1 = Guid.NewGuid(); var target = new Entity("contact") { Id = guid1 }; var inputParams = new ParameterCollection { new KeyValuePair <string, object>("Target", target) }; var unsecureConfiguration = "Unsecure Configuration"; var secureConfiguration = "Secure Configuration"; //Execute our plugin against the selected target var plugCtx = fakedContext.GetDefaultPluginContext(); plugCtx.InputParameters = inputParams; Assert.Throws <ArgumentException>(() => fakedContext.ExecutePluginWithConfigurations <FollowupPlugin>(plugCtx, unsecureConfiguration, secureConfiguration)); }
public void ActionMetric_Aggregate_Test() { AiSetup aiSetup = Configs.GetAiSetup(false, false, false, false, false, false, true); string unsecureConfig = SerializationHelper.SerializeObject <AiSetup>(aiSetup); XrmFakedContext context = new XrmFakedContext(); XrmFakedPluginExecutionContext xrmFakedPluginExecution = new XrmFakedPluginExecutionContext(); Guid userId = Guid.Parse("9e7ec57b-3a08-4a41-a4d4-354d66f19b65"); xrmFakedPluginExecution.InitiatingUserId = userId; xrmFakedPluginExecution.UserId = userId; xrmFakedPluginExecution.CorrelationId = Guid.Parse("15cc775b-9ebc-48d1-93a6-b0ce9c920b66"); xrmFakedPluginExecution.MessageName = "update"; xrmFakedPluginExecution.Mode = 1; xrmFakedPluginExecution.Depth = 1; xrmFakedPluginExecution.OrganizationName = "test.crm.dynamics.com"; xrmFakedPluginExecution.Stage = 40; xrmFakedPluginExecution.OperationCreatedOn = DateTime.Now; xrmFakedPluginExecution.InputParameters = GetInputParameters(); xrmFakedPluginExecution.OutputParameters = new ParameterCollection { new KeyValuePair <string, object>("name", "Hello from MetricTest - 1"), new KeyValuePair <string, object>("value", 34), new KeyValuePair <string, object>("count", 1), new KeyValuePair <string, object>("min", 34), new KeyValuePair <string, object>("max", 34), new KeyValuePair <string, object>("stddev", 0) }; context.ExecutePluginWithConfigurations <LogMetric>(xrmFakedPluginExecution, unsecureConfig, null); Assert.IsTrue((bool)xrmFakedPluginExecution.OutputParameters["logsuccess"]); }
// ReSharper disable once InconsistentNaming public void When_AccountNameIsTooShort_Expect_PluginToFail() { var ctx = new XrmFakedContext { ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account)) }; const string AccountName = "AAA"; var target = new Account { Name = AccountName }; var pluginCtx = new CreatePreValidationSyncBase(ctx) { TargetEntity = target }; var exc = Assert.Throws <InvalidPluginExecutionException>( () => ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Account.Create>( pluginCtx, string.Empty, string.Empty)); var message = $"Account name \"{AccountName}\" is incorrect. It should contain at least 4 characters."; Assert.Equal(message, exc.Message); }
public void It_Should_Create_Notification_On_Parent_On_Child_Create() { var context = new XrmFakedContext(); var service = context.GetOrganizationService(); var userId = Guid.NewGuid(); var incident = new Entity { LogicalName = "incident", Id = Guid.NewGuid(), ["description"] = "NaNaNaNaNaNaNaNa Batman", ["test"] = "This should be filtered out" }; var subscription = new Entity { LogicalName = "oss_subscription", Id = Guid.NewGuid(), ["oss_incidentid"] = incident.ToEntityReference(), ["statecode"] = new OptionSetValue(0), ["ownerid"] = new EntityReference("systemuser", userId) }; var task = new Entity { LogicalName = "task", Id = Guid.NewGuid(), ["title"] = "Test", ["regardingobjectid"] = incident.ToEntityReference() }; context.Initialize(new Entity[] { incident, subscription, task }); var pluginCtx = context.GetDefaultPluginContext(); pluginCtx.UserId = userId; pluginCtx.InputParameters = new ParameterCollection { ["Target"] = task }; pluginCtx.MessageName = "Create"; var config = new CreateNotificationConfig { CapturedFields = new List <string> { "title" }, NotificationLookupName = "oss_incidentid", NotifyCurrentUser = true, SubscriptionLookupName = "oss_incidentid", ParentLookupName = "regardingobjectid" }; Assert.That(() => context.ExecutePluginWithConfigurations <CreateNotification>(pluginCtx, JsonSerializer.Serialize(config), string.Empty), Throws.Nothing); Assert.That(context.Data, Contains.Key("oss_notification")); var notification = context.Data["oss_notification"].First().Value; Assert.That(notification.GetAttributeValue <EntityReference>("ownerid")?.Id, Is.EqualTo(userId)); Assert.That(notification.GetAttributeValue <EntityReference>("oss_incidentid"), Is.EqualTo(incident.ToEntityReference())); var data = JsonDeserializer.Parse <EventData>(notification.GetAttributeValue <string>("oss_data")); Assert.That(data.EventRecordReference, Is.EqualTo(task.ToEntityReference())); Assert.That(data.UpdatedFields, Is.EquivalentTo(new List <string> { "title" })); }
public void CheckForInvalidMessage() { var cntxt = GetPluginContext(sourceMarketId, Messages.Associate, (int)PluginStage.Postoperation, (int)PluginMode.Asynchronous); context.ExecutePluginWithConfigurations <Tc.Crm.Plugins.Customer.CreateEntityCacheOnCustomerOperation>(cntxt, null, null); Assert.IsTrue(context.Data.Count == 1); }