示例#1
0
        public void CreateShortURL()
        {
            var su = new ShortURL(_shortURL);

            Assert.Equal(_shortURL, su.SUrl);
            su = ShortURL.ComputeShortURLFromExtendedURL(_url);
            Assert.Equal(_shortURL, su.SUrl);
        }
示例#2
0
        public URLServiceTest()
        {
            _mockUrlRepo = new Mock <IURLRepository>();

            _surl = ShortURL.ComputeShortURLFromExtendedURL(ShortURLTest._shortURL);
            _url  = new URL(ShortURLTest._url, _surl);
            _mockUrlRepo.Setup(x => x.GetByIdAsync(It.IsAny <ShortURL>())).ReturnsAsync(_url);

            _mockConfig = new Mock <IConfigApplicationLimits>();
            _mockConfig.Setup(x => x.MaxURLChars).Returns(100);
            _mockConfig.Setup(x => x.ShortUrlBase64Padding).Returns("=");
            _mockConfig.Setup(x => x.ShortUrlBase64PaddingLength).Returns(1);
            _mockConfig.Setup(x => x.ShortUrlLength).Returns(11);
            _goodSurl = StringGenerator.RandomString(11, false);
            _badSurl  = "asda";
        }
示例#3
0
        public async Task <string> CreateURLAsync(string extendedURL)
        {
            Guard.Against.NullOrEmpty(extendedURL, "URL value");
            Guard.Against.OutOfRange(extendedURL.Length, "URL value", 1, _config.MaxURLChars);
            string res = null;

            try {
                ShortURL surl = ShortURL.ComputeShortURLFromExtendedURL(extendedURL);
                if (!await _urlRepository.ExistsAsync(surl))
                {
                    URL newURL = new URL(extendedURL, surl);
                    await _urlRepository.AddAsync(newURL);
                }

                res = RemoveBase64Strings(surl.ToString());
            } catch (Exception excp) {
                _logger.LogError(excp, $"Error creating url with value: {extendedURL}.");
            }
            return(res);
        }
示例#4
0
 public URL(string extended)
 {
     Value = extended;
     Id    = ShortURL.ComputeShortURLFromExtendedURL(extended);
 }