Esempio n. 1
0
        public void AbstractViewModel_with_no_validation_service_always_validates_to_true()
        {
            var sut     = new SampleTestViewModel();
            var isValid = sut.Validate();

            Assert.IsTrue(isValid);
        }
Esempio n. 2
0
        public void AbstractViewModel_with_no_validation_service_has_no_errors()
        {
            var sut = new SampleTestViewModel();

            sut.Validate();
            var errors = sut.ValidationErrors;

            Assert.IsTrue(errors.Count == 0);
        }
Esempio n. 3
0
        public void AbstractViewModel_When_merge_errors_changes_it_should_not_fail()
        {
            var sut = new SampleTestViewModel();
            var svc = new DataAnnotationValidationService <SampleTestViewModel>(sut);

            sut.ValidateUsing(svc, forceIsValidationEnabledTo: true);

            sut.Validate();
            svc.MergeValidationErrors = !svc.MergeValidationErrors;
        }
Esempio n. 4
0
        public void AbstractViewModel_with_validation_service_should_generate_expected_errors()
        {
            var sut = new SampleTestViewModel();

            sut.ValidateUsing(
                new DataAnnotationValidationService <SampleTestViewModel>(sut));
            sut.Validate();
            var errors = sut.ValidationErrors;

            Assert.IsTrue(errors.Count == 1);
        }
Esempio n. 5
0
        public void AbstractMementoViewModel_When_Validate_and_Validation_is_suspended_Validated_event_should_not_be_raised()
        {
            Boolean raised = false;

            var sut = new SampleTestViewModel();
            var svc = new DataAnnotationValidationService <SampleTestViewModel>(sut);

            sut.ValidateUsing(svc, forceIsValidationEnabledTo: true);
            sut.Validated += (s, e) => raised = true;

            using (svc.SuspendValidation())  //so that we can change a property without triggering the validation process
            {
                sut.Validate();
            }

            Assert.IsFalse(raised);
        }
Esempio n. 6
0
        public void AbstractViewModel_when_validating_entire_entity_PropertyChanged_for_IsValid_property_should_be_raised()
        {
            bool raised = false;

            var sut = new SampleTestViewModel();

            sut.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "IsValid")
                {
                    raised = true;
                }
            };

            sut.ValidateUsing(
                new DataAnnotationValidationService <SampleTestViewModel>(sut),
                forceIsValidationEnabledTo: true);

            var isValid = sut.Validate();

            Assert.IsFalse(isValid);
            Assert.IsTrue(raised);
        }