public void It_returns_true_when_value1_is_greater_than_value2()
        {
            var row = new ValidatableStub
            {
                NumberInt = 1
            };

            Assert.IsTrue(_greaterThanEvaluator.Evaluate(row));
        }
        public void It_returns_false_when_value1_is_equal_or_lesser_than_value2()
        {
            var row = new ValidatableStub
            {
                NumberInt = 0
            };

            Assert.IsFalse(_greaterThanEvaluator.Evaluate(row));

            row.NumberInt = -1;

            Assert.IsFalse(_greaterThanEvaluator.Evaluate(row));
        }
        public void It_updates_HasErrors_property_based_on_prescence_of_rule_violations()
        {
            Assert.IsFalse(_validationService.HasErrors);

            const string validationName = "Stub";
            var stub = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub, "NumberInt");

            Assert.IsTrue(_validationService.HasErrors);

            _validationRuleMock.Setup(r => r.Evaluate(It.IsAny<ValidatableStub>())).Returns(true);

            _validateMock.Raise(v => v.ValidationTrigger += null, stub, "NumberInt");

            Assert.IsFalse(_validationService.HasErrors);
        }
        public void It_tries_to_remove_Rule_Notification_if_Rule_evaluates_to_true()
        {
            _validationRuleMock.Setup(r => r.Evaluate(It.IsAny<ValidatableStub>())).Returns(true);

            var stub = new ValidatableStub();

            _validateMock.Raise(v => v.ValidationTrigger += null, stub, "NumberInt");

            _notificationServiceMock.Verify(s => s.TryRemoveNotification(_validationRuleId, stub.Id));
        }
        public void It_raises_HasErrorsChanged_when_last_violation_is_resolved()
        {
            bool eventRaised;

            _validationService.HasErrorsChanged += state => eventRaised = true;

            const string validationName = "Stub";
            var stub1 = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub1, "NumberInt");

            var stub2 = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub2, "NumberInt");

            _validationRuleMock.Setup(r => r.Evaluate(It.IsAny<ValidatableStub>())).Returns(true);

            _validateMock.Raise(v => v.ValidationTrigger += null, stub1, "NumberInt");

            eventRaised = false;

            _validateMock.Raise(v => v.ValidationTrigger += null, stub2, "NumberInt");

            Assert.IsTrue(eventRaised);
        }
        public void It_raises_HasErrorsChanged_on_first_rule_violation()
        {
            var eventRaised = false;

            _validationService.HasErrorsChanged += state => eventRaised = true;

            const string validationName = "Stub";
            var stub = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub, "NumberInt");

            Assert.IsTrue(eventRaised);
        }
        public void It_does_not_raise_HasErrorsChanged_when_rule_complies_and_no_violations_present()
        {
            var eventRaised = false;

            _validationService.HasErrorsChanged += state => eventRaised = true;

            _validationRuleMock.Setup(r => r.Evaluate(It.IsAny<ValidatableStub>())).Returns(true);

            const string validationName = "Stub";
            var stub = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub, "NumberInt");

            Assert.IsFalse(eventRaised);
        }
        public void It_does_not_raise_HasErrorsChanged_on_second_rule_validation()
        {
            bool eventRaised;

            _validationService.HasErrorsChanged += state => eventRaised = true;

            const string validationName = "Stub";
            var stub1 = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub1, "NumberInt");

            eventRaised = false;

            var stub2 = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub2, "NumberInt");

            Assert.IsFalse(eventRaised);
        }
        public void It_adds_Notification_if_Rule_evaluates_to_false()
        {
            const string validationName = "Stub";
            var stub = new ValidatableStub(validationName);
            _validateMock.Raise(v => v.ValidationTrigger += null, stub, "NumberInt");

            // Test that AddNotification is called with right args
            _notificationServiceMock.Verify(s => s.AddNotification(_validationRuleId, stub.Id, validationName, _validationRuleMessage));
        }