예제 #1
0
        public void When_PluginStepRegisteredAsCreatePostOperationAsyncronous_Expect_CorrectValues()
        {
            // Arange
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            var id = Guid.NewGuid();

            // Act
            context.RegisterPluginStep <ValidatePipelinePlugin, Contact>("Create", ProcessingStepStage.Postoperation, ProcessingStepMode.Asynchronous);

            var newEntity = new Contact
            {
                Id = id
            };

            var service = context.GetOrganizationService();

            service.Create(newEntity);

            // Assert
            var trace = context.GetFakeTracingService().DumpTrace().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.Equal(5, trace.Length);
            Assert.Contains("Message Name: Create", trace);
            Assert.Contains("Stage: 40", trace);
            Assert.Contains("Mode: 1", trace);
            Assert.Contains($"Entity Logical Name: {Contact.EntityLogicalName}", trace);
            Assert.Contains($"Entity ID: {id}", trace);
        }
예제 #2
0
        public void When_PluginIsRegisteredForOtherEntity_And_OtherPluginCreatesAnAccount_Expect_AccountNumberIsNotSet()
        {
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            context.RegisterPluginStep <AccountNumberPlugin, Contact>("Create");

            context.ExecutePluginWith <CreateAccountPlugin>();

            var account = context.CreateQuery <Account>().FirstOrDefault();

            Assert.NotNull(account);
            Assert.False(account.Attributes.ContainsKey("accountnumber"));
        }
예제 #3
0
        public void When_AccountNumberPluginIsRegisteredAsPluginStep_And_OtherPluginCreatesAnAccount_Expect_AccountNumberIsSet()
        {
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            context.RegisterPluginStep <AccountNumberPlugin>("Create", ProcessingStepStage.Preoperation);

            context.ExecutePluginWith <CreateAccountPlugin>();

            var account = context.CreateQuery <Account>().FirstOrDefault();

            Assert.NotNull(account);
            Assert.True(account.Attributes.ContainsKey("accountnumber"));
            Assert.NotNull(account["accountnumber"]);
        }
예제 #4
0
        public void When_UsingFilteringAttributes_And_TheyMatch_Expect_PluginTriggers()
        {
            // Arange
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            var id = Guid.NewGuid();

            var entities = new List <Entity>
            {
                new Contact
                {
                    Id = id
                }
            };

            context.Initialize(entities);

            // Act
            context.RegisterPluginStep <ValidatePipelinePlugin, Contact>("Update", ProcessingStepStage.Preoperation, ProcessingStepMode.Synchronous, filteringAttributes: new string[] { "address1_city" });

            var updatedEntity = new Contact
            {
                Id            = id,
                Address1_City = "NY"
            };

            var service = context.GetOrganizationService();

            service.Update(updatedEntity);

            // Assert
            var trace = context.GetFakeTracingService().DumpTrace().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.Equal(5, trace.Length);
            Assert.Contains("Message Name: Update", trace);
            Assert.Contains("Stage: 20", trace);
            Assert.Contains("Mode: 0", trace);
            Assert.Contains($"Entity Logical Name: {Contact.EntityLogicalName}", trace);
            Assert.Contains($"Entity ID: {id}", trace);
        }
예제 #5
0
        public void When_UsingWeaklyTypedEntity_And_AccountNumberPlugin_Expect_AccountNumberIsSet()
        {
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            context.InitializeMetadata(typeof(Account).Assembly);
            context.RegisterPluginStep <AccountNumberPlugin, Account>("Create");
            context.ExecutePluginWith <CreateAccountPlugin>();

            var organizationService = context.GetOrganizationService();
            var accountId           = organizationService.Create(new Entity(Account.EntityLogicalName));

            Assert.NotEqual(Guid.Empty, accountId);
            var account = organizationService.Retrieve(Account.EntityLogicalName, accountId, new ColumnSet(true));

            Assert.True(account.Attributes.ContainsKey("accountnumber"));
        }
예제 #6
0
        public void When_PluginStepRegisteredAsCreatePostOperation_Entity_Available()
        {
            var context = new XrmFakedContext {
                UsePipelineSimulation = true
            };

            var target = new Account
            {
                Id   = Guid.NewGuid(),
                Name = "Original"
            };

            context.RegisterPluginStep <PostOperationUpdatePlugin>("Create");
            IOrganizationService serivce = context.GetOrganizationService();

            serivce.Create(target);

            var updatedAccount = serivce.Retrieve(Account.EntityLogicalName, target.Id, new ColumnSet(true)).ToEntity <Account>();

            Assert.Equal("Updated", updatedAccount.Name);
        }
예제 #7
0
        public void When_PluginStepRegisteredAsDeletePreOperationSyncronous_Expect_CorrectValues()
        {
            // Arange
            var context = new XrmFakedContext()
            {
                UsePipelineSimulation = true
            };

            var id = Guid.NewGuid();

            var entities = new List <Entity>
            {
                new Contact
                {
                    Id = id
                }
            };

            context.Initialize(entities);

            // Act
            context.RegisterPluginStep <ValidatePipelinePlugin, Contact>("Delete", ProcessingStepStage.Preoperation, ProcessingStepMode.Synchronous);

            var service = context.GetOrganizationService();

            service.Delete(Contact.EntityLogicalName, id);

            // Assert
            var trace = context.GetFakeTracingService().DumpTrace().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            Assert.Equal(5, trace.Length);
            Assert.Contains("Message Name: Delete", trace);
            Assert.Contains("Stage: 20", trace);
            Assert.Contains("Mode: 0", trace);
            Assert.Contains($"Entity Reference Logical Name: {Contact.EntityLogicalName}", trace);
            Assert.Contains($"Entity Reference ID: {id}", trace);
        }