public IPlugin ExecutePluginWith <T>(XrmFakedPluginExecutionContext ctx) where T : IPlugin, new()
 {
     return(this.ExecutePluginWith <T>(ctx, new T()));
 }
示例#2
0
        protected void PopulateExecutionContextPropertiesFromFakedContext(IExecutionContext context, XrmFakedPluginExecutionContext ctx)
        {
            var newUserId = Guid.NewGuid();

            A.CallTo(() => context.Depth).ReturnsLazily(() => ctx.Depth <= 0 ? 1 : ctx.Depth);
            A.CallTo(() => context.IsExecutingOffline).ReturnsLazily(() => ctx.IsExecutingOffline);
            A.CallTo(() => context.InputParameters).ReturnsLazily(() => ctx.InputParameters);
            A.CallTo(() => context.OutputParameters).ReturnsLazily(() => ctx.OutputParameters);
            A.CallTo(() => context.PreEntityImages).ReturnsLazily(() => ctx.PreEntityImages);
            A.CallTo(() => context.PostEntityImages).ReturnsLazily(() => ctx.PostEntityImages);
            A.CallTo(() => context.MessageName).ReturnsLazily(() => ctx.MessageName);
            A.CallTo(() => context.Mode).ReturnsLazily(() => ctx.Mode);
            A.CallTo(() => context.OrganizationName).ReturnsLazily(() => ctx.OrganizationName);
            A.CallTo(() => context.OrganizationId).ReturnsLazily(() => ctx.OrganizationId);
            A.CallTo(() => context.InitiatingUserId).ReturnsLazily(() => ctx.InitiatingUserId == Guid.Empty ? newUserId : ctx.InitiatingUserId);
            A.CallTo(() => context.UserId).ReturnsLazily(() => ctx.UserId == Guid.Empty ? newUserId : ctx.UserId);
            A.CallTo(() => context.PrimaryEntityName).ReturnsLazily(() => ctx.PrimaryEntityName);
            A.CallTo(() => context.SecondaryEntityName).ReturnsLazily(() => ctx.SecondaryEntityName);
            A.CallTo(() => context.SharedVariables).ReturnsLazily(() => ctx.SharedVariables);
            A.CallTo(() => context.BusinessUnitId).ReturnsLazily(() => ctx.BusinessUnitId);
            A.CallTo(() => context.CorrelationId).ReturnsLazily(() => ctx.CorrelationId);
            A.CallTo(() => context.OperationCreatedOn).ReturnsLazily(() => ctx.OperationCreatedOn);

            // Create message will pass an Entity as the target but this is not always true
            // For instance, a Delete request will receive an EntityReference
            if (ctx.InputParameters != null && ctx.InputParameters.ContainsKey("Target"))
            {
                if (ctx.InputParameters["Target"] is Entity)
                {
                    var target = (Entity)ctx.InputParameters["Target"];
                    A.CallTo(() => context.PrimaryEntityId).ReturnsLazily(() => target.Id);
                    A.CallTo(() => context.PrimaryEntityName).ReturnsLazily(() => target.LogicalName);
                }
                else if (ctx.InputParameters["Target"] is EntityReference)
                {
                    var target = (EntityReference)ctx.InputParameters["Target"];
                    A.CallTo(() => context.PrimaryEntityId).ReturnsLazily(() => target.Id);
                    A.CallTo(() => context.PrimaryEntityName).ReturnsLazily(() => target.LogicalName);
                }
            }
        }
        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...
            Assert.DoesNotThrow(() => context.ExecutePluginWith<TestContextPlugin>(pluginContext));

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


            Assert.DoesNotThrow(() => context.ExecutePluginWith<TestContextPlugin>(pluginContext));

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

            Assert.DoesNotThrow(() => context.ExecutePluginWith<TestContextPlugin>(pluginContext));
        }