public ActionResult <string> Post([FromBody] UrlRequest urlRequest)
        {
            string longUrl;

            if (!(urlRequest.LongUrl.StartsWith("http://") || urlRequest.LongUrl.StartsWith("https://") || urlRequest.LongUrl.StartsWith("ftp://") || urlRequest.LongUrl.StartsWith("file://")))
            {
                longUrl = "http://" + urlRequest.LongUrl;
            }
            else
            {
                longUrl = urlRequest.LongUrl;
            }
            Console.WriteLine("im here!");
            if (UrlValidator.validator(longUrl))
            {
                UrlRequest request = new UrlRequest()
                {
                    LongUrl = longUrl
                };
                UrlResorce shortUrl = urlMapper.setShortUrl(request);
                return(Ok(shortUrl));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 2
0
 public void PassingTest1()
 {
     Assert.Equal(true, UrlValidator.validator("http://google.com"));
 }
Exemplo n.º 3
0
 public void FailingTest3()
 {
     Assert.Equal(false, UrlValidator.validator("http://googl//e.com"));
 }
Exemplo n.º 4
0
 public void PassingTest3()
 {
     Assert.Equal(true, UrlValidator.validator("http://ali-nazari.com"));
 }
Exemplo n.º 5
0
 public void FailingTest2()
 {
     Assert.Equal(false, UrlValidator.validator("http://dfskjhkjdsa..dfs"));
 }
Exemplo n.º 6
0
 public void PassingTest2()
 {
     Assert.Equal(true, UrlValidator.validator("http://1.1.1.1"));
 }