Exemplo n.º 1
0
        public void ValidateUrlTest()
        {
            _urlValidator = new UrlValidator();

            Assert.AreEqual(_urlValidator.Validate(_hotels[0]).Uri, _hotels[0].Uri);
            Assert.AreEqual(_urlValidator.Validate(_hotels[2]).Uri, null);
        }
Exemplo n.º 2
0
        public void Validation_fails_if_url_is_invalid(string url)
        {
            var exception = Assert.Throws <UrlValidationException>(
                () => _sut.Validate(url));

            Assert.Equal(exception.Message,
                         string.Format(ValidationMessages.IncorrectUrl, url));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Performs validation of the user's input
 /// </summary>
 /// <returns>True if the input values are OK, otherwise false.</returns>
 private bool ValidateForm()
 {
     if (txtHostAddress.Text == String.Empty)
     {
         MessageBox.Show("You must supply the address of the host you wish to add to the banned list!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         txtHostAddress.Focus();
         return(false);
     }
     try
     {
         if (validator.Validate(txtHostAddress.Text))
         {
             //it is a fully qualified Url, let's get its hostname
             Uri uri = new Uri(txtHostAddress.Text);
             txtHostAddress.Text = uri.Host;
         }
         else
         {
             //it's not a fully qualified Url. let's check if it's a valid hostname.
             if (Uri.CheckHostName(txtHostAddress.Text) == UriHostNameType.Unknown)
             {
                 MessageBox.Show("The host name you supplied is not valid!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 txtHostAddress.Focus();
                 return(false);
             }
         }
     }
     catch
     {
         MessageBox.Show("The host name you supplied is not valid!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         txtHostAddress.Focus();
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
        public void Expect_valid_url_to_be_ok()
        {
            var validator = new UrlValidator();

            //Topper was here again
            validator.Validate("http://www.dn.se");
        }
Exemplo n.º 5
0
        public async Task <UserIdentificationResultDto> IdentifyUser(IdentityUrlDto urlDto)
        {
            var url = await urlRepository.GetByIdAsync(id : urlDto.Id);

            var urlValidator        = new UrlValidator();
            var urlValidationResult = urlValidator.Validate(url);

            UserIdentificationResultDto userIdentificationResult;

            if (!urlValidationResult.IsValid)
            {
                userIdentificationResult            = mapper.Map <UserIdentificationResultDto>(urlValidationResult);
                userIdentificationResult.IsUrlValid = false;
                return(userIdentificationResult);
            }

            if (url.NumberOfRuns.HasValue && url.NumberOfRuns > 0)
            {
                --url.NumberOfRuns;
                urlRepository.Update(url);
                await unitOfWork.SaveAsync();
            }

            var intervieweeNameValidator        = new UrlIntervieweeNameValidator(urlDto.IntervieweeName);
            var intervieweeNameValidationResult = intervieweeNameValidator.Validate(url);

            userIdentificationResult            = mapper.Map <UserIdentificationResultDto>(intervieweeNameValidationResult);
            userIdentificationResult.IsUrlValid = true;
            return(userIdentificationResult);
        }
Exemplo n.º 6
0
        public async Task <UrlValidationResultDto> CheckIsUrlValid(int urlId)
        {
            var url = await urlRepository.GetByIdAsync(id : urlId);

            var urlValidator = new UrlValidator();
            var result       = urlValidator.Validate(url);

            return(mapper.Map <UrlValidationResultDto>(result));
        }
Exemplo n.º 7
0
        public static bool Create(Address address, List <string> urlsCollection)
        {
            bool urlExists = UrlValidator.Validate(address.LongUrl);

            if (urlExists)
            {
                address.ShortUrl     = UrlGenerator.Generate(urlsCollection);
                address.CreationData = DateTime.Now.ToString("yyyy-MM-dd h:mm tt");
            }
            return(urlExists);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Validates the user's input
 /// </summary>
 /// <returns>True if the user input is OK, otherwise false.</returns>
 private bool ValidateForm()
 {
     txtUrl.Text = txtUrl.Text.Trim();
     if (txtUrl.Text == String.Empty)
     {
         MessageBox.Show("You must supply a new Url Address to insert!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         txtUrl.Focus();
         return(false);
     }
     if (!validator.Validate(txtUrl.Text))
     {
         MessageBox.Show("The Url Address you provided is not valid!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         txtUrl.Focus();
         return(false);
     }
     return(true);
 }
Exemplo n.º 9
0
        private void ValidateUrl(UrlViewModel urlViewModel)
        {
            var errors = new List <string>();

            var validator = new UrlValidator();
            var result    = validator.Validate(urlViewModel);

            errors.AddRange(result.Errors.Select(e => e.ErrorMessage));

            if (urls.FirstOrDefault(u => u.ShortUrl == urlViewModel.ShortUrl) != null)
            {
                errors.Add("Alias already exists");
            }

            if (errors.Count > 0)
            {
                throw new UrlValidationException("One or more errors occured", errors);
            }
        }
Exemplo n.º 10
0
        private async Task ValidateUrl(UrlViewModel urlViewModel)
        {
            var errors = new List <string>();

            var validator = new UrlValidator();
            var result    = validator.Validate(urlViewModel);

            errors.AddRange(result.Errors?.Select(e => e.ErrorMessage));

            if (_cacheService.FindItem <string>(urlViewModel.ShortUrl) != null ||
                await _urlRepository.FindAsync(urlViewModel.ShortUrl) != null)
            {
                errors.Add("Alias already exists");
            }

            if (errors.Count > 0)
            {
                throw new UrlValidationException("One or more errors occured", errors);
            }
        }
        public void Then_correct_errors_are_returned(string input, bool isValid)
        {
            var validator = new UrlValidator
            {
                ValidationDefinition = new ValidationDefinition()
                {
                    ErrorMessage = "Not a valid Url",
                    Name         = "Url"
                }
            };

            var question = new Question {
                QuestionId = "Q1"
            };
            var errors = validator.Validate(question, new Answer {
                Value = input, QuestionId = question.QuestionId
            });

            (errors.Count is 0).Should().Be(isValid);
        }
Exemplo n.º 12
0
        public void Expect_empty_url_to_be_invalid()
        {
            var validator = new UrlValidator();

            validator.Validate("");
        }
Exemplo n.º 13
0
        public void Expect_valid_url_to_be_ok()
        {
            var validator = new UrlValidator();

            validator.Validate("http://www.dn.se");
        }
 public static bool IsAbsoluteUrl(this string self)
 {
     return(UrlValidator.Validate(self, UriKind.Absolute));
 }