public async void RaceLogin_Should_Return_Correctly() { var response = new MazebotLoginResponse(); _apiClient.SendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <Func <HttpResponseMessage, Task <MazebotLoginResponse> > >()).Returns(response); var actual = await _client.RaceLogin(new MazebotLoginRequest()); actual.Should().Be(response); }
public async void RaceLogin_Should_Deserialize_SendAsync_Response() { Func <HttpResponseMessage, Task <MazebotLoginResponse> > responseMapper = null; await _apiClient.SendAsync(Arg.Any <HttpRequestMessage>(), Arg.Do <Func <HttpResponseMessage, Task <MazebotLoginResponse> > >(a => responseMapper = a)); await _client.RaceLogin(new MazebotLoginRequest()); var content = new MazebotLoginResponse { Message = "message", NextMaze = "next" }; var stringContent = JsonConvert.SerializeObject(content); var response = new HttpResponseMessage { Content = new StringContent(stringContent) }; var actual = await responseMapper(response); actual.Should().BeEquivalentTo(content); }
private async Task <IEnumerable <MazebotSolverResponseSummary> > FinishRace(string sessionId, MazebotLoginResponse start) { var responses = new List <MazebotSolverResponseSummary>(); var nextMaze = start.NextMaze; while (!string.IsNullOrWhiteSpace(nextMaze)) { var maze = await GetRaceTrack(nextMaze); var solution = await SolveMaze(maze); var result = await PostSolution(maze, solution); var response = new MazebotSolverResponse(sessionId, maze, solution, result); await _repository.Add(sessionId, response); responses.Add(response.CreateSummary()); nextMaze = result?.NextMaze; } return(responses); }