public void When_OrganizationName_Set()
        {
            var fakedContext = new XrmFakedContext();
            var pluginCtx    = fakedContext.GetDefaultPluginContext();

            pluginCtx.OutputParameters = new ParameterCollection();
            pluginCtx.OrganizationName = "TestOrgName";
            fakedContext.ExecutePluginWith <TestContextOrgNamePlugin>(pluginCtx);

            Assert.True(pluginCtx.OutputParameters.ContainsKey("OrgName"));
            Assert.Equal("TestOrgName", pluginCtx.OutputParameters["OrgName"]);
        }
        public void When_getting_a_default_context_shared_variables_can_be_accessed_from_a_plugin()
        {
            var context = new XrmFakedContext();

            var pluginContext = context.GetDefaultPluginContext();

            pluginContext.SharedVariables.Add("key", "somevalue");

            var ex = Record.Exception(() => context.ExecutePluginWith <TestSharedVariablesPropertyPlugin>(pluginContext));

            Assert.Null(ex);
        }
示例#3
0
        public void _02_Check_PrimaryEntityName()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PostOperation;
            plugin.PrimaryEntityName = "abcd";
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PostAccountdevkit_SendEmailSynchronous>(plugin);
            }, $"PrimaryEntityName does not equals {PrimaryEntityName}");
        }
示例#4
0
        public void _02_Check_PrimaryEntityName()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PreValidation;
            plugin.PrimaryEntityName = "abcd";
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PreValidationPhoneCallDeleteSynchronous>(plugin);
            }, $"PrimaryEntityName does not equals {PrimaryEntityName}");
        }
示例#5
0
        public void PostAccountUpdateAsynchronousTest_PrimaryEntityName_Does_Not_Equals_account()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PostOperation;
            plugin.PrimaryEntityName = "abcd";
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PostAccountUpdateAsynchronous>(plugin);
            }, "PrimaryEntityName does not equals account");
        }
示例#6
0
        public void When_Passing_In_No_Properties_Plugins_Only_Get_Default_Values()
        {
            var context = new XrmFakedContext();

            ParameterCollection inputParameters = new ParameterCollection();

            inputParameters.Add("Target", new Entity());

            var pluginContext = new XrmFakedPluginExecutionContext()
            {
                InputParameters  = inputParameters,
                UserId           = Guid.NewGuid(),
                InitiatingUserId = Guid.NewGuid()
            };

            //Parameters are defaulted now...
            var ex = Record.Exception(() => context.ExecutePluginWith <TestContextPlugin>(pluginContext));

            Assert.Null(ex);

            pluginContext = new XrmFakedPluginExecutionContext()
            {
                InputParameters  = inputParameters,
                MessageName      = "Create",
                InitiatingUserId = Guid.NewGuid()
            };

            ex = Record.Exception(() => context.ExecutePluginWith <TestContextPlugin>(pluginContext));
            Assert.Null(ex);

            pluginContext = new XrmFakedPluginExecutionContext()
            {
                InputParameters = inputParameters,
                MessageName     = "Update",
                UserId          = Guid.NewGuid()
            };

            ex = Record.Exception(() => context.ExecutePluginWith <TestContextPlugin>(pluginContext));
            Assert.Null(ex);
        }
        public void PreOperationOneParentTwoChild()
        {
            // Arrange
            var fakedContext = new XrmFakedContext();
            var parentEntity = new Entity("new_parententity")
            {
                Id           = Guid.NewGuid(),
                ["new_name"] = "First Parent"
            };


            var childEntityFirst = new Entity("new_childentity")
            {
                Id                   = Guid.NewGuid(),
                ["new_name"]         = "First Child",
                ["new_parententity"] = parentEntity.ToEntityReference()
            };


            var childEntitySecond = new Entity("new_childentity")
            {
                Id                   = Guid.NewGuid(),
                ["new_name"]         = "Second Child",
                ["new_parententity"] = parentEntity.ToEntityReference()
            };


            fakedContext.Initialize(new List <Entity>
            {
                parentEntity,
                childEntityFirst,
                childEntitySecond
            });

            var inputParameters = new ParameterCollection();

            inputParameters.Add("Target", parentEntity.ToEntityReference());

            var plugCtx = fakedContext.GetDefaultPluginContext();

            plugCtx.MessageName     = "Delete";
            plugCtx.Stage           = 10;
            plugCtx.InputParameters = inputParameters;
            plugCtx.Depth           = 1;

            // Act
            fakedContext.ExecutePluginWith <Plugin.DeleteParentThenChildPlugin>(plugCtx);

            // Assert
            Assert.NotNull(plugCtx.SharedVariables["toDelete"]);
            Assert.That(((EntityCollection)plugCtx.SharedVariables["toDelete"]).Entities, Has.Count.EqualTo(2));
        }
示例#8
0
        public void TestEncryptionPluginRetrieveContactCols(bool mayDecrypt)
        {
            var context     = new XrmFakedContext();
            var stage       = 20; // pre-operation¬
            var messageName = "Retrieve";
            var userId      = Guid.NewGuid();

            var target = new Entity("contact")
            {
                Id = Guid.NewGuid(),
                ["deb_idnumber"] = "******",
                ["firstname"]    = "Bob",
                ["birthdate"]    = new DateTime(1900, 1, 1),
            };
            var mayDecryptTargets = fakedUser(userId, mayDecrypt);

            mayDecryptTargets.Add(target);
            context.Initialize(mayDecryptTargets);
            var defaultPluginContext = context.GetDefaultPluginContext();

            defaultPluginContext.InputParameters.Add("Target", target.ToEntityReference());
            var colset = new ColumnSet((from k in target.Attributes where k.Key != "Id" select k.Key).ToArray());

            defaultPluginContext.InputParameters.Add("ColumnSet", colset);
            defaultPluginContext.OutputParameters.Add("BusinessEntity", target);
            defaultPluginContext.MessageName = messageName;
            defaultPluginContext.UserId      = userId;
            defaultPluginContext.Stage       = stage;

            var plugin = new CRM.Plugins.PIIEncryption("", _key);

            // var pluginResult = context.ExecutePluginWithTargetReference( plugin, target.ToEntityReference(), messageName, stage);
            var pluginResult = context.ExecutePluginWith(defaultPluginContext, plugin);

            Assert.IsNotNull(pluginResult);

            Assert.IsTrue(defaultPluginContext.SharedVariables.ContainsKey("MayDecrypt"));
            if (mayDecrypt)
            {
                Assert.AreEqual(12, colset.Columns.Count);
                Assert.IsTrue(colset.Columns.Contains("deb_idnumber_encrypted"));
                Assert.IsTrue(colset.Columns.Contains("deb_birthdate_encrypted"));
                Assert.IsTrue((bool)defaultPluginContext.SharedVariables["MayDecrypt"]);
            }
            else
            {
                Assert.AreEqual(10, colset.Columns.Count);
                Assert.IsFalse(colset.Columns.Contains("deb_idnumber_encrypted"));
                Assert.IsFalse(colset.Columns.Contains("deb_birthdate_encrypted"));
                Assert.IsFalse((bool)defaultPluginContext.SharedVariables["MayDecrypt"]);
            }
        }
示例#9
0
            public void owner_team_should_be_disassociated_from_all_AAD_team_members()
            {
                // Arrange
                var  context = new XrmFakedContext();
                var  pluginContext = context.GetDefaultPluginContext();
                Guid targetAADTeamGuid, userGuid1, userGuid2, targetOwnerTeamGuid;

                context.Initialize(new[] {
                    new Entity("team", targetOwnerTeamGuid = Guid.NewGuid()),
                    new Entity("team", targetAADTeamGuid   = Guid.NewGuid()),
                    new Entity("systemuser", userGuid1     = Guid.NewGuid()),
                    new Entity("systemuser", userGuid2     = Guid.NewGuid()),
                    new TeamMembership {
                        Id = Guid.NewGuid(), ["teamid"] = targetAADTeamGuid, ["systemuserid"] = userGuid1
                    },
                    new TeamMembership {
                        Id = Guid.NewGuid(), ["teamid"] = targetAADTeamGuid, ["systemuserid"] = userGuid2
                    },
                    new TeamMembership {
                        Id = Guid.NewGuid(), ["teamid"] = targetOwnerTeamGuid, ["systemuserid"] = userGuid1
                    },
                    new TeamMembership {
                        Id = Guid.NewGuid(), ["teamid"] = targetOwnerTeamGuid, ["systemuserid"] = userGuid2
                    }
                });
                context.AddRelationship("teammembership_association", new XrmFakedRelationship("teammembership", "teamid", "systemuserid", "team", "systemuser"));

                pluginContext.MessageName     = PluginMessage.Disassociate;
                pluginContext.InputParameters = new ParameterCollection {
                    { "Target", new EntityReference("team", targetOwnerTeamGuid) },
                    { "Relationship", new Relationship("opc_teams_teams_owneraadassociation") },
                    { "RelatedEntities", new EntityReferenceCollection(new [] { new EntityReference("team", targetAADTeamGuid) }) }
                };;

                // Act
                context.ExecutePluginWith <OwnerTeamMemberShipPlugin>(pluginContext);

                // Assert
                context.GetOrganizationService().RetrieveMultiple(new QueryExpression("teammembership")
                {
                    Distinct  = false,
                    ColumnSet = new ColumnSet(false),
                    Criteria  =
                    {
                        Conditions =
                        {
                            new ConditionExpression("teamid",       ConditionOperator.In, targetOwnerTeamGuid),
                            new ConditionExpression("systemuserid", ConditionOperator.In, new [] { userGuid1,  userGuid2})
                        }
                    }
                }).Entities.Count.Should().Be(0);
            }
        public void _03_MessageName_Does_Not_Equals_GrantAccess()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PostOperation;
            plugin.PrimaryEntityName = "account";
            plugin.MessageName       = "abcd";
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PostAccountGrantAccessAsynchronous>(plugin);
            }, "MessageName does not equals GrantAccess");
        }
示例#11
0
        public void PreAccountCreateSynchronousTest_MessageName_Does_Not_Equals_Create()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PreOperation;
            plugin.PrimaryEntityName = "account";
            plugin.MessageName       = "abcd";
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PreAccountCreateSynchronous>(plugin);
            }, "MessageName does not equals Create");
        }
        public void _03_Check_MessageName()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PostOperation;
            plugin.PrimaryEntityName = PrimaryEntityName;
            plugin.MessageName       = "abcd";
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PostContactMergeAsynchronous>(plugin);
            }, $"MessageName does not equals {MessageName}");
        }
示例#13
0
            public void owner_teams_should_not_be_associated_to_users_who_are_member_through_another_AAD_team()
            {
                // Arrange
                var  context = new XrmFakedContext();
                var  pluginContext = context.GetDefaultPluginContext();
                Guid targetAADTeamGuid, targetUserGuid, ownerTeamGuid, startingAADTeamGuid;

                context.Initialize(new[] {
                    new Entity("systemuser", targetUserGuid = Guid.NewGuid()),
                    new Entity("team", ownerTeamGuid        = Guid.NewGuid()),
                    new Entity("team", targetAADTeamGuid    = Guid.NewGuid()),
                    new Entity("team", startingAADTeamGuid  = Guid.NewGuid()),
                    new opc_teams_teams {
                        Id = Guid.NewGuid(), ["teamidone"] = ownerTeamGuid, ["teamidtwo"] = targetAADTeamGuid
                    },
                    new opc_teams_teams {
                        Id = Guid.NewGuid(), ["teamidone"] = ownerTeamGuid, ["teamidtwo"] = startingAADTeamGuid
                    },
                    new TeamMembership {
                        Id = Guid.NewGuid(), ["teamid"] = ownerTeamGuid, ["systemuserid"] = targetUserGuid
                    },
                    new TeamMembership {
                        Id = Guid.NewGuid(), ["teamid"] = startingAADTeamGuid, ["systemuserid"] = targetUserGuid
                    }
                });
                context.AddRelationship("teammembership_association", new XrmFakedRelationship("teammembership", "teamid", "systemuserid", "team", "systemuser"));

                pluginContext.MessageName     = PluginMessage.Associate;
                pluginContext.InputParameters = new ParameterCollection {
                    { "Target", new EntityReference("team", targetAADTeamGuid) },
                    { "Relationship", new Relationship("teammembership_association") },
                    { "RelatedEntities", new EntityReferenceCollection(new [] { new EntityReference("systemuser", targetUserGuid) }) }
                };

                // Act
                context.ExecutePluginWith <OwnerTeamMemberShipPlugin>(pluginContext);

                // Assert
                context.GetOrganizationService().RetrieveMultiple(new QueryExpression("teammembership")
                {
                    ColumnSet = new ColumnSet(false),
                    Criteria  =
                    {
                        Conditions =
                        {
                            new ConditionExpression("teamid",       ConditionOperator.In, ownerTeamGuid),
                            new ConditionExpression("systemuserid", ConditionOperator.In, targetUserGuid)
                        }
                    }
                }).Entities.Count.Should().Be(1);
            }
示例#14
0
        public void _04_Mode_Does_Not_Equals_Synchronous()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PreOperation;
            plugin.PrimaryEntityName = "account";
            plugin.MessageName       = "Delete";
            plugin.Mode = -1;
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PreAccountDeleteSynchronous>(plugin);
            }, "Execution does not equals Synchronous");
        }
示例#15
0
        public void TestRetrieveMultipleColsetWithFetchExpression()
        {
            var context     = new XrmFakedContext();
            var stage       = 20; // pre-operation¬
            var messageName = "RetrieveMultiple";

            var target = new Entity("contact")
            {
                Id = Guid.NewGuid(),
                ["deb_idnumber"] = "******",
                ["firstname"]    = "Bob",
                ["birthdate"]    = new DateTime(1900, 1, 1),
            };

            context.Initialize(target);

            var fetchQuery = new FetchExpression(@"<fetch top=""50"" >
  <entity name=""contact"" >
    <attribute name=""deb_idnumber"" alias=""deb_idnumber"" />
    <attribute name=""birthdate"" alias=""birthdate"" />
    <attribute name=""firstname"" alias=""firstname"" />
    <filter type=""and"" >
      <condition attribute=""firstname"" operator=""eq"" value=""Bob"" />
    </filter>
  </entity>
</fetch>");


            var defaultPluginContext = context.GetDefaultPluginContext();

            defaultPluginContext.InputParameters.Add("Query", fetchQuery);
            defaultPluginContext.OutputParameters.Add("BusinessEntityCollection", target);
            defaultPluginContext.MessageName = messageName;
            defaultPluginContext.Stage       = stage;


            var plugin = new CRM.Plugins.PIIEncryption("", _key);

            // var pluginResult = context.ExecutePluginWithTargetReference( plugin, target.ToEntityReference(), messageName, stage);
            var pluginResult = context.ExecutePluginWith(defaultPluginContext, plugin);

            Assert.IsNotNull(pluginResult);

            Debugger.Break();
            //var colset = fetchQuery. query.ColumnSet;
            //Assert.AreEqual(5, colset.Columns.Count);

            //Assert.IsTrue(colset.Columns.Contains("deb_idnumber_encrypted"));
            //Assert.IsTrue(colset.Columns.Contains("deb_birthdate_encrypted"));
        }
示例#16
0
        public void TestCreateBehavior()
        {
            Entity target = new Entity("kpd_entity")
            {
                Id = Guid.NewGuid()
            };
            ParameterCollection inputParameters = new ParameterCollection();

            inputParameters.Add("Target", target);

            _fakedpluginContext = new XrmFakedPluginExecutionContext
            {
                InputParameters = inputParameters,
                MessageName     = "Create",
                UserId          = Guid.NewGuid()
            };

            PluginActionTestAdapter <PluginActionOnCreateBehavior> _pluginActionTestAdapter = new PluginActionTestAdapter <PluginActionOnCreateBehavior>();

            _fakedContext.ExecutePluginWith(_fakedpluginContext, _pluginActionTestAdapter);

            Assert.IsTrue(string.IsNullOrEmpty(_pluginActionTestAdapter.ErrorMessage));
        }
        public void _04_Check_Mode()
        {
            var context = new XrmFakedContext();
            var plugin  = context.GetDefaultPluginContext();

            plugin.Stage             = (int)StageEnum.PostOperation;
            plugin.PrimaryEntityName = PrimaryEntityName;
            plugin.MessageName       = MessageName;
            plugin.Mode = -1;
            Assert.ThrowsException <InvalidPluginExecutionException>(() =>
            {
                context.ExecutePluginWith <PostAccountDeleteAsynchronous>(plugin);
            }, "Execution does not equals Asynchronous");
        }
        public void When_initializing_the_context_with_Properties_Plugins_Can_Access_It()
        {
            var context = new XrmFakedContext();

            ParameterCollection inputParameters = new ParameterCollection();

            inputParameters.Add("Target", new Entity());

            var plugCtx = context.GetDefaultPluginContext();

            plugCtx.MessageName     = "Create";
            plugCtx.InputParameters = inputParameters;

            Assert.DoesNotThrow(() => context.ExecutePluginWith <TestContextPlugin>(plugCtx));
        }
        public void EmailWithNoGuid()
        {
            var context = new XrmFakedContext();
            var target  = new Microsoft.Xrm.Sdk.Entity("email")
            {
                Id = Guid.Empty
            };
            var pluginContext = new XrmFakedPluginExecutionContext();

            pluginContext.Stage           = 20;
            pluginContext.MessageName     = "create";
            pluginContext.InputParameters = new ParameterCollection();
            pluginContext.InputParameters.Add("Target", target);
            Assert.ThrowsException <InvalidPluginExecutionException>(() => context.ExecutePluginWith <Crm.Plugins.Email.PreoperationUpdateEmailBody>(pluginContext));
        }
示例#20
0
            public void it_should_add_the_document_to_sharepoint()
            {
                // Arrange
                var context       = new XrmFakedContext();
                var pluginContext = context.GetDefaultPluginContext();

                pluginContext.InputParameters = inputs;
                pluginContext.MessageName     = PluginMessage.GenerateDocumentFromTemplate;

                // Act
                context.ExecutePluginWith(pluginContext, PluginInstance);

                // Assert
                MockSharePointService.Verify(x => x.AddFileToSharePoint(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <byte[]>()), Times.Once());
            }
            public void timeline_records_should_not_throw_when_null()
            {
                // Arrange
                var context       = new XrmFakedContext();
                var pluginContext = context.GetDefaultPluginContext();

                pluginContext.OutputParameters.Add(OutputParameter.TimelineWallRecords, null);
                pluginContext.MessageName = PluginMessage.RetrieveTimelineWallRecords;
                pluginContext.SharedVariables.Add(LanguageKey, (int)Language.English);

                // Act
                var ex = Record.Exception(() => context.ExecutePluginWith <MultiLanguagePlugin>(pluginContext));

                // Assert
                Assert.Null(ex);
            }
示例#22
0
        public void When_executing_a_plugin_primaryentityname_exists_in_the_context()
        {
            var context = new XrmFakedContext();

            var pluginContext = context.GetDefaultPluginContext();

            pluginContext.PrimaryEntityName = "Account";
            pluginContext.MessageName       = "Create";
            pluginContext.Stage             = 20;

            var entity = new Entity();

            context.ExecutePluginWith <PreAccountCreate>(pluginContext);

            Assert.True(true);
        }
示例#23
0
        public void When_PluginIsRegisteredForOtherEntity_And_OtherPluginCreatesAnAccount_Expect_AccountNumberIsNotSet()
        {
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            context.RegisterPluginStep <AccountNumberPlugin, Contact>("Create");

            context.ExecutePluginWith <CreateAccountPlugin>();

            var account = context.CreateQuery <Account>().FirstOrDefault();

            Assert.NotNull(account);
            Assert.False(account.Attributes.ContainsKey("accountnumber"));
        }
            public void timeline_records_strings_should_switch_to_correct_language(TimelineRecordTransform timelineRecordTransform)
            {
                // Arrange
                var context       = new XrmFakedContext();
                var pluginContext = context.GetDefaultPluginContext();

                pluginContext.OutputParameters.Add(OutputParameter.TimelineWallRecords, timelineRecordTransform.Initial);
                pluginContext.MessageName = PluginMessage.RetrieveTimelineWallRecords;
                pluginContext.SharedVariables.Add(LanguageKey, (int)timelineRecordTransform.Language);

                // Act
                context.ExecutePluginWith <MultiLanguagePlugin>(pluginContext);

                // Assert
                pluginContext.OutputParameters[OutputParameter.TimelineWallRecords].Should().Be(timelineRecordTransform.Expected);
            }
            public void recalculatechecklistresponses_fields_should_be_set_to_true()
            {
                // Arrange
                var  context = new XrmFakedContext();
                var  pluginContext = context.GetDefaultPluginContext();
                Guid targetComplaint, targetComplaint2, targetIndustry;

                context.Initialize(new[]
                {
                    new Entity("opc_complaint", targetComplaint  = Guid.NewGuid()),
                    new Entity("opc_complaint", targetComplaint2 = Guid.NewGuid()),
                    new Entity("opc_industry", targetIndustry    = Guid.NewGuid()),
                    new opc_complaintsrelatedindustries {
                        Id = Guid.NewGuid(), ["complaintid"] = targetComplaint, ["industryid"] = targetIndustry
                    },
                    new opc_complaintsrelatedindustries {
                        Id = Guid.NewGuid(), ["complaintid"] = targetComplaint2, ["industryid"] = targetIndustry
                    }
                });
                context.AddRelationship
                (
                    nameof(opc_complaint.opc_complaints_industries_relatedindustries),
                    new XrmFakedRelationship(nameof(opc_complaint.opc_complaints_industries_relatedindustries), "complaintid", "industryid", "opc_complaint", "industry")
                );

                pluginContext.MessageName     = PluginMessage.Associate;
                pluginContext.InputParameters = new ParameterCollection
                {
                    { "Target", new EntityReference("opc_industry", targetIndustry) },
                    { "Relationship", new Relationship(nameof(opc_complaint.opc_complaints_industries_relatedindustries)) },
                    { "RelatedEntities", new EntityReferenceCollection(new [] { new EntityReference("opc_complaint", targetComplaint), new EntityReference("opc_complaint", targetComplaint2) }) }
                };

                // Act
                context.ExecutePluginWith <RecalculateChecklistResponsesFlagPlugin>(pluginContext);

                // Assert
                var complaints = context.GetOrganizationService().RetrieveMultiple(new QueryExpression("opc_complaint")
                {
                    ColumnSet = new ColumnSet("opc_recalculatechecklistresponses"),
                }).Entities;

                foreach (var complaint in complaints)
                {
                    complaint.Attributes["opc_recalculatechecklistresponses"].Should().Be(true);
                }
            }
示例#26
0
            public void an_event_should_not_be_created_for_non_tracked_changed_field()
            {
                // Arrange
                var  context = new XrmFakedContext();
                var  pluginContext = context.GetDefaultPluginContext();
                Guid complaintId, preOwnerId, postOwnerId;

                var preImageEntity = new Entity("opc_complaint", complaintId = Guid.NewGuid())
                {
                    Attributes = new AttributeCollection()
                    {
                        { nameof(opc_complaint.opc_complainantrep), new EntityReference("Contact", preOwnerId = Guid.NewGuid())
                          {
                              Name = "John Doe"
                          } }
                    }
                };

                var postImageEntity = new Entity("opc_complaint", complaintId = Guid.NewGuid())
                {
                    Attributes = new AttributeCollection()
                    {
                        { nameof(opc_complaint.opc_complainantrep), new EntityReference("Contact", postOwnerId = Guid.NewGuid())
                          {
                              Name = "Johna Doey"
                          } }
                    }
                };

                pluginContext.PreEntityImages.Add(new KeyValuePair <string, Entity>("EntityImages", preImageEntity));
                pluginContext.PostEntityImages.Add(new KeyValuePair <string, Entity>("EntityImages", postImageEntity));
                context.AddRelationship("opc_complaint_opc_events", new XrmFakedRelationship("opc_complaint_opc_events", "opc_complaint_opc_events", "opc_complaint", "opc_event"));
                pluginContext.InputParameters = new ParameterCollection {
                    { "Target", new EntityReference("opc_complaint", complaintId) },
                };

                pluginContext.MessageName = PluginMessage.Update;

                // Act
                context.ExecutePluginWith <ChangeEventPlugin>(pluginContext);

                // Assert
                context.GetOrganizationService().RetrieveMultiple(new QueryExpression(Annotation.EntityLogicalName)
                {
                    ColumnSet = new ColumnSet(false)
                }).Entities.Count.Should().Be(0);
            }
            public void modified_on_should_be_replaced_with_created_on(Annotation annotation)
            {
                // Arrange
                var context       = new XrmFakedContext();
                var pluginContext = context.GetDefaultPluginContext();

                pluginContext.OutputParameters = new ParameterCollection {
                    { "BusinessEntity", annotation }
                };
                pluginContext.MessageName = PluginMessage.Retrieve;

                // Act
                context.ExecutePluginWith <TimelineTransformationsPlugin>(pluginContext);

                // Assert
                annotation.ModifiedOn.Should().Be(annotation.CreatedOn);
            }
示例#28
0
        public void When_AccountNumberPluginIsRegisteredAsPluginStep_And_OtherPluginCreatesAnAccount_Expect_AccountNumberIsSet()
        {
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            context.RegisterPluginStep <AccountNumberPlugin>("Create", ProcessingStepStage.Preoperation);

            context.ExecutePluginWith <CreateAccountPlugin>();

            var account = context.CreateQuery <Account>().FirstOrDefault();

            Assert.NotNull(account);
            Assert.True(account.Attributes.ContainsKey("accountnumber"));
            Assert.NotNull(account["accountnumber"]);
        }
示例#29
0
        public void UpdateAddress()
        {
            var xrmFakeContext = new XrmFakedContext();

            xrmFakeContext.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
            var guid         = Guid.NewGuid();
            var targetEntity = new Entity("acca_devops")
            {
                Id = guid
            };

            ParameterCollection inputParameter = new ParameterCollection();

            inputParameter.Add("Target", targetEntity);

            xrmFakeContext.ExecutePluginWith <UpdateAddress.Update>(inputParameter, null, null, null);
            Assert.IsTrue(targetEntity["acca_name"] == "TEST");
        }
示例#30
0
            public void it_should_throw_an_InvalidPluginExecutionException_if_there_is_an_exception_when_sending_the_file_to_sharepoint()
            {
                // Arrange
                var context       = new XrmFakedContext();
                var pluginContext = context.GetDefaultPluginContext();

                pluginContext.InputParameters = inputs;
                pluginContext.MessageName     = PluginMessage.GenerateDocumentFromTemplate;

                MockSharePointService.Setup(x => x.AddFileToSharePoint(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <byte[]>()))
                .ThrowsAsync(new Exception());

                // Act
                Action executePluginWith = () => context.ExecutePluginWith(pluginContext, PluginInstance);

                // Assert
                executePluginWith.Should().Throw <InvalidPluginExecutionException>();
            }
        public void Should_Execute_Mock_For_OrganizationRequests()
        {
            var context = new XrmFakedContext();
            var service = context.GetFakedOrganizationService();

            var e = new Entity("Contact") { Id = Guid.NewGuid() };
            context.Initialize(new[] { e });
            context.AddExecutionMock<RetrieveEntityRequest>(RetrieveEntityMock);

            var inputs = new ParameterCollection
            {
                {"Target", e }
            };

            context.ExecutePluginWith<CustomMockPlugin>(inputs, new ParameterCollection(), new EntityImageCollection(), new EntityImageCollection());

            Assert.Equal("Successful", (string)e["response"]);
            Assert.DoesNotThrow(() => context.RemoveExecutionMock<RetrieveEntityRequest>());
        }