public void TestExecuteAsyncWithValidValidator()
        {
            var fakeModel = new FakeValidationTargetModel();
            var mockValidator = ValidatorExecutorTestHelper.CreateMockValidator(true, Guid.NewGuid());
            var validators = new List<ValidatorContainer<FakeValidationTargetModel>>
            {
                ValidatorExecutorTestHelper.CreateValidatorContainer(mockValidator.Object, 0)
            };
            var target = new PlainValidatorExecutor<FakeValidationTargetModel>();

            var validationResults = target.ExecuteAsync(fakeModel, validators).Result;

            Assert.IsNotNull(validationResults);
            var failedValidatorTask = validationResults.SingleOrDefault();
            Assert.IsNotNull(failedValidatorTask);
            var failedValidator = failedValidatorTask;
            Assert.IsNotNull(failedValidator);
            Assert.IsTrue(failedValidator.IsValid());
            mockValidator.Verify();
        }
        public void TestExecuteWithTwoAsyncValidatorsInvalidValidatorWithHighPriority()
        {
            var fakeModel = new FakeValidationTargetModel();
            var failedValidatorId = Guid.NewGuid();
            var firstMockValidator = ValidatorExecutorTestHelper.CreateMockValidator(false, Guid.NewGuid());
            var secondMockValidator = ValidatorExecutorTestHelper.CreateMockValidator(false, failedValidatorId);
            var validators = new List<ValidatorContainer<FakeValidationTargetModel>>
            {
                ValidatorExecutorTestHelper.CreateValidatorContainer(firstMockValidator.Object, 1),
                ValidatorExecutorTestHelper.CreateValidatorContainer(secondMockValidator.Object, 0)
            };

            var target = new PlainValidatorExecutor<FakeValidationTargetModel>();

            IEnumerable<ValidationResult> validationResults = target.ExecuteAsync(fakeModel, validators).Result;

            Assert.IsNotNull(validationResults);
            var failedValidator = validationResults.FirstOrDefault();
            Assert.IsNotNull(failedValidator);
            Assert.IsFalse(failedValidator.IsValid());
            Assert.AreEqual(failedValidatorId, failedValidator.Id);
            firstMockValidator.Verify();
            secondMockValidator.Verify();
        }
        public void TestExecuteAsyncWithNullModel()
        {
            var validators = new List<ValidatorContainer<FakeValidationTargetModel>>();
            var target = new PlainValidatorExecutor<FakeValidationTargetModel>();

            var validationResults = target.ExecuteAsync(null, validators).Result;

            // expected exception.
        }
        public void TestExecuteAsyncWithNullCollection()
        {
            var target = new PlainValidatorExecutor<FakeValidationTargetModel>();

            var validationResults = target.ExecuteAsync(new FakeValidationTargetModel(), null).Result;

            // expected exception.
        }
        public void TestExecuteAsyncWithEmptyValidatorsCollection()
        {
            var fakeModel = new FakeValidationTargetModel();
            var validators = new List<ValidatorContainer<FakeValidationTargetModel>>();
            var target = new PlainValidatorExecutor<FakeValidationTargetModel>();

            var validationResults = target.ExecuteAsync(fakeModel, validators).Result;

            Assert.IsNotNull(validationResults);
            Assert.IsFalse(validationResults.Any());
        }