public async Task <string> FindSuitableShortLinkAsync(int maximimAttemptsCount = 5) { for (var attempt = 0; attempt < maximimAttemptsCount; attempt++) { var shortLink = _shortLinkGenerator.CreateShortLink(7); if (await _checkExistenceFunction(shortLink)) { continue; } return(shortLink); } throw new MaximumAttemptsReachedException(maximimAttemptsCount); }
public void GenerateShortLink(string inputLink) { var actual = _generator.CreateShortLink(7); actual.Should().MatchRegex("[A-Z0-9]{7}"); }