internal SSLLabsApiService(string apiUrl, IApiProvider apiProvider) { _apiProvider = apiProvider; _requestModelFactory = new RequestModelFactory(); _urlValidation = new UrlValidation(); _responsePopulation = new ResponsePopulation(); ApiUrl = _urlValidation.Format(apiUrl); }
public void InvalidUrl2_BadFormat_ShouldReturFalse() { // arrange var url = "facebook"; var validator = new UrlValidation(); var expected = false; // act var actual = validator.ValidUrl(url); // assert Assert.AreEqual(actual, expected); }
public void ValidUrl_GoodFormat_ShouldReturTrue() { // arrange var url = "https://www.facebook.com"; var validator = new UrlValidation(); var expected = true; // act var actual = validator.ValidUrl(url); // assert Assert.AreEqual(actual, expected); }
private static string ValidateLinkToSite(string linkToSite) { if (linkToSite == "") { return(linkToSite); } if (!UrlValidation.IsValid(linkToSite)) { throw ShopException.InvalidLinkToSiteException(linkToSite); } return(linkToSite); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value == null) { return(ValidationResult.Success); } var url = value.ToString(); if (UrlValidation.IsValidUrl(url)) { return(ValidationResult.Success); } return(new ValidationResult(string.Format("The value entered for {0} is not a valid URL", validationContext.DisplayName))); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value == null) { return(ValidationResult.Success); } var url = value.ToString(); if (UrlValidation.IsValidUrl(url) && ImageValidation.HasValidImageExtension(url, ImageType.Ico, ImageType.Jpeg, ImageType.Png)) { return(ValidationResult.Success); } return(new ValidationResult(string.Format("The value entered for {0} is not a valid image URL", validationContext.DisplayName))); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpContextBase httpContextBase = controllerContext.RequestContext.HttpContext; UrlValidation urlValidation = new UrlValidation(); //Binding posted values to UrlValidation type urlValidation.Expirydate = DateTime.ParseExact( httpContextBase.Request["UrlValidation.Expirydate"].ToString(), "d/M/yyyy", CultureInfo.InvariantCulture).ToString("G"); urlValidation.ProjectTypeID = Convert.ToInt16(httpContextBase.Request["ProjectType"]); urlValidation.Url = httpContextBase.Request["UrlValidation.Url"].ToString(); string datetime = DateTime.Now.ToString("G"); urlValidation.CreateDate = datetime; // returning UrlValidation type return(urlValidation); }
private async void OnGetArtworkFromUrl() { var enterUrlModel = new EnterStringViewModel( _messenger, "Get Artwork", "Enter the URL for the artwork below", str => UrlValidation.IsValidUrl(str) && ImageValidation.HasValidImageExtension(str, ImageType.Jpeg, ImageType.Bmp, ImageType.Png), "The value entered is not a valid artwork URL"); _messenger.Send(new ShowDialogMessage(enterUrlModel)); var result = enterUrlModel.Result; if (result == null) { return; } LoadingArtwork = true; UpdateArtwork(await GetImageBytesFromUrl(result)); }
// [ValidateAntiForgeryToken] public IActionResult Create([FromBody] string originalUrl) { if (UrlValidation.IsValidUrl(originalUrl)) { var shortUrl = new ShortenedUrl { OriginalUrl = originalUrl }; TryValidateModel(shortUrl); if (ModelState.IsValid) { _service.Save(shortUrl); } var returnedUrl = ShortUrlHelper.Encode(shortUrl.Id); return(Ok("http://shrturl.keith-pearce.co.uk/url/" + returnedUrl)); } else { return(BadRequest("Please enter a valid URL")); } }
private bool ValidateRow(ImportRedirectRow row) { if (!UrlValidation.IsRelativeUrl(row.FromUrl)) { return(false); } if (!UrlValidation.ValidFromUrl(row.FromUrl)) { return(false); } if (!UrlValidation.IsWithinLengthLimit(row.FromUrl)) { return(false); } if (!UrlValidation.ValidToUrl(row.ToUrl)) { return(false); } if (!UrlValidation.IsWithinLengthLimit(row.ToUrl)) { return(false); } return(true); }
public void WillPassForValidUrls(string url) { bool result = UrlValidation.ValidHttpURL(url, out Uri uriResult); result.Should().BeTrue(); }
public void Test_UrlValidation() { const string url = "https://test.com"; Assert.IsTrue(UrlValidation.Validate(url)); }
public void Test_UrlValidationError() { const string url = "test.com"; Assert.IsFalse(UrlValidation.Validate(url)); }
public void Should_know_if_Url_Exist_or_Not() { //Cheate an array of our Model class var arr = new Url[] { new Url{ UrlId = 0, UrlCode = "TYUR", OriginalUrl="https://fluentvalidation.com", IpAddress="127.0.0.1", PostedDate = DateTime.Now}, new Url{ UrlId = 1, UrlCode = "TwUR", OriginalUrl="https://www.facebook.com", IpAddress="127.0.0.1", PostedDate = DateTime.Now}, new Url{ UrlId = 2, UrlCode = "TkUR", OriginalUrl="https://www.youtube.com/", IpAddress="127.0.0.1", PostedDate = DateTime.Now} }.AsQueryable(); //mock and create the fake of our Url var mockSet = new Mock<IDbSet<Url>>(); mockSet.As<IQueryable<Url>>().Setup(m => m.Provider).Returns(arr.Provider); mockSet.As<IQueryable<Url>>().Setup(m => m.Expression).Returns(arr.Expression); mockSet.As<IQueryable<Url>>().Setup(m => m.ElementType).Returns(arr.ElementType); mockSet.As<IQueryable<Url>>().Setup(m => m.GetEnumerator()).Returns(arr.GetEnumerator()); var fakeContext = new Mock<EFDbContext>(); fakeContext.SetupGet(ctx => ctx.Urls).Returns(mockSet.Object); var validator = new UrlValidation(); validator.context = (EFDbContext)fakeContext.Object; //the url below exist in our record above, therefore notExist shall be false. Assert.IsFalse(validator.notExist("https://www.youtube.com/")); //the url below does not exist in our record above and hence notExist shall return true Assert.IsTrue(validator.notExist("https://www.facebooker.com/")); }
private async Task <bool> ImportRowAsync(ImportRedirectRow row) { if (!ValidateRow(row)) { return(false); } var existing = await _session.Query <ContentItem>() .With <RedirectPartIndex>(x => x.Url == row.FromUrl) .ListAsync(); ContentItem redirectItem = null; var newItem = false; if (existing.Any()) { redirectItem = existing.FirstOrDefault(x => x.Published); } if (redirectItem == null) { redirectItem = await _contentManager.NewAsync(Constants.RedirectContentType); redirectItem.Owner = _httpContextAccessor.HttpContext.User.Identity.Name; redirectItem.CreatedUtc = DateTime.UtcNow; newItem = true; } if (redirectItem == null) { return(false); } var redirectPart = redirectItem.Get <RedirectPart>(nameof(RedirectPart)); if (redirectPart == null) { return(false); } redirectItem.Author = _httpContextAccessor.HttpContext.User.Identity.Name; redirectItem.DisplayText = row.Title; redirectPart.FromUrl = UrlValidation.CleanFromUrl(row.FromUrl)?.Trim(); redirectPart.ToUrl = row.ToUrl?.Trim(); redirectPart.IsPermanent = true; redirectPart.Apply(); redirectItem.Apply(nameof(RedirectPart), redirectPart); ContentExtensions.Apply(redirectItem, redirectItem); if (newItem) { await _contentManager.CreateAsync(redirectItem); } else { await _contentManager.UpdateAsync(redirectItem); } await _contentManager.PublishAsync(redirectItem); return(true); }
public void IsValid_Test(string url, bool expectedIsValid) { var validationResult = UrlValidation.IsValid(url); Assert.AreEqual(expectedIsValid, validationResult); }
public void WillFailOnInvalidUrls(string url) { bool result = UrlValidation.ValidHttpURL(url, out Uri uriResult); result.Should().BeFalse(); }
public UnitTest1() { val = new UrlValidation(); }