Exemplo n.º 1
0
        public async Task <IHttpActionResult> AddLongUrl(UrlRequest longUrl)
        {
            var url = await _constructInput.ConstructUrl(longUrl.Url);

            var result = await _validateUrl.CheckWebsite(url);

            if (result)
            {
                var urlSearch = await _urlStorage.GetItem(url);

                if (urlSearch == null)
                {
                    var shortUrlCode = _convertUrl.GetShorterUrl(url);
                    var container    = new UrlContainer {
                        LongUrl = url, ShortUrl = shortUrlCode
                    };
                    await _urlStorage.AddItem(container);

                    return(Ok(container.ShortUrl));
                }

                return(Ok(urlSearch.ShortUrl));
            }
            return(BadRequest());
        }
Exemplo n.º 2
0
 public void Test_Convert_Url_Base_Url_Long()
 {
     Assert.IsTrue(_convertMethod.GetShorterUrl("http://www.some.com/page1/page2") == "243212");
 }