public void Produces_BindingNotifications()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new IndeiValidationPlugin();
            var data = new Data { Maximum = 5 };
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.Value));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.Value), accessor);
            var result = new List<object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue(5, BindingPriority.LocalValue);
            validator.SetValue(6, BindingPriority.LocalValue);
            data.Maximum = 10;
            data.Maximum = 5;

            Assert.Equal(new[]
            {
                new BindingNotification(0),
                new BindingNotification(5),

                // Value is first signalled without an error as validation hasn't been updated.
                new BindingNotification(6),
                
                // Then the ErrorsChanged event is fired.
                new BindingNotification(new Exception("Must be less than Maximum"), BindingErrorType.DataValidationError, 6),

                // Maximum is changed to 10 so value is now valid.
                new BindingNotification(6),

                // And Maximum is changed back to 5.
                new BindingNotification(new Exception("Must be less than Maximum"), BindingErrorType.DataValidationError, 6),
            }, result);
        }
        public void Produces_Aggregate_BindingNotificationsx()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new DataAnnotationsValidationPlugin();
            var data = new Data();
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.PhoneNumber));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.PhoneNumber), accessor);
            var result = new List<object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue("123456", BindingPriority.LocalValue);
            validator.SetValue("abcdefghijklm", BindingPriority.LocalValue);

            Assert.Equal(new[]
            {
                new BindingNotification(null),
                new BindingNotification("123456"),
                new BindingNotification(
                    new AggregateException(
                        new ValidationException("The PhoneNumber field is not a valid phone number."),
                        new ValidationException("The field PhoneNumber must be a string or array type with a maximum length of '10'.")),
                    BindingErrorType.DataValidationError,
                    "abcdefghijklm"),
            }, result);
        }
        public void Produces_Aggregate_BindingNotificationsx()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new DataAnnotationsValidationPlugin();
            var data      = new Data();
            var accessor  = inpcAccessorPlugin.Start(new WeakReference <object>(data), nameof(data.PhoneNumber));
            var validator = validatorPlugin.Start(new WeakReference <object>(data), nameof(data.PhoneNumber), accessor);
            var result    = new List <object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue("123456", BindingPriority.LocalValue);
            validator.SetValue("abcdefghijklm", BindingPriority.LocalValue);

            Assert.Equal(3, result.Count);
            Assert.Equal(new BindingNotification(null), result[0]);
            Assert.Equal(new BindingNotification("123456"), result[1]);
            var errorResult = (BindingNotification)result[2];

            Assert.Equal(BindingErrorType.DataValidationError, errorResult.ErrorType);
            Assert.Equal("abcdefghijklm", errorResult.Value);
            var exceptions = ((AggregateException)(errorResult.Error)).InnerExceptions;

            Assert.True(exceptions.Any(ex =>
                                       ex.Message.Contains("The PhoneNumber field is not a valid phone number.")));
            Assert.True(exceptions.Any(ex =>
                                       ex.Message.Contains("The field PhoneNumber must be a string or array type with a maximum length of '10'.")));
        }
示例#4
0
        public void Produces_Aggregate_BindingNotificationsx()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new DataAnnotationsValidationPlugin();
            var data      = new Data();
            var accessor  = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.PhoneNumber));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.PhoneNumber), accessor);
            var result    = new List <object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue("123456", BindingPriority.LocalValue);
            validator.SetValue("abcdefghijklm", BindingPriority.LocalValue);

            Assert.Equal(new[]
            {
                new BindingNotification(null),
                new BindingNotification("123456"),
                new BindingNotification(
                    new AggregateException(
                        new ValidationException("The PhoneNumber field is not a valid phone number."),
                        new ValidationException("The field PhoneNumber must be a string or array type with a maximum length of '10'.")),
                    BindingErrorType.DataValidationError,
                    "abcdefghijklm"),
            }, result);
        }
        public void Produces_BindingNotifications()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new IndeiValidationPlugin();
            var data = new Data {
                Maximum = 5
            };
            var accessor  = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.Value));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.Value), accessor);
            var result    = new List <object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue(5, BindingPriority.LocalValue);
            validator.SetValue(6, BindingPriority.LocalValue);
            data.Maximum = 10;
            data.Maximum = 5;

            Assert.Equal(new[]
            {
                new BindingNotification(0),
                new BindingNotification(5),

                // Value is first signalled without an error as validation hasn't been updated.
                new BindingNotification(6),

                // Then the ErrorsChanged event is fired.
                new BindingNotification(new Exception("Must be less than Maximum"), BindingErrorType.DataValidationError, 6),

                // Maximum is changed to 10 so value is now valid.
                new BindingNotification(6),

                // And Maximum is changed back to 5.
                new BindingNotification(new Exception("Must be less than Maximum"), BindingErrorType.DataValidationError, 6),
            }, result);
        }
        public void Produces_Range_BindingNotificationsx()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new DataAnnotationsValidationPlugin();
            var data      = new Data();
            var accessor  = inpcAccessorPlugin.Start(new WeakReference <object>(data), nameof(data.Between5And10));
            var validator = validatorPlugin.Start(new WeakReference <object>(data), nameof(data.Between5And10), accessor);
            var result    = new List <object>();

            var errmsg = new RangeAttribute(5, 10).FormatErrorMessage(nameof(Data.Between5And10));

            validator.Subscribe(x => result.Add(x));
            validator.SetValue(3, BindingPriority.LocalValue);
            validator.SetValue(7, BindingPriority.LocalValue);
            validator.SetValue(11, BindingPriority.LocalValue);

            Assert.Equal(new[]
            {
                new BindingNotification(5),
                new BindingNotification(
                    new ValidationException(errmsg),
                    BindingErrorType.DataValidationError,
                    3),
                new BindingNotification(7),
                new BindingNotification(
                    new ValidationException(errmsg),
                    BindingErrorType.DataValidationError,
                    11),
            }, result);
        }
        public void Produces_Range_BindingNotificationsx()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new DataAnnotationsValidationPlugin();
            var data = new Data();
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.Between5And10));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.Between5And10), accessor);
            var result = new List<object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue(3, BindingPriority.LocalValue);
            validator.SetValue(7, BindingPriority.LocalValue);
            validator.SetValue(11, BindingPriority.LocalValue);

            Assert.Equal(new[]
            {
                new BindingNotification(5),
                new BindingNotification(
                    new ValidationException("The field Between5And10 must be between 5 and 10."),
                    BindingErrorType.DataValidationError,
                    3),
                new BindingNotification(7),
                new BindingNotification(
                    new ValidationException("The field Between5And10 must be between 5 and 10."),
                    BindingErrorType.DataValidationError,
                    11),
            }, result);
        }
示例#8
0
        public void Setting_Validating_Property_To_Invalid_Value_Returns_Failed_ValidationStatus()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new IndeiValidationPlugin();
            var data                 = new Data();
            var accessor             = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive), _ => { });
            IValidationStatus status = null;
            var validator            = validatorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive), accessor, s => status = s);

            validator.SetValue(-5, BindingPriority.LocalValue);

            Assert.False(status.IsValid);
        }
示例#9
0
        public void Setting_Non_Validating_Does_Not_Trigger_Validation()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new IndeiValidationPlugin();
            var data                 = new Data();
            var accessor             = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.NonValidated), _ => { });
            IValidationStatus status = null;
            var validator            = validatorPlugin.Start(new WeakReference(data), nameof(data.NonValidated), accessor, s => status = s);

            validator.SetValue(5, BindingPriority.LocalValue);

            Assert.Null(status);
        }
示例#10
0
        public void Setting_Validating_Property_To_Valid_Value_Returns_Successful_ValidationStatus()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new IndeiValidationPlugin();
            var data = new Data();
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive), _ => { });
            IValidationStatus status = null;
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive), accessor, s => status = s);

            validator.SetValue(5, BindingPriority.LocalValue);

            Assert.True(status.IsValid);
        }
示例#11
0
        public void Setting_Non_Validating_Does_Not_Trigger_Validation()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new IndeiValidationPlugin();
            var data = new Data();
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.NonValidated), _ => { });
            IValidationStatus status = null;
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.NonValidated), accessor, s => status = s);

            validator.SetValue(5, BindingPriority.LocalValue);

            Assert.Null(status);
        }
        public void Subscribes_And_Unsubscribes()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new IndeiValidationPlugin();
            var data = new Data { Maximum = 5 };
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.Value));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.Value), accessor);

            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
            var sub = validator.Subscribe(_ => { });
            Assert.Equal(1, data.ErrorsChangedSubscriptionCount);
            sub.Dispose();
            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
        }
        public void Subscribes_And_Unsubscribes()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new IndeiValidationPlugin();
            var data = new Data {
                Maximum = 5
            };
            var accessor  = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.Value));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.Value), accessor);

            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
            validator.Subscribe(_ => { });
            Assert.Equal(1, data.ErrorsChangedSubscriptionCount);
            validator.Unsubscribe();
            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
        }
示例#14
0
        public void Subscribes_And_Unsubscribes()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new IndeiValidationPlugin();
            var data = new Data {
                Maximum = 5
            };
            var accessor  = inpcAccessorPlugin.Start(new WeakReference <object>(data), nameof(data.Value));
            var validator = validatorPlugin.Start(new WeakReference <object>(data), nameof(data.Value), accessor);

            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
            validator.Subscribe(_ => { });
            Assert.Equal(1, data.ErrorsChangedSubscriptionCount);
            validator.Unsubscribe();
            // Forces WeakEvent compact
            Dispatcher.UIThread.RunJobs();
            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
        }
        public void Produces_BindingNotifications()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin = new ExceptionValidationPlugin();
            var data = new Data();
            var accessor = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive), accessor);
            var result = new List<object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue(5, BindingPriority.LocalValue);
            validator.SetValue(-2, BindingPriority.LocalValue);
            validator.SetValue(6, BindingPriority.LocalValue);

            Assert.Equal(new[]
            {
                new BindingNotification(0),
                new BindingNotification(5),
                new BindingNotification(new ArgumentOutOfRangeException("value"), BindingErrorType.DataValidationError),
                new BindingNotification(6),
            }, result);
        }
        public void Produces_BindingNotifications()
        {
            var inpcAccessorPlugin = new InpcPropertyAccessorPlugin();
            var validatorPlugin    = new ExceptionValidationPlugin();
            var data      = new Data();
            var accessor  = inpcAccessorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive));
            var validator = validatorPlugin.Start(new WeakReference(data), nameof(data.MustBePositive), accessor);
            var result    = new List <object>();

            validator.Subscribe(x => result.Add(x));
            validator.SetValue(5, BindingPriority.LocalValue);
            validator.SetValue(-2, BindingPriority.LocalValue);
            validator.SetValue(6, BindingPriority.LocalValue);

            Assert.Equal(new[]
            {
                new BindingNotification(0),
                new BindingNotification(5),
                new BindingNotification(new ArgumentOutOfRangeException("value"), BindingErrorType.DataValidationError),
                new BindingNotification(6),
            }, result);
        }
示例#17
0
 public void InpcAccessorStart()
 {
     _inpcPlugin.Start(_targetWeakRef, nameof(AccessorTestObject.Test));
 }