public void SetUp()
        {
            this.mockery = new Mockery();
            this.validationFactory = this.mockery.NewMock<IValidationFactory>();

            IValidationResult validationResult = this.mockery.NewMock<IValidationResult>();
            Stub.On(validationResult).GetProperty("Valid").Will(Return.Value(true));
            Stub.On(this.validationFactory).Method("CreateValidationResult").With(true).Will(Return.Value(validationResult));

            this.testee = new TestValidationRule(this.validationFactory);
        }
        public void TestValidatePropertyWithError()
        {
            var rule = new TestValidationRule
            {
                Result = new ValidationRuleResult(true, "test"),
            };

            var vm = new TestViewModel
            {
                AProperty = 5,
            };

            vm.AddValidationRule(nameof(TestViewModel.AProperty), rule);

            string[] errors = vm.GetErrors(nameof(TestViewModel.AProperty)).ToArray();

            Assert.AreEqual(1, rule.RunCount);
            Assert.AreEqual(5, rule.LastRunValue);
            CollectionAssert.AreEqual(new string[] { "test" }, errors);
        }
        public void TestPropertyChangedNullNameConvertedToEmpty()
        {
            var rule = new TestValidationRule
            {
                Result = ValidationRuleResult.Success,
            };

            var vm = new TestViewModel();

            vm.AddValidationRule(null, rule);

            List <string> errorChanges = CaptureErrorChanges(vm, () =>
            {
                vm.PublicRaisePropertyChanged(null);
            });

            CollectionAssert.AreEqual(
                new[] { string.Empty },
                errorChanges
                );
        }
        public void TestRemoveEntityValidationRule()
        {
            var rule = new TestValidationRule
            {
                Result = new ValidationRuleResult(true, "test"),
            };

            var vm = new TestViewModel
            {
                AProperty = 5,
            };

            vm.AddValidationRule(null, rule);

            vm.RemoveValidationRule(null, rule);

            string[] errors = vm.GetErrors(null).ToArray();

            Assert.AreEqual(0, rule.RunCount);
            CollectionAssert.AreEqual(Array.Empty <string>(), errors);
        }
        public void TestPropertyChangeFiresErrorsChanged()
        {
            var rule = new TestValidationRule
            {
                Result = ValidationRuleResult.Success,
            };

            var vm = new TestViewModel
            {
                AProperty = 5,
            };

            vm.AddValidationRule(nameof(TestViewModel.AProperty), rule);

            List <string> errorChanges = CaptureErrorChanges(vm, () =>
            {
                vm.PublicRaisePropertyChanged(nameof(vm.AProperty));
            });

            CollectionAssert.AreEqual(
                new[] { nameof(TestViewModel.AProperty), string.Empty },
                errorChanges
                );
        }