Example #1
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        /// <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);
            }
        }
Example #6
0
        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);
        }
Example #7
0
        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));
            }
        }
Example #8
0
        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);
        }