Exemple #1
0
        private bool ValidateRequiredFields()
        {
            string message = string.Empty;

            if (String.IsNullOrWhiteSpace(textTitle.Text))
            {
                message += "Title is required.\n";
            }

            if (String.IsNullOrWhiteSpace(textLink.Text))
            {
                message += "Link is required.\n";
            }

            if (!UrlValidator.ValidateUrl(textLink.Text))
            {
                message += "Link Url is not valid!";
            }

            if (String.IsNullOrWhiteSpace(textDesc.Text))
            {
                message += "Description is required.\n";
            }

            if (message != String.Empty)
            {
                MessageBox.Show(message);
                return(false);
            }

            return(true);
        }
        private bool ValidateRequiredFields(Channel channel)
        {
            string message = String.Empty;

            if (String.IsNullOrWhiteSpace(channel.Title))
            {
                message += "Title is required.\n";
            }

            if (String.IsNullOrWhiteSpace(channel.Description))
            {
                message += "Description is required.\n";
            }

            if (String.IsNullOrWhiteSpace(channel.Link))
            {
                message += "Link is required.\n";
            }

            if (!UrlValidator.ValidateUrl(channel.Link))
            {
                message += "Link Url is not valid!";
            }

            if (message != String.Empty)
            {
                MessageBox.Show(message);
                return(false);
            }

            return(true);
        }
Exemple #3
0
        public async Task <IActionResult> Get(string url)
        {
            if (!UrlValidator.ValidateUrl(url))
            {
                ModelState.AddModelError("url", "Please provide a proper url");
                return(BadRequest(ModelState));
            }

            var pageResult = await _crawlerService.GetPageResults(url);

            //TODO: add proper error handling. Would make sense to return bad request for bad URLs, internal server errors for others.
            if (pageResult == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Ruh roh, something bad happened"));
            }

            return(Ok(pageResult));
        }
        public async System.Threading.Tasks.Task ValidateUrlShouldContructTheCorrectHttpRequestAndSendIt()
        {
            var url = "http://example.com/api/doMagic";

            var expected = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK
            };

            var mockHttpMessageHandler = new MockHttpMessageHandler();

            mockHttpMessageHandler.When(url).Respond(req => expected);

            var mockHttpClient = mockHttpMessageHandler.ToHttpClient();

            var urlValidator = new UrlValidator(mockHttpClient);

            var actual = await urlValidator.ValidateUrl(url);

            Assert.Equal(HttpMethod.Get, actual.RequestMessage.Method);
            Assert.Equal(url, actual.RequestMessage.RequestUri.ToString());
            Assert.Equal(expected, actual);
        }
 [InlineData("www.google.com")]         // Invalid, missing protocol
 public void TestValidUrls(string url)
 {
     Assert.True(UrlValidator.ValidateUrl(url));
 }