Beispiel #1
0
        public ActionResult Index(string shortenUrl)
        {
            UrlItem item = _urlRepo.GetById(UrlGenerator.Decode(shortenUrl)) ?? _urlRepo.All().FirstOrDefault(i => i.CustomUrl.Equals(shortenUrl));

            if (item == null)
            {
                return(View("NotFound"));
            }

            if (IsExpired(item))
            {
                _urlRepo.Delete(item);
                return(View("Expired"));
            }

            var urlHit = new UrlHit {
                UrlItemId = item.Id,
                ClientIp  = Request.UserHostAddress
            };

            _urlRepo.Update(item);
            _hitRepo.Add(urlHit);

            return(Redirect(item.OriginUrl));
        }
Beispiel #2
0
        public void Add()
        {
            var item = new UrlItem {
                ExpireMode = (short)ExpireMode.Never,
                OriginUrl  = "http://www.google.com/"
            };

            _repo.Add(item);

            UrlItem storedItem = _repo.GetById(UrlGenerator.Decode(item.CustomUrl));

            Assert.That(storedItem, Is.Not.Null);
        }