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_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'.")));
        }
示例#3
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);
        }