public void When_passing_a_custom_workflow_activity_context_injected_property_is_returned()
        {
            var fakedContext = new XrmFakedContext();
            var wfContext    = fakedContext.GetDefaultWorkflowContext();

            wfContext.MessageName = "Update";

            //Inputs
            var inputs = new Dictionary <string, object>();

            CheckContextPropertyActivity codeActivity = new CheckContextPropertyActivity();

            var result = fakedContext.ExecuteCodeActivity <CheckContextPropertyActivity>(wfContext, inputs, codeActivity);

            Assert.True(((string)result["MessageName"]).Equals("Update"));
        }
Ejemplo n.º 2
0
        public void FetchXml_Operator_EqualBusinessId_Execution()
        {
            XrmFakedContext _context = new XrmFakedContext();

            string _fetchXml =
                @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                <entity name='resource'>
                    <attribute name='name'/>
                    <filter type = 'and'>
                        <condition attribute='businessunitid' operator='eq-businessid' />
                    </filter>
                </entity>
            </fetch>";

            string _resource1Id = "8AE5C98B-46E6-41B8-8326-279B29951A73";
            string _resource2Id = "DF328B18-45D9-4C30-B86A-A54D5CA2F04D";
            string _business1Id = "262DAFB9-9FC9-4006-9881-A680120B40C3";
            string _business2Id = "8BFC5749-8630-4CA0-A80F-9BDADE5F2BDB";

            List <Resource> _entities = new List <Resource>()
            {
                new Resource()
                {
                    Id = Guid.Parse(_resource1Id), BusinessUnitId = new EntityReference("resource", Guid.Parse(_business1Id))
                },
                new Resource()
                {
                    Id = Guid.Parse(_resource2Id), BusinessUnitId = new EntityReference("resource", Guid.Parse(_business2Id))
                }
            };

            _context.BusinessUnitId = new EntityReference("businessunit", Guid.Parse(_business2Id));
            XrmFakedWorkflowContext _workflowContext = _context.GetDefaultWorkflowContext();

            IOrganizationService _service = _context.GetOrganizationService();

            _context.Initialize(_entities);

            EntityCollection _collection = _service.RetrieveMultiple(new FetchExpression(_fetchXml));

            Assert.NotNull(_collection);
            Assert.Single(_collection.Entities);
            Assert.Equal(Guid.Parse(_resource2Id), _collection.Entities[0].Id);
        }
Ejemplo n.º 3
0
        public void TestAccountDuplicatesWithFakes2()
        {
            var account1 = new Entity("account")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "Account One",
            };
            var account2 = new Entity("account")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "Account Two",
            };
            var account3 = new Entity("account")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "Account Three",
            };
            var ctx = new XrmFakedContext();

            ctx.Initialize(new List <Entity> {
                account1, account2, account3
            });
            var wfContext = ctx.GetDefaultWorkflowContext();

            wfContext.MessageName     = "Create";
            wfContext.PrimaryEntityId = account1.Id;
            wfContext.PreEntityImages.Add("account", account1);

            var input = new Dictionary <string, object>();
            //            input.Add("AccountReference", new EntityReference("account", account1.Id));


            var codeActivity = new DuplicateChecker();
            var result       = ctx.ExecuteCodeActivity <DuplicateChecker>(wfContext, input, codeActivity);

            Assert.IsTrue(result.ContainsKey("PossibleMatch"));
            Assert.IsTrue((bool)result["PossibleMatch"]);

            //            Debugger.Break();
        }
Ejemplo n.º 4
0
        public void TestAccountDuplicatesWithFakes1()
        {
            var account1 = new Entity("account")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "Account One",
            };
            var account2 = new Entity("account")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "Account Two",
            };
            var account3 = new Entity("account")
            {
                Id       = Guid.NewGuid(),
                ["name"] = "Account Three",
            };
            var ctx = new XrmFakedContext();

            ctx.Initialize(new List <Entity> {
                account1, account2, account3
            });
            var wfContext = ctx.GetDefaultWorkflowContext();

            wfContext.MessageName = "Create";

            var input = new Dictionary <string, object>();

            input.Add("AccountReference", new EntityReference("account", account1.Id));


            var codeActivity = new DuplicateChecker();
            var result       = codeActivity.NumberOfDuplicates(ctx.GetOrganizationService(), "Name1");

            Assert.AreEqual(0, result);

            result = codeActivity.NumberOfDuplicates(ctx.GetOrganizationService(), "Account One");
            Assert.AreEqual(1, result);
        }
 public static void ClassInit(TestContext context)
 {
     Context = new XrmFakedContext();
     Context.ProxyTypesAssembly = Assembly.GetAssembly(typeof(ProxyTypesAssembly));
     Workflow = Context.GetDefaultWorkflowContext();
 }
 public static void ClassInit(TestContext context)
 {
     Context         = new XrmFakedContext();
     WorkflowContext = Context.GetDefaultWorkflowContext();
 }
Ejemplo n.º 7
0
 public UnitTest1()
 {
     fakedContext = new XrmFakedContext();
     wfContext    = fakedContext.GetDefaultWorkflowContext();
 }
Ejemplo n.º 8
0
        private void SetupMock()
        {
            FakedServices = MockOptions.FakedServices;

            FakedServices.AddHttpMock();

            //Setup Facked Context
            FakedContext = new XrmFakedContext
            {
                ProxyTypesAssembly = MockOptions.ProxyTypesAssembly
            };

            //Build system store
            foreach (Entity entity in MockOptions.Store)
            {
                AddFakeData(entity);
            }

            foreach (MockRelationship relationship in MockOptions.Relationships)
            {
                FakedContext.AddRelationship(relationship.RelationshipName, (XrmFakedRelationship)relationship);
            }

            var fakedService = FakedContext.GetFakedOrganizationService();

            foreach (AssociateRequest associationRequest in MockOptions.AssociateRequests)
            {
                fakedService.Execute(associationRequest);
            }

            if (typeof(TExecutionContext) == typeof(XrmFakedPluginExecutionContext))
            {
                XrmFakedPluginExecutionContext executionContext = FakedContext.GetDefaultPluginContext();
                executionContext.InputParameters = MockOptions.InputParameters;
                executionContext.CorrelationId   = Guid.NewGuid();
                executionContext.OperationId     = Guid.NewGuid();

                Guard.That(() => MockOptions.Message).IsNotNullOrEmpty();
                executionContext.MessageName = MockOptions.Message;

                Guard.That(() => MockOptions.UserId).IsNotEqual(Guid.Empty);
                executionContext.UserId = MockOptions.UserId;

                executionContext.PrimaryEntityName = MockOptions.PrimaryEntityName;

                FakedExecutionContext = executionContext as TExecutionContext;
            }
            else if (typeof(TExecutionContext) == typeof(XrmFakedWorkflowContext))
            {
                XrmFakedWorkflowContext executionContext = FakedContext.GetDefaultWorkflowContext();
                executionContext.InputParameters = MockOptions.InputParameters;
                executionContext.CorrelationId   = Guid.NewGuid();
                executionContext.OperationId     = Guid.NewGuid();

                Guard.That(() => MockOptions.Message).IsNotNullOrEmpty();
                executionContext.MessageName = MockOptions.Message;

                Guard.That(() => MockOptions.UserId).IsNotEqual(Guid.Empty);
                executionContext.UserId = MockOptions.UserId;

                executionContext.PrimaryEntityName = MockOptions.PrimaryEntityName;

                FakedExecutionContext = executionContext as TExecutionContext;
            }

            Guard.That(() => FakedExecutionContext).IsNotNull();

            Setup();
        }