/// <summary>
 /// Initializes a new instance of the <see cref="ObservableValidation{TViewModel,TValue,TProp}"/> class.
 /// </summary>
 /// <param name="viewModel">ViewModel instance.</param>
 /// <param name="viewModelProperty">ViewModel property.</param>
 /// <param name="observable">Observable that updates the view model property validity.</param>
 /// <param name="isValidFunc">Func to define if the viewModelProperty is valid or not.</param>
 /// <param name="messageFunc">Func to define the validation error message.</param>
 public ObservableValidation(
     TViewModel viewModel,
     Expression <Func <TViewModel, TProp> > viewModelProperty,
     IObservable <TValue> observable,
     Func <TViewModel, TValue, bool> isValidFunc,
     Func <TViewModel, TValue, bool, string> messageFunc)
     : base(viewModel, observable, isValidFunc, (vm, value, isValid) =>
            ValidationText.Create(messageFunc(vm, value, isValid))) =>
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelObservableValidation{TViewModel, TProperty1}"/> class.
 /// </summary>
 /// <param name="viewModel">ViewModel instance.</param>
 /// <param name="viewModelProperty">ViewModel property referenced in validityObservable.</param>
 /// <param name="validityObservable">Observable to define if the viewModel is valid or not.</param>
 /// <param name="message">Func to define the validation error message based on the viewModelProperty value.</param>
 public ModelObservableValidation(
     TViewModel viewModel,
     Expression <Func <TViewModel, TViewModelProp> > viewModelProperty,
     Func <TViewModel, IObservable <bool> > validityObservable,
     Func <TViewModel, string> message)
     : this(viewModel, viewModelProperty, validityObservable, (p, isValid) =>
            isValid ? ValidationText.Empty : ValidationText.Create(message(p)))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelObservableValidation{TViewModel, TProperty1}"/> class.
 /// </summary>
 /// <param name="viewModel">ViewModel instance.</param>
 /// <param name="viewModelProperty">ViewModel property referenced in validityObservable.</param>
 /// <param name="validityObservable">Observable to define if the viewModel is valid or not.</param>
 /// <param name="messageFunc">Func to define the validation error message based on the viewModel and validityObservable values.</param>
 public ModelObservableValidation(
     TViewModel viewModel,
     Expression <Func <TViewModel, TViewModelProp> > viewModelProperty,
     Func <TViewModel, IObservable <bool> > validityObservable,
     Func <TViewModel, bool, string> messageFunc)
     : this(viewModel, viewModelProperty, validityObservable, (vm, state) =>
            ValidationText.Create(messageFunc(vm, state)))
 {
 }
        public void CombineValidationTextEmptyReturnsTwoEmpty()
        {
            ValidationText vt = ValidationText.Create(new[] { ValidationText.Empty, ValidationText.Empty });

            Assert.NotSame(ValidationText.Empty, vt);
            Assert.Equal(2, vt.Count);

            // Calling Count() checks the enumeration returns no results, unlike the Count property.
#pragma warning disable CA1829 // Use Length/Count property instead of Count() when available
            Assert.Equal(2, vt.Count());
#pragma warning restore CA1829 // Use Length/Count property instead of Count() when available
            Assert.Equal(string.Empty, vt[0]);
            Assert.Equal(string.Empty, vt[1]);

            Assert.Equal("|", vt.ToSingleLine("|"));
        }
        public void CreateEmptyValidationTextEnumerableReturnsNone()
        {
            ValidationText vt = ValidationText.Create(Array.Empty <ValidationText>());

            Assert.Same(ValidationText.None, vt);
        }
        public void CreateEmptyStringEnumerableReturnsNone()
        {
            ValidationText vt = ValidationText.Create((IEnumerable <string>)Array.Empty <string>());

            Assert.Same(ValidationText.None, vt);
        }
        public void ParameterlessCreateReturnsNone()
        {
            ValidationText vt = ValidationText.Create();

            Assert.Same(ValidationText.None, vt);
        }
        public void CombineValidationTextEmptyAndNoneReturnsEmpty()
        {
            ValidationText vt = ValidationText.Create(new[] { ValidationText.None, ValidationText.Empty });

            Assert.Same(ValidationText.Empty, vt);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ValidationState"/> class.
 /// </summary>
 /// <param name="isValid">Determines if the property is valid or not.</param>
 /// <param name="text">Validation text.</param>
 public ValidationState(bool isValid, string text)
     : this(isValid, ValidationText.Create(text))
 {
 }
        public void CreateSingleStringEmptyReturnsEmpty()
        {
            ValidationText vt = ValidationText.Create((IEnumerable <string>) new[] { string.Empty });

            Assert.Same(ValidationText.Empty, vt);
        }
        public void CreateStringEmptyReturnsEmpty()
        {
            ValidationText vt = ValidationText.Create(string.Empty);

            Assert.Same(ValidationText.Empty, vt);
        }
        public void CreateNoneItemStringEnumerableReturnsNone()
        {
            ValidationText vt = ValidationText.Create(ValidationText.None);

            Assert.Same(ValidationText.None, vt);
        }
        public void CreateNoneItemValidationTextEnumerableReturnsNone()
        {
            ValidationText vt = ValidationText.Create(new[] { ValidationText.None });

            Assert.Same(ValidationText.None, vt);
        }
        public void CreateNullItemStringEnumerableReturnsNone()
        {
            ValidationText vt = ValidationText.Create((IEnumerable <string>) new string[] { null });

            Assert.Same(ValidationText.None, vt);
        }
        public void CreateNullValidationTextEnumerableReturnsNone()
        {
            ValidationText vt = ValidationText.Create((IEnumerable <ValidationText>)null);

            Assert.Same(ValidationText.None, vt);
        }
        public void CreateNullReturnsNone()
        {
            ValidationText vt = ValidationText.Create((string)null);

            Assert.Same(ValidationText.None, vt);
        }
        public void CreateValidationTextEmptyReturnsEmpty()
        {
            ValidationText vt = ValidationText.Create(new[] { ValidationText.Empty });

            Assert.Same(ValidationText.Empty, vt);
        }
        public void CombineValidationTextNoneReturnsNone()
        {
            ValidationText vt = ValidationText.Create(new[] { ValidationText.None, ValidationText.None });

            Assert.Same(ValidationText.None, vt);
        }
 public ValidationState(bool isValid, string text, IValidationComponent component)
     : this(isValid, ValidationText.Create(text), component)
 {
 }
 public CustomValidationState(bool isValid, string message)
 {
     IsValid = isValid;
     Text    = isValid ? ValidationText.Empty : ValidationText.Create(message);
 }