Ejemplo n.º 1
0
        public void Test(IIndexer indexer)
        {
            var releases = _feedFetcher.FetchRss(indexer);

            if (releases.Any()) return;

            try
            {
                var url = indexer.RecentFeed.First();
                var xml = _httpProvider.DownloadString(url);

                NewznabPreProcessor.Process(xml, url);
            }
            catch (ApiKeyException apiKeyException)
            {
                _logger.Warn("Indexer returned result for Newznab RSS URL, API Key appears to be invalid");

                var apiKeyFailure = new ValidationFailure("ApiKey", "Invalid API Key");
                throw new ValidationException(new List<ValidationFailure> { apiKeyFailure }.ToArray());
            }
            catch (Exception ex)
            {
                _logger.Warn("Indexer doesn't appear to be Newznab based");

                var failure = new ValidationFailure("Url", "Invalid Newznab URL entered");
                throw new ValidationException(new List<ValidationFailure> { failure }.ToArray());
            }
        }
Ejemplo n.º 2
0
        public ValidationFailure ValidateAnimeFilename(SampleResult sampleResult)
        {
            var validationFailure = new ValidationFailure("AnimeEpisodeFormat", ERROR_MESSAGE);
            var parsedEpisodeInfo = Parser.Parser.ParseTitle(sampleResult.FileName);

            if (parsedEpisodeInfo == null)
            {
                return validationFailure;
            }

            if (parsedEpisodeInfo.AbsoluteEpisodeNumbers.Any())
            {
                if (!parsedEpisodeInfo.AbsoluteEpisodeNumbers.First().Equals(sampleResult.Episodes.First().AbsoluteEpisodeNumber))
                {
                    return validationFailure;
                }

                return null;
            }

            if (!ValidateSeasonAndEpisodeNumbers(sampleResult.Episodes, parsedEpisodeInfo))
            {
                return validationFailure;
            }

            return null;
        }
Ejemplo n.º 3
0
        public ValidationFailure ValidateDailyFilename(SampleResult sampleResult)
        {
            var validationFailure = new ValidationFailure("DailyEpisodeFormat", ERROR_MESSAGE);
            var parsedEpisodeInfo = Parser.Parser.ParseTitle(sampleResult.FileName);

            if (parsedEpisodeInfo == null)
            {
                return validationFailure;
            }

            if (parsedEpisodeInfo.IsDaily)
            {
                if (!parsedEpisodeInfo.AirDate.Equals(sampleResult.Episodes.Single().AirDate))
                {
                    return validationFailure;
                }

                return null;
            }

            if (!ValidateSeasonAndEpisodeNumbers(sampleResult.Episodes, parsedEpisodeInfo))
            {
                return validationFailure;
            }

            return null;
        }
Ejemplo n.º 4
0
 private void AddExceptionToModelErrors(ActionExecutedContext filterContext, Exception exception)
 {
     var validationFailure = new ValidationFailure("", exception.Message);
     var validationException = new ValidationException(new[] { validationFailure });
     new Validation.ValidationExceptionHandler()
         .AddToModel(filterContext, validationException);
 }
Ejemplo n.º 5
0
        public NzbDroneValidationFailure(ValidationFailure validationFailure)
            : base(validationFailure.PropertyName, validationFailure.ErrorMessage, validationFailure.AttemptedValue)
        {
            CustomState = validationFailure.CustomState;
            var state = validationFailure.CustomState as NzbDroneValidationState;

            IsWarning = state != null && state.IsWarning;
        }
 public IEnumerable<ValidationFailure> Validate(ValidationContext context)
 {
     var rawValue = _propertyChain.GetValue(context.InstanceToValidate);
     var validationFailure = new ValidationFailure(_propertyChain.Name, string.Format("{0} must be at least {1} characters", context.PropertyChain.BuildPropertyName(_propertyChain.Name).ToPrettyString(), _length));
     if (rawValue != null && rawValue.ToString().Length < _length)
     {
         yield return validationFailure;
     }
 }
        public IEnumerable<ValidationFailure> Validate(ValidationContext context)
        {
            var rawValue = _propertyChain.GetValue(context.InstanceToValidate);
            if (rawValue == null) yield break;

            var value = (DateTime) rawValue;
            var validationFailure = new ValidationFailure(_propertyChain.Name, "{0} cannot be in the future".ToFormat(context.PropertyChain.BuildPropertyName(_propertyChain.Name).ToPrettyString()));

            if (value > DateTime.UtcNow)
            {
                yield return validationFailure;
            }
        }
        public ValidationError(string id,
            ValidationFailure validationFailure)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentOutOfRangeException("id");
            }

            if (validationFailure == null)
            {
                throw new ArgumentNullException("validationFailure");
            }

            Id = id;
            ValidationFailure = validationFailure;
        }
Ejemplo n.º 9
0
        public ValidationFailure ValidateStandardFilename(SampleResult sampleResult)
        {
            var validationFailure = new ValidationFailure("StandardEpisodeFormat", ERROR_MESSAGE);
            var parsedEpisodeInfo = Parser.Parser.ParseTitle(sampleResult.FileName);

            if (parsedEpisodeInfo == null)
            {
                return validationFailure;
            }

            if (!ValidateSeasonAndEpisodeNumbers(sampleResult.Episodes, parsedEpisodeInfo))
            {
                return validationFailure;
            }

            return null;
        }
        public static ValidationMessage Create(ValidationFailure validationFailure)
        {
            var result = new ValidationMessage
            {
                Category = ValidationMessageCategories.Error,
                PropertyName = validationFailure.PropertyName,
                Message = validationFailure.ErrorMessage,
                AttemptedValue = validationFailure.AttemptedValue
            };

            if (validationFailure.CustomState is ValidationCodes)
            {
                result.Code = (ValidationCodes)validationFailure.CustomState;
            }
            else
            {
                result.Code = ValidationCodes.FieldLevelValidationBroken;
            }

            return result;
        }
Ejemplo n.º 11
0
            public void GivenAValidId_ReturnsGenre()
            {
                const int aValidId = 1;
                var genres = new List<Genre>
                                 {
                                     new Genre
                                         {
                                             Id = aValidId
                                         }
                                 };
                var dbSet = new FakeDbSet<Genre>();
                genres.ForEach(genre => dbSet.Add(genre));

                var entitiesContext = A.Fake<IEntitiesContext>();
                A.CallTo(() => entitiesContext.Set<Genre>()).Returns(dbSet);

                var fakeValidator = A.Fake<IValidator>();
                var failure = new ValidationFailure("Id", "error");
                var failures = new List<ValidationFailure> { failure };
                A.CallTo(() => fakeValidator.Validate(A<Genre>.Ignored)).Returns(new ValidationResult(failures));

                IValidatorFactory factory = A.Fake<IValidatorFactory>();
                //var hasPermissionToGet = new HasPermissionToGet(fakeRepo);

                //A.CallTo(() => factory.GetValidator<HasPermissionToGet>()).Returns<HasPermissionToGet>(hasPermissionToGet as IValidator<HasPermissionToGet>);

                var fakeMapping = A.Fake<IMappingEngine>();

                var repo = new EntityRepository<Genre>(entitiesContext);
                var genreService = new GenreService(repo, factory, fakeMapping);

                Genre result = genreService.GetGenre(aValidId);

                result.Should().NotBeNull();
            }
Ejemplo n.º 12
0
 public ApiError(ValidationFailure validationFailure)
 {
     Property = validationFailure.PropertyName;
     Message = validationFailure.ErrorMessage;
 }
Ejemplo n.º 13
0
        public void Given_invalid_viewModel_When_Validate_Then_MarkChecklistWithCompleteFailureAttemptRequest_parameters_are_set()
        {
            // Given
            var target = GetTarget();
            var model = GetValidViewModel();
            MarkChecklistWithCompleteFailureAttemptRequest passedRequest = null;

            var validationFailure1 = new ValidationFailure("prop1", "error 1");

            var validationResult = new ValidationResult(new List<ValidationFailure>
                                                        {
                                                            validationFailure1
                                                        });

            _fireRiskAssessmentChecklistService
                .Setup(x => x.ValidateFireRiskAssessmentChecklist(It.IsAny<ValidateCompleteFireRiskAssessmentChecklistRequest>()))
                .Returns(validationResult);

            _fireRiskAssessmentChecklistService
                .Setup(x => x.MarkChecklistWithCompleteFailureAttempt(It.IsAny<MarkChecklistWithCompleteFailureAttemptRequest>()))
                .Callback<MarkChecklistWithCompleteFailureAttemptRequest>(y => passedRequest = y);

            // When
            target.Validate(model);

            // Then
            Assert.That(passedRequest.ChecklistId, Is.EqualTo(model.ChecklistId));
            Assert.IsNotNull(passedRequest.UserId);
            Assert.That(passedRequest.CompanyId, Is.EqualTo(TestControllerHelpers.CompanyIdAssigned));
        }
Ejemplo n.º 14
0
        public void Given_invalid_viewModel_When_Validate_Then_ask_service_to_mark_as_complete_attempted()
        {
            // Given
            var target = GetTarget();
            var model = GetValidViewModel();

            var validationFailure1 = new ValidationFailure("prop1", "error 1");

            var validationResult = new ValidationResult(new List<ValidationFailure>
                                                        {
                                                            validationFailure1
                                                        });

            _fireRiskAssessmentChecklistService
                .Setup(x => x.ValidateFireRiskAssessmentChecklist(It.IsAny<ValidateCompleteFireRiskAssessmentChecklistRequest>()))
                .Returns(validationResult);

            _fireRiskAssessmentChecklistService
                .Setup(x => x.MarkChecklistWithCompleteFailureAttempt(It.IsAny<MarkChecklistWithCompleteFailureAttemptRequest>()));

            // When
            target.Validate(model);

            // Then
            _fireRiskAssessmentChecklistService.Verify(x => x.MarkChecklistWithCompleteFailureAttempt(It.IsAny<MarkChecklistWithCompleteFailureAttemptRequest>()));
        }
Ejemplo n.º 15
0
        public void Given_invalid_viewModel_When_Validate_Then_return_json_object_with_list_of_errors_in_validation_result()
        {
            // Given
            var target = GetTarget();
            var model = GetValidViewModel();

            var validationFailure1 = new ValidationFailure("prop1", "error 1");
            var validationFailure2 = new ValidationFailure("prop2", "error 2");
            var validationFailure3 = new ValidationFailure("prop3", "error 3");

            var validationResult = new ValidationResult(new List<ValidationFailure>
                                                        {
                                                            validationFailure1,
                                                            validationFailure2,
                                                            validationFailure3
                                                        });

            _fireRiskAssessmentChecklistService
                .Setup(x => x.ValidateFireRiskAssessmentChecklist(It.IsAny<ValidateCompleteFireRiskAssessmentChecklistRequest>()))
                .Returns(validationResult);

            // When
            dynamic result = target.Validate(model);
            // Then

            Assert.That(
                result.Data.Errors[0].PropertyName,
                Is.EqualTo(validationFailure1.PropertyName));
            Assert.That(
                result.Data.Errors[0].ErrorMessage,
                Is.EqualTo(validationFailure1.ErrorMessage));

            Assert.That(
                result.Data.Errors[1].PropertyName,
                Is.EqualTo(validationFailure2.PropertyName));
            Assert.That(
                result.Data.Errors[1].ErrorMessage,
                Is.EqualTo(validationFailure2.ErrorMessage));

            Assert.That(
                result.Data.Errors[2].PropertyName,
                Is.EqualTo(validationFailure3.PropertyName));
            Assert.That(
                result.Data.Errors[2].ErrorMessage,
                Is.EqualTo(validationFailure3.ErrorMessage));
        }