Exemple #1
0
        public void WhenTwoPropertiesInvolvedTheLastValidatedHasTheSharedErrorMessage()
        {
            // Prepare
            ConfigureThread();

            var purchasingPricePropertyName = FakeEditableViewModel.PurchasingPrice.PropertyMetadata.Name;
            var sellingPricePropertyName    = FakeEditableViewModel.SellingPrice.PropertyMetadata.Name;

            FakeEditableViewModel.SellingPrice.Value     = 30;
            FakeEditableViewModel.PurchasingPrice.Value  = 20;
            FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine
                                                           .AssertThatProperty <int>(vm => vm.PurchasingPrice).Is.LessThan(vm => vm.SellingPrice).Otherwise("ERROR");
            FakeFluentValidationEngine.BuildRules();

            // Act
            FakeEditableViewModel.ConfigureExpectedNumberOfPropertyValidation(2);
            FakeEditableViewModel.SellingPrice.Value    = 10;
            FakeEditableViewModel.PurchasingPrice.Value = 15;
            FakeEditableViewModel.WaitForPropertyValidationsToTerminate();

            // Verify
            var purchasingPriceErrors = FakeFluentValidationEngine.GetErrors(purchasingPricePropertyName);
            var sellingPriceErrors    = FakeFluentValidationEngine.GetErrors(sellingPricePropertyName);

            Assert.IsFalse(sellingPriceErrors.Any());
            Assert.IsNotNull(purchasingPriceErrors);
            Assert.IsTrue(purchasingPriceErrors.Count() == 1);
        }
Exemple #2
0
        public void CanBreakSimpleRuleThatComparesTwoProperties()
        {
            // Prepare
            ConfigureThread();
            FakeEditableViewModel.ConfigureExpectedNumberOfPropertyValidation(2);

            var propertyName = FakeEditableViewModel.PurchasingPrice.PropertyMetadata.Name;

            FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.PurchasingPrice).Is.LessThan(vm => vm.SellingPrice);
            FakeFluentValidationEngine.BuildRules();

            // Act
            FakeEditableViewModel.SellingPrice.Value    = 19;
            FakeEditableViewModel.PurchasingPrice.Value = 20;
            FakeEditableViewModel.WaitForPropertyValidationsToTerminate();

            // Verify
            VerifyThatRuleIsBroken(propertyName);
        }
Exemple #3
0
        public void CanBreakRuleThatUsesBetweenPropertiesOperator()
        {
            // Prepare
            ConfigureThread();
            FakeEditableViewModel.ConfigureExpectedNumberOfPropertyValidation(3);

            var propertyName = FakeEditableViewModel.Quantity.PropertyMetadata.Name;

            FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine
                                                           .AssertThatProperty <int>(vm => vm.Quantity).Is.BetweenPoperties(vm => vm.PurchasingPrice, vm => vm.SellingPrice);
            FakeFluentValidationEngine.BuildRules();

            // Act
            FakeEditableViewModel.PurchasingPrice.Value = 10;
            FakeEditableViewModel.SellingPrice.Value    = 20;
            FakeEditableViewModel.Quantity.Value        = 30;
            FakeEditableViewModel.WaitForPropertyValidationsToTerminate();

            // Verify
            VerifyThatRuleIsBroken(propertyName);
        }
Exemple #4
0
        public void WhenTwoPropertiesInvolvedErrorsOtherThanSharedOnesRemains()
        {
            // Prepare
            ConfigureThread();

            var purchasingPricePropertyName = FakeEditableViewModel.PurchasingPrice.PropertyMetadata.Name;
            var sellingPricePropertyName    = FakeEditableViewModel.SellingPrice.PropertyMetadata.Name;

            FakeEditableViewModel.SellingPrice.Value    = 30;
            FakeEditableViewModel.PurchasingPrice.Value = 20;

            FakeFluentValidationEngine.DefineRulesAction = () =>
            {
                // Selling price shoud be greater than 30
                FakeFluentValidationEngine.AssertThatProperty <int>(
                    vm => vm.SellingPrice).Is.GreaterThan(30);

                // Purchasing price shoud be less than Selling price
                FakeFluentValidationEngine
                .AssertThatProperty <int>(vm => vm.PurchasingPrice).Is.
                LessThan(vm => vm.SellingPrice);
            };

            FakeFluentValidationEngine.BuildRules();

            // Act
            FakeEditableViewModel.ConfigureExpectedNumberOfPropertyValidation(2);
            FakeEditableViewModel.SellingPrice.Value    = 10;
            FakeEditableViewModel.PurchasingPrice.Value = 15;
            FakeEditableViewModel.WaitForPropertyValidationsToTerminate();

            // Verify
            var purchasingPriceErrors = FakeFluentValidationEngine.GetErrors(purchasingPricePropertyName);
            var sellingPriceErrors    = FakeFluentValidationEngine.GetErrors(sellingPricePropertyName);

            Assert.IsNotNull(sellingPriceErrors);
            Assert.IsTrue(sellingPriceErrors.Count() == 1);
            Assert.IsNotNull(purchasingPriceErrors);
            Assert.IsTrue(purchasingPriceErrors.Count() == 1);
        }