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()); } }
public void PassingTest1() { Assert.Equal(true, UrlValidator.validator("http://google.com")); }
public void FailingTest3() { Assert.Equal(false, UrlValidator.validator("http://googl//e.com")); }
public void PassingTest3() { Assert.Equal(true, UrlValidator.validator("http://ali-nazari.com")); }
public void FailingTest2() { Assert.Equal(false, UrlValidator.validator("http://dfskjhkjdsa..dfs")); }
public void PassingTest2() { Assert.Equal(true, UrlValidator.validator("http://1.1.1.1")); }