Exemplo n.º 1
0
        public override void Test(Action <IXrmContext, IKernel> testCriteria)
        {
            TPlugin pluginInstance = (TPlugin)Activator.CreateInstance(typeof(TPlugin), FakedServices, SetupMockServices);

            Assert.DoesNotThrow(() => FakedContext.ExecutePluginWith(FakedExecutionContext, pluginInstance));
            testCriteria(FakedContext, FakedServices);
            FakedServices.RemoveHttpMock();
        }
        public override void Test(Action <IXrmContext, IKernel> testCriteria)
        {
            TCodeActivity codeActivityInstance = (TCodeActivity)Activator.CreateInstance(typeof(TCodeActivity), FakedServices, SetupMockServices);

            Assert.DoesNotThrow(() => FakedContext.ExecuteCodeActivity(FakedExecutionContext, null, codeActivityInstance));
            testCriteria(FakedContext, FakedServices);
            FakedServices.RemoveHttpMock();
        }
Exemplo n.º 3
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();
        }