Пример #1
0
        public void Test_plugin_2015_preimage()
        {
            //Arrange

            //Create the plug-in mock
            CrmPluginMock pluginMock = new CrmPluginMock();
            //Define the Pre-Image
            Entity preImage = new Entity("contact")
            {
                Id           = Guid.NewGuid(),
                ["fullname"] = "Fred Flintstone"
            };

            //Set the PreIMage
            pluginMock.PluginPreImage = new PreImage("PreImage", preImage);

            //Act

            //Execute the plug-in
            pluginMock.Execute <ExamplePlugin3>();

            //Assert

            //Review the test Output to see the 'fullname' from the PreImage
            Assert.IsNotNull(1);
        }
Пример #2
0
        public void Test_plugin_2016_execute_nonvirtual_method()
        {
            //Arrange

            string expected = "Hello World!";

            //Create a plug-in mock - this allows the constructor values to be set
            CrmPluginMock pluginMock = new CrmPluginMock {
                UnsecureConfiguration = expected
            };

            //Act

            //Use the ExecuteMethod method of the plug-in mock to execute
            //a method in the workflow - in this case a method named Test3
            string unsecureConfig = String.Empty;
            object result         = pluginMock.ExecuteMethod <ExamplePlugin5>("Test3");

            if (result != null)
            {
                unsecureConfig = result.ToString();
            }

            //Assert

            //Compare the method result to the expected value
            Assert.AreEqual(unsecureConfig, expected);
        }
Пример #3
0
        public void Test_plugin_2016_methodonly_trace_retrieve()
        {
            //Arrange

            //Create the plug-in mock - not need to create the context as we aren't using it
            CrmPluginMock pluginMock = new CrmPluginMock();

            //Define the entity to be returned from the Retrieve request
            Entity user = new Entity("systemuser", new Guid())
            {
                ["fullname"] = "John Smith"
            };

            //Set the Retrieve response
            pluginMock.SetMockRetrieves(user);

            //Act

            //Execute the method (which was marked Public)
            ExamplePlugin examplePlugin = new ExamplePlugin();
            string        name          = examplePlugin.RetrieveUserFullName(pluginMock.FakeOrganizationService, pluginMock.FakeTracingService, Guid.NewGuid());

            //Assert

            //Check the returned value matches the expected value being
            //returned from the method in the plug-in
            Assert.AreEqual(name, "John Smith");

            //Also check this test's output and you will see that the trace message was written
        }
Пример #4
0
        public void Test_plugin_2011_multiple_retrievemultiple()
        {
            //Arrange

            //Create the plug-in mock
            CrmPluginMock pluginMock = new CrmPluginMock();

            //Define the result of the first query - type QueryExpressions
            EntityCollection accounts = new EntityCollection
            {
                Entities =
                {
                    new Entity("account")
                    {
                        Id = Guid.NewGuid(), ["name"] = "test1", ["telephone1"] = "555-555-5555"
                    },
                    new Entity("account")
                    {
                        Id = Guid.NewGuid(), ["name"] = "test2", ["telephone1"] = "333-333-3333"
                    }
                }
            };

            //Define the result of the first query - type FetchExpression
            EntityCollection contacts = new EntityCollection
            {
                Entities =
                {
                    new Entity("contact")
                    {
                        Id = Guid.NewGuid(), ["fullname"] = "Joe Smith", ["telephone1"] = "444-444-4444"
                    },
                    new Entity("contact")
                    {
                        Id = Guid.NewGuid(), ["fullname"] = "Bob Smith", ["telephone1"] = "777-777-7777"
                    }
                }
            };

            //Set the RetrieveMultiple responses
            pluginMock.SetMockRetrieveMultiples(accounts, contacts);

            //Act

            //Execute the plug-in
            ExamplePlugin2 examplePlugin2 = new ExamplePlugin2(String.Empty, String.Empty);
            int            count          = examplePlugin2.GetAccountAndContactCount(pluginMock.FakeOrganizationService);

            //Assert

            //Review the test Output to see the configuration values
            Assert.AreEqual(count, 4);
        }
Пример #5
0
        public void Test_plugin_2011_preupdate_messagetype_execute()
        {
            //Arrange

            //Define the Target entity
            Entity target = new Entity("account")
            {
                Id = Guid.NewGuid()
            };
            //Create the plug-in mock and set the MessageName using a helper method, CreateMessageName.GetCustom
            //can be used to specify a message not included or for a custom action
            CrmPluginMock pluginMock = new CrmPluginMock
            {
                PluginExecutionContext = new FakePluginExecutionContext
                {
                    MessageName = XrmMoq.Helpers.CreateMessageName.GetExisting(MessageName.create)
                }
            };

            //Set the Target entity - there is an overload for EntityReference as well
            pluginMock.SetTarget(ref target);

            //Most of the specific OrganizationResponse classes do not have 'setters' on their properties so to get
            //around this create the specific response but instead define any return values in the 'Results' collection.
            //Define the mock Execute response
            OrganizationResponse response = new WhoAmIResponse
            {
                Results = new ParameterCollection
                {
                    { "UserId", new Guid("D1D92A0D-8BC8-4001-BE3E-A2C5D36E5124") }
                }
            };

            //Set the Execute response
            pluginMock.SetMockExecutes(response);

            //Act

            //Execute the plug-in
            pluginMock.Execute <ExamplePlugin>();

            //Assert

            //Check the value updated in the Target entity matches the expected value being
            //returned from the plug-in
            Assert.AreEqual(target.GetAttributeValue <string>("name").ToUpper(), "D1D92A0D-8BC8-4001-BE3E-A2C5D36E5124");
        }
Пример #6
0
        public void Test_plugin_2011_preupdate_messagetype_retrieve()
        {
            //Arrange

            //Define the Target entity
            Entity target = new Entity("account")
            {
                Id = Guid.NewGuid()
            };
            //Create the plug-in mock and set the MessageName using a helper method, CreateMessageName.GetCustom
            //can be used to specify a message not included or for a custom action
            CrmPluginMock pluginMock = new CrmPluginMock
            {
                PluginExecutionContext = new FakePluginExecutionContext
                {
                    MessageName = CreateMessageName.GetExisting(MessageName.update)
                }
            };

            //Set the Target entity
            pluginMock.SetTarget(ref target);

            //Define the entity to be returned from the Retrieve request
            Entity user = new Entity("systemuser")
            {
                ["fullname"] = "John Smith",
                Id           = Guid.NewGuid()
            };

            //Set the Retrieve response
            pluginMock.SetMockRetrieves(user);

            //Act

            //Execute the plug-in
            pluginMock.Execute <ExamplePlugin>();

            //Assert

            //Check the value updated in the Target entity matches the expected value being
            //returned from the plug-in
            Assert.AreEqual(target.GetAttributeValue <string>("name"), "John Smith");
        }
Пример #7
0
        public void Test_plugin_2011_trace_configurations()
        {
            //Arrange

            //Create the plug-in mock and set the unsecure & secure configurations
            CrmPluginMock pluginMock = new CrmPluginMock
            {
                UnsecureConfiguration = "Hello World",
                SecureConfiguration   = "Testing 1234"
            };

            //Act

            //Execute the plug-in
            pluginMock.Execute <ExamplePlugin2>();

            //Assert

            //Review the test Output to see the configuration values
            Assert.IsNotNull(1);
        }
Пример #8
0
        public void Test_plugin_2016_method_livecrm_setup_teardown()
        {
            //Arrange

            //We don't really need to use the plug-in mock here since we've already got an
            //instance at the class level - but this could be used if executing the entire plug-in
            CrmPluginMock pluginMock = new CrmPluginMock
            {
                LiveOrganizationService = _service
            };

            //Act

            //Execute the plug-in method providing the real CRM service
            string telephone1 = ExamplePlugin4.GetAccountTelephone(_service);

            //Assert

            //Check the value specified in the test record matches what was created and returned from CRM
            Assert.AreEqual(telephone1, "444-555-6677");
        }