public void TestUpdateExchangeRates()
        {
            using (var pipeline = new PluginPipeline(
                       "sf365_UpdateExchangeRates", FakeStages.PreOperation, new Entity("sf365_UpdateExchangeRates")))
            {
                pipeline.FakeService.ExpectExecute((OrganizationRequest request) => new RetrieveMultipleResponse()
                {
                    ["EntityCollection"] = new EntityCollection(new Entity[]
                    {
                        new TransactionCurrency()
                        {
                            TransactionCurrencyId = Guid.NewGuid(),
                            CurrencyName          = "CAD",
                            CurrencySymbol        = "CAD"
                        },
                        new TransactionCurrency()
                        {
                            TransactionCurrencyId = Guid.NewGuid(),
                            CurrencyName          = "GBP",
                            CurrencySymbol        = "GBP"
                        }
                    })
                });

                pipeline.FakeService.ExpectUpdate((Entity record) => { });
                pipeline.FakeService.ExpectUpdate((Entity record) => { });

                var plugin = new ExchangeRateActionPlugin();

                pipeline.Execute(plugin);

                pipeline.FakeService.AssertExpectedCalls();
            }
        }
        public void StatusCodeOne_AbortsCall()
        {
            #region arrange - given

            var entityName = "fdbzap_ar_action";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            target.Attributes["statuscode"] = new OptionSetValue(1);

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Update, FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <PostUpdate>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    pipeline.PostImages.Add("Post", target);
                    SetPipelineDefaults(pipeline);

                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then

                    // No errors means it exited properly
                    #endregion
                }
        }
示例#3
0
        public void CreatePipeline()
        {
            var target = new Xrm.Sdk.Entity("account");

            target.Id = Guid.NewGuid();

            // Arrange
            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
            {
                pipeline.Depth = 10;

                pipeline.FakeService.ExpectRetrieve((entityName, id, columnSet) => {
                    var returned     = new Entity("account");
                    returned["name"] = "123";
                    return(returned);
                });

                var plugin = new AccountPlugin();
                // Act & Assert
                pipeline.Execute(plugin);
                // Assert
                Assert.AreEqual("123", target.GetAttributeValue <string>("name"));
                Assert.AreEqual(10, pipeline.PluginExecutionContext.Depth);
                pipeline.FakeService.AssertExpectedCalls();
            }
        }
        public void CreateAccount_BadWebClient_ThrowsError()
        {
            #region arrange - given
            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            var fakeWebClient = A.Fake <IWebClient>();
            A.CallTo(() => fakeWebClient.DownloadData(A <Uri> .Ignored)).Throws(new InvalidCastException("error"));
            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <PreCreateSample>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline
                    plugin.Instance.WebClient = fakeWebClient;
                    SetPipelineDefaults(pipeline);
                    #endregion

                    #region act and assert

                    Assert.ThrowsException <InvalidPluginExecutionException>(
                        () => pipeline.Execute(plugin));
                    #endregion
                }
        }
示例#5
0
        public void TestWithNullActionTemplates()
        {
            #region arrange - given

            var entityName = "fdbzap_ar_approvalrequest";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline("fdbzap_ar_applytemplategroup", FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <ApplyTemplateGroupAction>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    var actionGroupId = Guid.NewGuid();
                    pipeline.InputParameters["ApprovalActionGroup"] =
                        new EntityReference("fdbzap_ar_actiongroup", actionGroupId);
                    pipeline.InputParameters["Target"] = target.ToEntityReference();
                    SetPipelineDefaults(pipeline);

                    #endregion

                    #region pipeline responses and tests

                    pipeline.FakeService.ExpectUpdate(r => { });

                    pipeline.FakeService.ExpectRetrieveMultiple(
                        query =>
                    {
                        var queryExpression = query as QueryExpression;
                        Assert.IsNotNull(
                            queryExpression,
                            "Retrieve Multiple expected Query Expression and received something else.");

                        Assert.AreEqual(
                            "fdbzap_ar_actiontemplate",
                            queryExpression.EntityName,
                            "Wrong type of entity trying to be retrieved.");

                        return(null);
                    });
                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then
                    pipeline.FakeService.AssertExpectedCalls();
                    #endregion
                }
        }
        public void TestHappyPath()
        {
            #region arrange - given

            var entityName = "fdbzap_ar_action";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            target["statuscode"] = new OptionSetValue(2); /* Status Code: Run */
            var targetApprovalRequest = new EntityReference("fdbzap_ar_approvalrequest", Guid.NewGuid());
            target["fdbzap_ar_approvalrequest"] = targetApprovalRequest;

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Update, FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <PostUpdate>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    pipeline.PostImages.Add("Post", target);
                    SetPipelineDefaults(pipeline);

                    #endregion

                    #region pipeline responses and tests

                    pipeline.FakeService
                    .ExpectUpdate((entity) => { })
                    .ExpectActionTakenUpdate(targetApprovalRequest, target)
                    .ExpectRetrieveMultipleOfApprovalRequest(
                        PostUpdateFakeServiceCalls.ExpectRetrieveMultipleOfApprovalRequestResult.NoChild)
                    .ExpectRetrieveMultiple((query) => null)
                    .ExpectExecute((request) =>
                    {
                        Assert.AreEqual("fdbzap_ar_checkstatus", request.RequestName);
                        return(null);
                    });

                    pipeline.FakeService.ExpectRetrieveMultiple((query) => null);
                    // TODO: Complete the rest of the happy path here...

                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then

                    // No errors means it exited properly
                    #endregion
                }
        }
        public void CreateAccount_DownloadsDataUsingWebClient()
        {
            #region arrange - given

            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            var fakeWebClient = A.Fake <IWebClient>();

            A.CallTo(() => fakeWebClient.UploadData(A <string> .Ignored, A <string> .Ignored, A <byte[]> .Ignored))
            .Returns(null);

            A.CallTo(() => fakeWebClient.DownloadData(A <Uri> .Ignored)).Returns(null);

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <PreCreateSample>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline
                    plugin.Instance.WebClient = fakeWebClient;
                    SetPipelineDefaults(pipeline);
                    #endregion

                    #region pipeline responses and tests

                    //pipeline.FakeService.ExpectRetrieve((retrieveEntityName, retrieveEntityId, retrieveColumnSet) =>
                    //    {
                    //        return new Entity("account");
                    //    }).ExpectCreate(createEntity =>
                    //    {
                    //        // test in create call
                    //        Assert.IsTrue(createEntity.LogicalName.Equals("annotation",
                    //            StringComparison.InvariantCultureIgnoreCase));
                    //        return Guid.NewGuid();
                    //    });

                    #endregion

                    #region act - when
                    pipeline.Execute(plugin);
                    #endregion

                    #region assert - then
                    A.CallTo(
                        () => fakeWebClient.DownloadData(A <Uri> .Ignored)
                        ).MustHaveHappened();

                    pipeline.FakeService.AssertExpectedCalls();
                    #endregion
                }
        }
示例#8
0
        public void CreateAccount_ModifiesTheCreatedEntity()
        {
            #region arrange - given

            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <Plugin>(_unsecureConfig, _secureConfig))
                {
                    //pipelines have to have the arrange and any inner asserts as part of them if you are attempting to
                    //check a child entity

                    #region pipeline responses and tests

                    pipeline.FakeService.ExpectRetrieve((retrieveEntityName, retrieveEntityId, retrieveColumnSet) =>
                    {
                        return(new Entity("account"));
                    }).ExpectCreate(createEntity =>
                    {
                        // test in create call
                        Assert.IsTrue(createEntity.LogicalName.Equals("annotation",
                                                                      StringComparison.InvariantCultureIgnoreCase));
                        return(Guid.NewGuid());
                    });

                    #endregion

                    string exceptionOccurred = null;

                    #region arrange - given with pipeline
                    SetPipelineDefaults(pipeline);
                    #endregion

                    #region act - when
                    pipeline.Execute(plugin);
                    #endregion

                    #region assert - then

                    Assert.IsNull(exceptionOccurred, exceptionOccurred);
                    pipeline.FakeService.AssertExpectedCalls();

                    #endregion
                }
        }
        public void CreateUknownEntity_ThrowsAnError()
        {
            #region arrange - given

            var entityName = "==UnkownEntity==";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <PreCreateSample>(UnsecureConfig, SecureConfig))
                {
                    // Wrapped in try catch because a failure is expected.
                    try
                    {
                        #region arrange - given with pipeline

                        SetPipelineDefaults(pipeline);

                        #endregion

                        #region act - when

                        pipeline.Execute(plugin);

                        #endregion

                        #region assert - then

                        Assert.Fail("An error was expected, but did not occur.");

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        #region assert - then

                        Assert.AreEqual(string.Format(ResponseMessages.InvalidEntity, entityName, plugin.Instance.PluginName),
                                        ex.Message);

                        #endregion
                    }
                }
        }
        public void InvalidEntityType_ThrowsError()
        {
            #region arrange - given

            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Update, FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <PostUpdate>(true, UnsecureConfig, SecureConfig))
                {
                    try
                    {
                        #region arrange - given with pipeline

                        SetPipelineDefaults(pipeline);

                        #endregion

                        #region act - when

                        pipeline.Execute(plugin);

                        #endregion

                        #region assert - then

                        Assert.Fail("An error was expected, but did not occur.");

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        #region assert - then

                        Assert.AreEqual(
                            string.Format(ResponseMessages.InvalidEntity, entityName, plugin.Instance.PluginName),
                            ex.Message);

                        #endregion
                    }
                }
        }
示例#11
0
        public void TestAccountPlugin()
        {
            using (var pipline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, new Entity("contact")))
            {
                var plugin = new AccountPlugin();

                try
                {
                    pipline.Execute(plugin);
                    Assert.Fail("Exception not thrown");
                }
                catch (InvalidPluginExecutionException ex)
                {
                    Assert.IsTrue(ex.Message.Contains("Working on it"), "Must throw exeception");
                }
            }
        }
示例#12
0
        public void InvalidEntity_ThrowsError()
        {
            #region arrange - given

            var entityName = "invalidentity";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline("fdbzap_ar_applytemplategroup", FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <ApplyTemplateGroupAction>(true, UnsecureConfig, SecureConfig))
                {
                    try
                    {
                        #region arrange - given with pipeline

                        pipeline.InputParameters["Target"] = target.ToEntityReference();
                        SetPipelineDefaults(pipeline);

                        #endregion

                        #region act - when

                        pipeline.Execute(plugin);

                        #endregion

                        #region assert - then

                        Assert.Fail("An error was expected, but did not occur.");

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        #region assert - then

                        Assert.AreEqual("The entity invalidentity is not support by ApplyTemplateGroupAction.", ex.Message);

                        #endregion
                    }
                }
        }
示例#13
0
 private void SetPipelineDefaults(PluginPipeline pipeline)
 {
     // Set the default values
     pipeline.UserId             = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
     pipeline.InitiatingUserId   = pipeline.UserId;
     pipeline.OrganizationId     = Guid.Parse("c0000000-c000-c000-c000-c00000000000");
     pipeline.OrganizationName   = "TestOrganization";
     pipeline.CorrelationId      = Guid.Parse("cccccccc-cccc-cccc-cccc-cccccccccccc");
     pipeline.BusinessUnitId     = Guid.Parse("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb");
     pipeline.RequestId          = Guid.NewGuid();
     pipeline.OperationId        = Guid.NewGuid();
     pipeline.OperationCreatedOn = DateTime.Now;
     pipeline.IsolationMode      = PluginAssemblyIsolationMode.Sandbox;
     pipeline.IsExecutingOffline = false;
     pipeline.IsInTransaction    = false;
     pipeline.Mode = SdkMessageProcessingStepMode.Synchronous;
 }
示例#14
0
        public void DeleteAccount_ThrowsAnError()
        {
            #region arrange - given

            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Delete, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <Plugin>(_unsecureConfig, _secureConfig))
                {
                    string exceptionOccurred = null;
                    //Wrapped in try catch because a failure is expected.
                    try
                    {
                        #region arrange - given with pipeline

                        SetPipelineDefaults(pipeline);

                        #endregion

                        #region act - when

                        pipeline.Execute(plugin);

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        exceptionOccurred = ex.Message;
                        Trace(ex.Message);
                    }

                    #region assert - then

                    Assert.AreEqual(string.Format(ResponseMessages.InvalidMessageName, plugin.Instance.PluginName),
                                    exceptionOccurred);

                    #endregion
                }
        }
示例#15
0
        public void CatchInvalidSandboxWebAccess()
        {
            #region arrange - given

            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <Plugin>(true, _unsecureConfig, _secureConfig))
                {
                    #region arrange - given with pipeline

                    SetPipelineDefaults(pipeline);

                    pipeline.FakeService.ExpectRetrieve((retrieveEntityName, retrieveEntityId, retrieveColumnSet) =>
                    {
                        return(new Entity("account"));
                    }).ExpectCreate(createEntity =>
                    {
                        // test in create call
                        Assert.IsTrue(createEntity.LogicalName.Equals("annotation",
                                                                      StringComparison.InvariantCultureIgnoreCase));
                        return(Guid.NewGuid());
                    });

                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then


                    #endregion
                }
        }
        /// <summary>
        /// The test up to approval request retrieve multiple.
        /// </summary>
        /// <param name="expectedResult">
        /// The expected result, such as null result, or one child.
        /// </param>
        private void TestUpToApprovalRequestRetrieveMultiple(
            PostUpdateFakeServiceCalls.ExpectRetrieveMultipleOfApprovalRequestResult expectedResult)
        {
            #region arrange - given

            var entityName = "fdbzap_ar_action";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            target["statuscode"] = new OptionSetValue(2); /* Status Code: Run */
            var targetApprovalRequest = new EntityReference("fdbzap_ar_approvalrequest", Guid.NewGuid());
            target["fdbzap_ar_approvalrequest"] = targetApprovalRequest;

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Update, FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <PostUpdate>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    pipeline.PostImages.Add("Post", target);
                    SetPipelineDefaults(pipeline);
                    #endregion

                    #region pipeline responses and tests

                    pipeline.FakeService.ExpectActionTakenUpdate(targetApprovalRequest, target)
                    .ExpectRetrieveMultipleOfApprovalRequest(expectedResult);

                    pipeline.FakeService.ExpectRetrieveMultiple((query) => { return(null); });
                    #endregion

                    #region act - when
                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then

                    // No errors means it exited properly
                    #endregion
                }
        }
        public void CreateAccount_NoSecureConfig_ThrowsError()
        {
            #region arrange - given

            var entityName = "account";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            var fakeWebClient = A.Fake <IWebClient>();

            A.CallTo(
                () => fakeWebClient.UploadData(A <string> .Ignored, A <string> .Ignored, A <byte[]> .Ignored)
                ).Returns(null);

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <PreCreateSample>(true, string.Empty, string.Empty))
                {
                    #region arrange - given with pipeline
                    plugin.Instance.WebClient = fakeWebClient;
                    SetPipelineDefaults(pipeline);
                    #endregion

                    #region act and assert

                    try
                    {
                        // act
                        pipeline.Execute(plugin);
                        // assert error
                        Assert.Fail("An error was expected, but did not occur.");
                    }
                    catch (InvalidPluginExecutionException ex)
                    {
                        Assert.AreEqual("No Secure Configuration", ex.Message);
                    }
                    #endregion
                }
        }
示例#18
0
        public void ThrowsException()
        {
            using (var pipeline = new PluginPipeline(
                       FakeMessageNames.Create, FakeStages.PreOperation, new Entity("contact")))
            {
                try
                {
                    // Act
                    var plugin = new AccountPlugin();
                    pipeline.Execute(plugin);
                    Assert.Fail("No exception thrown");
                }
                catch (Exception ex)
                {
                    // Assert
                    Assert.AreEqual("Working on it...", ex.Message);
                }

                pipeline.FakeService.AssertExpectedCalls();
            }
        }
示例#19
0
        public void GetTargetEntityReference_ThrowsErrorWhenTargetIsNull()
        {
            #region arrange - given

            var entityName = "invalidentity";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline("fdbzap_ar_applytemplategroup", FakeStages.PostOperation, target))
            {
                pipeline.InputParameters["Target"] = null;
                var context = new FakeLocalPluginContext(pipeline);

                Assert.ThrowsException <InvalidPluginExecutionException>(() =>
                {
                    ApplyTemplateGroupAction.GetTargetEntityReference(context);
                }, "An exception was expected, but it did not occur.");
            }
        }
        public void GetTargetEntityReference_ThrowsErrorWhenTargetIsMissing()
        {
            #region arrange - given

            var entityName = "invalidentity";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline("fdbzap_ar_checkstatus", FakeStages.PostOperation, target))
            {
                pipeline.InputParameters.Remove("Target");
                var context = new FakeLocalPluginContext(pipeline);

                Assert.ThrowsException <InvalidPluginExecutionException>(() =>
                {
                    CheckStatusAction.GetTargetEntityReference(context);
                }, "An exception was expected, but it did not occur.");
            }
        }
示例#21
0
        public void TestHappyPath()
        {
            #region arrange - given

            var entityName = "fdbzap_ar_approvalrequest";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };

            #endregion

            using (var pipeline = new PluginPipeline("fdbzap_ar_applytemplategroup", FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <ApplyTemplateGroupAction>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    var actionGroupId = Guid.NewGuid();
                    pipeline.InputParameters["ApprovalActionGroup"] =
                        new EntityReference("fdbzap_ar_actiongroup", actionGroupId);
                    pipeline.InputParameters["Target"] = target.ToEntityReference();
                    SetPipelineDefaults(pipeline);

                    #endregion

                    #region pipeline responses and tests
                    pipeline.FakeService.ExpectUpdate(
                        r =>
                    {
                        Assert.AreEqual("fdbzap_ar_approvalrequest", r.LogicalName);
                        Assert.AreEqual(target.Id, r.Id);
                    });

                    pipeline.FakeService.ExpectRetrieveMultiple(
                        query =>
                    {
                        var queryExpression = query as QueryExpression;
                        Assert.IsNotNull(
                            queryExpression,
                            "Retrieve Multiple expected Query Expression and received something else.");

                        Assert.AreEqual(
                            "fdbzap_ar_actiontemplate",
                            queryExpression.EntityName,
                            "Wrong type of entity trying to be retrieved.");

                        // This should return a collection of actions sorted by priority.

                        var result = new EntityCollection();

                        var approveid = Guid.NewGuid();
                        var denyid    = Guid.NewGuid();

                        result.Entities.AddRange(
                            new Entity("fdbzap_ar_actiontemplate", approveid)
                        {
                            ["fdbzap_ar_name"]             = "Approve",
                            ["fdbzap_ar_button_label"]     = "Approve",
                            ["fdbzap_ar_button_tooltip"]   = "Click here to approve the request.",
                            ["fdbzap_ar_customactioncode"] = "approve",
                            ["fdbzap_ar_actiontemplateid"] = approveid,
                            ["fdbzap_ar_allow_comments"]   = true,
                            ["fdbzap_ar_actiontype"]       = new OptionSetValue(741210000),
                            ["fdbzap_ar_actiongroupid"]    = new EntityReference("fdbzap_ar_actiongroup", actionGroupId)
                        },
                            new Entity("fdbzap_ar_action", denyid)
                        {
                            ["fdbzap_ar_name"]             = "Deny",
                            ["fdbzap_ar_button_label"]     = "Deny",
                            ["fdbzap_ar_button_tooltip"]   = "Click here to deny the request.",
                            ["fdbzap_ar_customactioncode"] = "deny",
                            ["fdbzap_ar_actiontemplateid"] = denyid,
                            ["fdbzap_ar_allow_comments"]   = true,
                            ["fdbzap_ar_actiontype"]       = new OptionSetValue(741210001),
                            ["fdbzap_ar_actiongroupid"]    = new EntityReference("fdbzap_ar_actiongroup", actionGroupId)
                        });

                        return(result);
                    });

                    pipeline.FakeService.ExpectCreate(r => Guid.NewGuid());
                    pipeline.FakeService.ExpectCreate(r => Guid.NewGuid());


                    // TODO: Fix testing... this stops before any recursion into child approvals.
                    pipeline.FakeService.ExpectRetrieveMultiple(r => null);

                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then
                    pipeline.FakeService.AssertExpectedCalls();
                    #endregion
                }
        }
        public void TestHappyPath()
        {
            #region arrange - given

            var taskid       = Guid.NewGuid();
            var compressedId = Utilities.CompressGuid(taskid);

            var from = new EntityCollection(new[]
            {
                new Entity
                {
                    ["partyid"] = new EntityReference("systemuser", Guid.NewGuid())
                }
            });

            var target = new Entity("email")
            {
                Id              = Guid.NewGuid(),
                ["from"]        = from,
                ["description"] = @"
<html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:w=""urn:schemas-microsoft-com:office:word"" xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml"" xmlns=""http://www.w3.org/TR/REC-html40""><head><META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=us-ascii""><meta name=Generator content=""Microsoft Word 15 (filtered medium)""><style><!--
/* Font Definitions */
@font-face
	{font-family:""Cambria Math"";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:""Calibri"",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:""Calibri"",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:""Calibri"",sans-serif;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=""edit"" spidmax=""1026"" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=""edit"">
<o:idmap v:ext=""edit"" data=""1"" />
</o:shapelayout></xml><![endif]--></head>
<body lang=EN-US link=""#0563C1"" vlink=""#954F72"">
<div class=WordSection1>
<p class=MsoNormal>Completed Blah Blah<o:p></o:p></p>
<p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>"
                                  + "#TSK-" + compressedId + "#"
                                  + "<o:p></o:p></p></div></body></html>"
            };

            #endregion

            using (var pipeline = new PluginPipeline(FakeMessageNames.Create, FakeStages.PreOperation, target))
                using (var plugin = new PluginContainer <PostCreateTaskCompletion>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    pipeline.InputParameters["Target"] = target;
                    SetPipelineDefaults(pipeline);

                    #endregion

                    #region pipeline responses and tests

                    pipeline.FakeService
                    .ExpectRetrieveMultiple((request) => new EntityCollection(new[] { new Entity()
                                                                                      {
                                                                                          Id = taskid
                                                                                      } }))
                    .ExpectUpdate((updateTask) => { })
                    .ExpectRetrieveMultiple((request) =>
                    {
                        var qe = (FetchExpression)request;
                        Assert.IsTrue(qe.Query.Contains("<fetch top='100'><entity name='activitymimeattachment'>"));
                        return(null);
                    });


                    // TODO: Complete the rest of the happy path here...

                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then

                    pipeline.FakeService.AssertExpectedCalls();

                    #endregion
                }
        }
 public FakeLocalPluginContext(PluginPipeline pipeline)
 {
     Pipeline = pipeline;
 }
        public void TestHappyPath()
        {
            #region arrange - given

            var entityName = "fdbzap_ar_approvalrequest";
            var target     = new Entity(entityName)
            {
                Id = Guid.NewGuid()
            };
            var actionTakenId = Guid.Parse("cccccccc-cccc-cccc-cccc-cccccccccccc");

            #endregion

            using (var pipeline = new PluginPipeline("fdbzap_ar_checkstatus", FakeStages.PostOperation, target))
                using (var plugin = new PluginContainer <CheckStatusAction>(true, UnsecureConfig, SecureConfig))
                {
                    #region arrange - given with pipeline

                    pipeline.InputParameters["Target"] = target.ToEntityReference();
                    SetPipelineDefaults(pipeline);

                    #endregion

                    #region pipeline responses and tests

                    pipeline.FakeService.ExpectRetrieveMultiple(
                        query =>
                    {
                        var queryExpression = query as QueryExpression;
                        Assert.IsNotNull(
                            queryExpression,
                            "Retrieve Multiple expected Query Expression and received something else.");

                        Assert.AreEqual(
                            "fdbzap_ar_action",
                            queryExpression.EntityName,
                            "Wrong type of entity trying to be retrieved.");

                        // This should return a collection of actions sorted by priority.

                        var result = new EntityCollection();
                        result.Entities.AddRange(
                            new Entity("fdbzap_ar_action", Guid.NewGuid())
                        {
                            ["fdbzap_ar_priority"]    = 1,
                            ["fdbzap_ar_minaction"]   = 3,
                            ["fdbzap_ar_actioncount"] = 2
                        },
                            new Entity("fdbzap_ar_action", Guid.NewGuid())
                        {
                            ["fdbzap_ar_priority"]    = 2,
                            ["fdbzap_ar_minaction"]   = 18,
                            ["fdbzap_ar_actioncount"] = 5
                        },
                            new Entity("fdbzap_ar_action", actionTakenId)     /* This action will be the action taken */
                        {
                            ["fdbzap_ar_priority"]    = 3,
                            ["fdbzap_ar_minaction"]   = 1,
                            ["fdbzap_ar_actioncount"] = 1
                        });

                        return(result);
                    })
                    .ExpectExecute((request) =>
                    {
                        Assert.AreEqual("fdbzap_ar_update_regardingobject", request.RequestName);
                        return(null);
                    });

                    // TODO: Complete the rest of the happy path here...

                    #endregion

                    #region act - when

                    pipeline.Execute(plugin);

                    #endregion

                    #region assert - then
                    pipeline.FakeService.AssertExpectedCalls();
                    Assert.IsTrue(pipeline.OutputParameters.Contains("ActionTaken"), "Output Parameter 'ActionTaken' is missing.");
                    var actionTaken = pipeline.OutputParameters["ActionTaken"] as EntityReference;
                    Assert.AreEqual(actionTakenId, actionTaken?.Id, "ActionTaken does not match expected result.");
                    #endregion
                }
        }