예제 #1
0
        public void When_ContactIsBeingCreatedAndMandatoryFieldsAreSpecified_Expect_PluginNotToFail()
        {
            var ctx       = new XrmFakedContextWithProxy();
            var target    = TestContactBase;
            var pluginCtx = new CreatePreValidationSyncBase(ctx)
            {
                TargetEntity = target
            };

            var exc = Record.Exception(
                () =>
                ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Create>(
                    pluginCtx, string.Empty, string.Empty));

            Assert.Null(exc);
        }
예제 #2
0
        public void When_ContactIsBeingCreatedAndMandatoryFieldIsNotSpecified_Expect_PluginToFail(string fieldName)
        {
            var ctx    = new XrmFakedContextWithProxy();
            var target = TestContactBase;

            target[fieldName] = null;

            var pluginCtx = new CreatePreValidationSyncBase(ctx)
            {
                TargetEntity = target
            };

            var exc = Assert.Throws <InvalidPluginExecutionException>(
                () =>
                ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Contact.Create>(
                    pluginCtx, string.Empty, string.Empty));

            var expectedMessage = string.Format(CommonConstants.MandatoryFieldExceptionMessageTemplate, fieldName);

            Assert.Contains(expectedMessage, exc.Message);
        }
        // ReSharper disable once InconsistentNaming
        public void When_AccountNameIsNotShort_Expect_PluginNotToFail()
        {
            var ctx = new XrmFakedContext {
                ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account))
            };
            const string AccountName = "AAAA";
            var          target      = new Account
            {
                Name = AccountName
            };

            var pluginCtx = new CreatePreValidationSyncBase(ctx)
            {
                TargetEntity = target
            };

            var exc = Record.Exception(
                () =>
                ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Account.Create>(
                    pluginCtx, string.Empty, string.Empty));

            Assert.Null(exc);
        }
        // ReSharper disable once InconsistentNaming
        public void When_AccountNameIsTooShort_Expect_PluginToFail()
        {
            var ctx = new XrmFakedContext {
                ProxyTypesAssembly = Assembly.GetAssembly(typeof(Account))
            };
            const string AccountName = "AAA";
            var          target      = new Account
            {
                Name = AccountName
            };

            var pluginCtx = new CreatePreValidationSyncBase(ctx)
            {
                TargetEntity = target
            };

            var exc = Assert.Throws <InvalidPluginExecutionException>(
                () =>
                ctx.ExecutePluginWithConfigurations <AdvancedPluginDemo.Plugins.Bound.Account.Create>(
                    pluginCtx, string.Empty, string.Empty));
            var message = $"Account name \"{AccountName}\" is incorrect. It should contain at least 4 characters.";

            Assert.Equal(message, exc.Message);
        }