public void Shorten_UrlPassedIn_HashedDbIdReturned() { //arrange const Int32 dbReturnedId = 46; const String expectedReturnedHash = "1a"; _fakeDb.InsertedUrlId = dbReturnedId; //Act var returnedHash = _shortener.Shorten("url"); //Assert Assert.AreEqual(expectedReturnedHash, returnedHash); }
public JsonResult Zip(string url) { Uri uri = null; string result = string.Empty; if (string.IsNullOrEmpty(url) || url.Length > 4000 || !Uri.TryCreate(url, UriKind.Absolute, out uri) || null == uri || (uri.Scheme != "http" && uri.Scheme != "https")) { return(new JsonResult(null) { StatusCode = (int)HttpStatusCode.NotFound }); } else { try { Shortener sh = new Shortener(_configuration["connectionString"], _configuration["salt"]); return(new JsonResult("https" + Uri.SchemeDelimiter + Request.Host + "/" + sh.Shorten(uri.ToString()))); } catch (Exception ex) { return(new JsonResult(ex.Message) { StatusCode = (int)HttpStatusCode.NotFound }); } } }