public void Test_Upsert_100_SameDomain() { UrlRepository repo = new UrlRepository(); for (int i = 0; i < 100; i++) { Url entity = new Url(); entity.Href = String.Format("http://demo.com/{0}", i); Url response = repo.Upsert(entity); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(Url)); Assert.IsNotNull(response.Id); Assert.IsNotNull(response.CasValue); Url responseCheck = repo.Get(response.Id); Assert.IsNotNull(responseCheck); Assert.IsInstanceOfType(responseCheck, typeof(Url)); Assert.IsNotNull(responseCheck.Id); Assert.IsNotNull(responseCheck.CasValue); Assert.IsTrue(response.Id.Equals(responseCheck.Id)); Assert.IsTrue(response.Href.Equals(responseCheck.Href)); } }
public IActionResult RedirectTo(string urlHash) { var url = _urlRepository.Get(urlHash); if (string.IsNullOrEmpty(url)) { return(NotFound()); } return(Redirect(url)); }
public ActionResult ViewShortenedUrl(string urlHash) { var urlRepo = new UrlRepository(Properties.Settings.Default.ConStr); var url = urlRepo.Get(urlHash); if (url == null) { return(View("NotFound")); } urlRepo.IncrementViews(url.Id); return(Redirect(url.OriginalUrl)); }
public ActionResult ViewShortenedUrl(string shortenedurl) { var urlRepo = new UrlRepository(Properties.Settings.Default.ConStr); var url = urlRepo.Get(shortenedurl); if (url == null) { return(View("/")); } urlRepo.IncrementViews(url.id); return(Redirect(url.RealURL)); }
/// <summary> /// Expands the URL. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">Id value is invalid</exception> public Url ExpandUrl(string id) { if (!id.IsShortCode()) { throw new ArgumentException("Id value is invalid"); } try { return(_repository.Get(id.DecodeBase58().ToString())); } catch (Exception ex) { throw HandleException(new object[] { id }, ex); } }
public void Test_Upsert_Remove() { UrlRepository repo = new UrlRepository(); Url entity = new Url(); entity.Href = "http://test.com"; Url response = repo.Upsert(entity); Assert.IsNotNull(response); Assert.IsNotNull(response.Id); Assert.IsInstanceOfType(response, typeof(Url)); // remove Assert.IsTrue(repo.Remove(response.Id)); var oldEntity = repo.Get(response.Id); Assert.IsNull(oldEntity); }
public void Test_Upsert_100() { UrlRepository repo = new UrlRepository(); for (int i = 0; i < 100; i++) { Url entity = new Url(); entity.Href = String.Format("http://testdomain{0}.com", i); entity.Tags.Add("demo"); entity.Tags.Add("test"); Url response = repo.Upsert(entity); Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(Url)); Assert.IsNotNull(response.Id); Assert.IsNotNull(response.CasValue); Url responseCheck = repo.Get(response.Id); Assert.IsNotNull(responseCheck); Assert.IsInstanceOfType(responseCheck, typeof(Url)); Assert.IsNotNull(responseCheck.Id); Assert.IsNotNull(responseCheck.CasValue); Assert.IsTrue(response.Id.Equals(responseCheck.Id)); Assert.IsTrue(response.Href.Equals(responseCheck.Href)); } }