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); }
public void CanBreakRuleThatUsesIsNotBetweenOperator() { // Prepare ConfigureThread(); var propertyName = FakeEditableViewModel.Quantity.PropertyMetadata.Name; FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.Quantity).IsNot.BetweenValues(15, 25); FakeFluentValidationEngine.BuildRules(); // Act FakeEditableViewModel.Quantity.Value = 20; FakeEditableViewModel.WaitForPropertyValidationsToTerminate(); // Verify VerifyThatRuleIsBroken(propertyName); }
public void CanBreakSimpleRule() { // Prepare ConfigureThread(); var propertyName = FakeEditableViewModel.PurchasingPrice.PropertyMetadata.Name; FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.PurchasingPrice).Is.GreaterThan(20); FakeFluentValidationEngine.BuildRules(); // Act FakeEditableViewModel.PurchasingPrice.Value = 20; FakeEditableViewModel.WaitForPropertyValidationsToTerminate(); // Verify VerifyThatRuleIsBroken(propertyName); }
public void CanBreakRuleWithOrConjunction() { // Prepare ConfigureThread(); var propertyName = FakeEditableViewModel.Quantity.PropertyMetadata.Name; FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.Quantity) .Is.EqualTo(20).Or.Is.EqualTo(30); FakeFluentValidationEngine.BuildRules(); // Act FakeEditableViewModel.Quantity.Value = 25; FakeEditableViewModel.WaitForPropertyValidationsToTerminate(); // Verify VerifyThatRuleIsBroken(propertyName); }
public void CanBreakRuleWithAndConjunction() { // Prepare ConfigureThread(); FakeEditableViewModel.ConfigureExpectedNumberOfPropertyValidation(2); var propertyName = FakeEditableViewModel.PurchasingPrice.PropertyMetadata.Name; FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.PurchasingPrice) .Is.LessThan(vm => vm.SellingPrice).And.Is.EqualTo(20); FakeFluentValidationEngine.BuildRules(); // Act FakeEditableViewModel.SellingPrice.Value = 21; FakeEditableViewModel.PurchasingPrice.Value = 19; FakeEditableViewModel.WaitForPropertyValidationsToTerminate(); // Verify VerifyThatRuleIsBroken(propertyName); }
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); }
public void CanBreakSimpleRuleWithCustomMessage() { // Prepare ConfigureThread(); const string erroMessage = "PurchasingPrice must be greater that 20"; var propertyName = FakeEditableViewModel.PurchasingPrice.PropertyMetadata.Name; FakeFluentValidationEngine.DefineRulesAction = () => FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.PurchasingPrice) .Is.GreaterThan(20).Otherwise(erroMessage); FakeFluentValidationEngine.BuildRules(); // Act FakeEditableViewModel.PurchasingPrice.Value = 20; FakeEditableViewModel.WaitForPropertyValidationsToTerminate(); // Verify Assert.IsNotNull(FakeFluentValidationEngine.GetErrors(propertyName)); Assert.IsTrue(FakeFluentValidationEngine.GetErrors(propertyName).Any()); Assert.AreEqual(erroMessage, FakeFluentValidationEngine.GetErrors(propertyName).ToList() [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); }
public void CanDefineManyRulesOnOneProperty() { // Prepare ConfigureThread(); var propertyName = FakeEditableViewModel.Quantity.PropertyMetadata.Name; FakeFluentValidationEngine.DefineRulesAction = () => { FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.Quantity).Is.GreaterThan(20); FakeFluentValidationEngine.AssertThatProperty <int>(vm => vm.Quantity).Is.EqualTo(40); }; FakeFluentValidationEngine.BuildRules(); // Act FakeEditableViewModel.Quantity.Value = 15; FakeEditableViewModel.WaitForPropertyValidationsToTerminate(); // Verify // if this is satisfied, that means that rules were broken Assert.IsNotNull(FakeFluentValidationEngine.GetErrors(propertyName)); Assert.IsTrue(FakeFluentValidationEngine.GetErrors(propertyName).Count() == 2); }