public GetFibonacciNumbersResponse Any(GetFibonacciNumbers request) { var skip = request.Skip.GetValueOrDefault(0); var take = request.Take.GetValueOrDefault(config.DefaultFibonacciLimit); var results = new List <long>(); var i = 0; foreach (var fibonacciNumber in GetFibonacciNumbersNumbers()) { if (i++ < skip) { continue; } results.Add(fibonacciNumber); if (results.Count == take) { break; } } return(new GetFibonacciNumbersResponse { Results = new ArrayOfLong(results) }); }
public void Can_GetFibonacciNumbers() { var request = new GetFibonacciNumbers { Skip = 3, Take = 5 }; SendToEachEndpoint <GetFibonacciNumbersResponse>(request, response => Assert.That(response.Results, Is.EquivalentTo(new List <long> { 5, 8, 13, 21, 34 }))); }
public void GetFibonacciNumbers_Test() { var request = new GetFibonacciNumbers { Take = 5 }; var handler = new GetFibonacciNumbersService( new ExampleConfig { DefaultFibonacciLimit = 10 }); var response = handler.Any(request); Assert.That(response.Results.Count, Is.EqualTo(request.Take)); Assert.That(response.Results, Is.EqualTo(new[] { 1, 2, 3, 5, 8 })); }