public async void CreateNotExists_Test() { _database.Execute("FLUSHDB"); //cleans db ShortURL surl = new ShortURL(ShortURLTest._shortURL); URL url = new URL(ShortURLTest._url, surl); bool res = await _urlRepository.ExistsAsync(surl); Assert.False(res); await _urlRepository.AddAsync(url); res = await _urlRepository.ExistsAsync(surl); Assert.True(res); }
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); }