Exemplo n.º 1
0
        public void CanIAddtoStorage()
        {
            var url = new Url();

            url.OriginalUrl = "http://cool.xyz";
            url.Active      = true;

            var inserted = MockStorage.Add(url);

            Assert.NotNull(inserted);
            Assert.Equal(url.OriginalUrl, inserted.OriginalUrl);
        }
Exemplo n.º 2
0
        public void CannotGetFromStorage()
        {
            var url = new Url();

            url.OriginalUrl = "long  URL";
            url.Active      = true;

            var inserted = MockStorage.Add(url);

            Assert.NotNull(inserted);
            Assert.Equal(url.OriginalUrl, inserted.OriginalUrl);

            var retrieved = MockStorage.GetById(999);

            Assert.Null(retrieved);
        }
Exemplo n.º 3
0
        public IActionResult CreateURL(UrlViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }

            //string shortenUrl = _shortenerService.Shorten(model.OriginalUrl);

            var url = new Url();

            url.OriginalUrl = model.OriginalUrl;
            url.Active      = true;

            var inserted = MockStorage.Add(url);

            var result = new UrlViewModel
            {
                Id         = inserted.Id,
                ShortenUrl = $"{HttpContext.Request.Path}/{inserted.Id}"
            };

            return(View("Success", result));
        }
Exemplo n.º 4
0
        public void CannotAddToStorage()
        {
            Url url = null;

            Assert.Throws <ArgumentNullException>(() => MockStorage.Add(url));
        }