Inheritance: MvvmValidation.Tests.Fakes.ViewModelBase, IValidatable, INotifyDataErrorInfo
コード例 #1
0
		public void AddChildValidatableCollection_ChildCollectionIsNullOrEmpty_NoErrorsAreAdded()
		{
			TestUtils.ExecuteWithDispatcher((uiThreadDispatcher, completedAction) =>
			{
				// ARRANGE
				var parent = new ValidatableViewModel();

				parent.Validator.AddChildValidatableCollection(() => parent.Children);

				// ACT
				parent.Validator.ValidateAllAsync().ContinueWith(r1 =>
				{
					// VERIFY
					Assert.True(r1.Result.IsValid, "Validation must not fail");

					// ARRANGE
					parent.Children = new List<IValidatable>();

					// ACT
					parent.Validator.ValidateAllAsync().ContinueWith(r2 =>
					{
						// VERIFY
						Assert.True(r2.Result.IsValid, "Validation must not fail.");

						completedAction();
					});
				});
			});
		}
コード例 #2
0
        public void AddChildValidatableCollection_MoreThan64Items_DoesNotFail()
        {
            TestUtils.ExecuteWithDispatcher((uiThreadDispatcher, completedAction) =>
            {
                // ARRANGE
                var parent = new ValidatableViewModel();

                var children = new List<IValidatable>();

                for (int i = 0; i < 65; i++)
                {
                    var child = new ValidatableViewModel();
                    child.Validator.AddRule(RuleResult.Valid);

                    children.Add(child);
                }

                parent.Children = children;

                parent.Validator.AddChildValidatableCollection(() => parent.Children);

                // ACT
                parent.Validator.ValidateAllAsync().ContinueWith(result =>
                {
                    // VERIFY
                    uiThreadDispatcher.BeginInvoke(new Action(() =>
                    {
                        Assert.Null(result.Exception);
                        Assert.True(result.Result.IsValid, "Validation must pass");

                        completedAction();
                    }));
                });
            });
        }
コード例 #3
0
		public void AddChildValidatable_ChildValidatableIsNull_NoErrorsAreAdded()
		{
			TestUtils.ExecuteWithDispatcher((uiThreadDispatcher, completedAction) =>
			{
				// ARRANGE
				var parent = new ValidatableViewModel();

				parent.Validator.AddChildValidatable(() => parent.Child);

				// ACT
				parent.Validator.ValidateAllAsync().ContinueWith(result =>
				{
					// VERIFY
					Assert.True(result.Result.IsValid, "Validation must not fail");

					completedAction();
				});
			});
		}
コード例 #4
0
		public void AddChildValidatableCollection_AddsRuleThatExecutedValidationOnAllValidatableChildren()
		{
			TestUtils.ExecuteWithDispatcher((uiThreadDispatcher, completedAction) =>
			{
				// ARRANGE
				var parent = new ValidatableViewModel();
				var child1 = new ValidatableViewModel();
				var child2 = new ValidatableViewModel();
				parent.Children = new List<IValidatable>
				{
					child1,
					child2
				};

				child1.Validator.AddRequiredRule(() => child1.Foo, "Error1");
				child2.Validator.AddRule(RuleResult.Valid);

				parent.Validator.AddChildValidatableCollection(() => parent.Children);

				// ACT
				parent.Validator.ValidateAllAsync().ContinueWith(result =>
				{
					// VERIFY
					Assert.False(result.Result.IsValid, "Validation must fail");
					Assert.Equal("Error1", result.Result.ErrorList[0].ErrorText);

					completedAction();
				});
			});
		}
コード例 #5
0
		public void AddChildValidatable_AddsRuleWithProperTarget()
		{
			TestUtils.ExecuteWithDispatcher((uiThreadDispatcher, completedAction) =>
			{
				// ARRANGE
				var parent = new ValidatableViewModel();
				var child = new ValidatableViewModel();
				parent.Child = child;

				child.Validator.AddRequiredRule(() => child.Foo, "Error1");
				parent.Validator.AddChildValidatable(() => parent.Child);

				// ACT
				parent.Validator.ValidateAllAsync().ContinueWith(result =>
				{
					// VERIFY
					Assert.False(result.Result.IsValid, "Validation must fail");
					Assert.Equal("parent.Child", result.Result.ErrorList[0].Target);

					completedAction();
				});
			});
		}