public void Generate_Code_By_Url()
        {
            // arrange
            var url = "www.bbc.com";

            // act
            var result = subject.GenerateCode(url);

            // assert
            Assert.IsAssignableFrom <string>(result);
        }
        public IActionResult ShortenUrl(string originalUrl)
        {
            if (!_urlService.Parse(originalUrl))
            {
                return(RedirectToAction(nameof(Error)));
            }

            var shortenedCode = _urlService.GenerateCode(originalUrl);
            var model         = new UrlModel
            {
                OriginalUrl  = originalUrl,
                ShortenedUrl = $"{_baseUrl}{shortenedCode}",
                Code         = shortenedCode
            };

            _repository.AddUrl(model);
            return(RedirectToAction(nameof(Index)));
        }