Exemplo n.º 1
0
        public void ConvertUrl_should_convert_long_to_short_by_making_last_part_of_short_url_and_stored_into_db_if_not_stored_in_db()
        {
            var shortenUrlSetting = new ShortenUrlSetting();

            shortenUrlSetting.DomainName = "http://shortenurl.my/";
            this.shortenUrlSetting.Setup(x => x.Value).Returns(shortenUrlSetting);
            sut = new LongUrlCommand(this.shortenUrlServiceQuery.Object, this.shortenUrlSetting.Object);
            this.shortenUrlServiceQuery.Setup(x => x.GetByLongUrl(It.IsAny <string>())).Returns(It.IsAny <ShortenUrl>());
            var result = sut.ConvertUrl("testurl");

            result.Length.Should().BeGreaterThan(shortenUrlSetting.DomainName.Length);
        }
Exemplo n.º 2
0
        public void ConvertUrl_should_not_convert_long_to_short_and_found_exception_if_appsettings_key_absence()
        {
            //var shortenUrlSetting = new ShortenUrlSetting();
            var shortenUrl = new ShortenUrl()
            {
                ShortUrl = "testurl"
            };

            this.shortenUrlSetting.Setup(x => x.Value).Returns(It.IsAny <ShortenUrlSetting>());
            sut = new ShortUrlCommand(this.shortenUrlServiceQuery.Object, this.shortenUrlSetting.Object);
            this.shortenUrlServiceQuery.Setup(x => x.GetByLongUrl(It.IsAny <string>())).Returns(shortenUrl);
            var exp = Assert.Throws <NullReferenceException>(() => sut.ConvertUrl("testurl"));
        }
Exemplo n.º 3
0
        public void ConvertUrl_should_convert_empty_longurl_if_not_stored_in_db()
        {
            var shortenUrlSetting = new ShortenUrlSetting();

            shortenUrlSetting.DomainName = "http://shortenurl.my/";
            var shortenUrl = new ShortenUrl()
            {
                ShortUrl = "testUrl", LongUrl = "https://www.linkedin.com/in/ehasanulhoque/"
            };

            this.shortenUrlSetting.Setup(x => x.Value).Returns(shortenUrlSetting);
            sut = new ShortUrlCommand(this.shortenUrlServiceQuery.Object, this.shortenUrlSetting.Object);
            this.shortenUrlServiceQuery.Setup(x => x.GetByShortUrl(It.IsAny <string>())).Returns(It.IsAny <ShortenUrl>());
            var result = sut.ConvertUrl(shortenUrlSetting.DomainName + shortenUrl.ShortUrl);

            result.Should().BeNullOrEmpty();
        }
Exemplo n.º 4
0
        public void ConvertUrl_should_convert_short_to_long_for_url_without_http_by_getting_from_db_if_already_stored_in_db()
        {
            var shortenUrlSetting = new ShortenUrlSetting();

            shortenUrlSetting.DomainName = "http://shortenurl.my/";
            var shortenUrl = new ShortenUrl()
            {
                ShortUrl = "testUrl", LongUrl = "https://www.linkedin.com/in/ehasanulhoque/"
            };

            this.shortenUrlSetting.Setup(x => x.Value).Returns(shortenUrlSetting);
            sut = new ShortUrlCommand(this.shortenUrlServiceQuery.Object, this.shortenUrlSetting.Object);
            this.shortenUrlServiceQuery.Setup(x => x.GetByShortUrl(It.IsAny <string>())).Returns(shortenUrl);
            var result = sut.ConvertUrl("shortenurl.my/" + shortenUrl.ShortUrl);

            result.Should().Contain(shortenUrl.LongUrl);
        }
Exemplo n.º 5
0
        public void ConvertUrl_should_convert_long_to_short_by_getting_last_part_of_short_url_from_db_if_already_stored_in_db()
        {
            var shortenUrlSetting = new ShortenUrlSetting();

            shortenUrlSetting.DomainName = "http://shortenurl.my/";
            var shortenUrl = new ShortenUrl()
            {
                ShortUrl = "testurl"
            };

            this.shortenUrlSetting.Setup(x => x.Value).Returns(shortenUrlSetting);
            sut = new LongUrlCommand(this.shortenUrlServiceQuery.Object, this.shortenUrlSetting.Object);
            this.shortenUrlServiceQuery.Setup(x => x.GetByLongUrl(It.IsAny <string>())).Returns(shortenUrl);
            var result = sut.ConvertUrl("testurl");

            result.Should().Contain(shortenUrl.ShortUrl);
        }