private PermutationsResponse GetPermutationsResponse(String request) { var cachedRequest = this._permutationsRepository.Get(request); if (cachedRequest != null) { return(new PermutationsResponse { Input = request, Seconds = cachedRequest.Seconds, Permutations = JsonHelper.Deserialize <String[]>(cachedRequest.PermutationsJson) }); } var watch = Stopwatch.StartNew(); var permutations = PermutationsService.GetPermutations(request); watch.Stop(); this._permutationsRepository.Add(request, JsonHelper.Serialize(permutations), watch.ElapsedMilliseconds / 1000.0); return(new PermutationsResponse { Input = request, Seconds = watch.ElapsedMilliseconds / 1000.0, Permutations = permutations }); }
public async Task ShouldCalculateCorrectly(int expectedCount, string value) { var service = new PermutationsService(_context); var result = await service.CalculateAsync(value); Assert.Equal(expectedCount, result.PermutationCount); }
public async Task ShouldStoreCalculated(string value) { var service = new PermutationsService(_context); var result = await service.CalculateAsync(value); var stored = await service.GetAsync(value); Assert.NotNull(stored); Assert.Equal(result.Value, stored.Value); }