Example #1
0
        public async Task <IActionResult> GetSourceUrlByShortenUrlAsync(string shortenUrl)
        {
            var url = await shortenerService.GetSourceUrlByShortenUrlAsync(shortenUrl);

            if (string.IsNullOrWhiteSpace(url))
            {
                return(NotFound());
            }

            return(Redirect(url));
        }
Example #2
0
        public async Task ReceiveCountIncrementShouldBeApplied()
        {
            const string shortUrl  = "fh84ea";
            var          shortLing = new ShortLink {
                ShortUrl = "fh84ea", SourceUrl = "https://google.com/"
            };

            DatabaseContextStub.ShortLinks.Add(shortLing);

            await ShortenerService.GetSourceUrlByShortenUrlAsync(shortUrl);

            Assert.That(shortLing.ReceiveCounter, Is.EqualTo(1));
        }
Example #3
0
        public async Task SourceUrlMustBeReturned()
        {
            const string expectedSourceUrl = "https://google.com/";
            const string shortUrl          = "fh84ea";

            DatabaseContextStub.ShortLinks.Add(new ShortLink {
                ShortUrl = shortUrl, SourceUrl = expectedSourceUrl
            });

            var sourceUrl = await ShortenerService.GetSourceUrlByShortenUrlAsync(shortUrl);

            Assert.That(sourceUrl, Is.EqualTo(expectedSourceUrl));
        }