Ejemplo n.º 1
0
        public async void GetMazebotRaceTrack_Should_Deserialize_SendAsync_Response()
        {
            Func <HttpResponseMessage, Task <MazebotResponse> > responseMapper = null;
            await _apiClient.SendAsync(Arg.Any <HttpRequestMessage>(), Arg.Do <Func <HttpResponseMessage, Task <MazebotResponse> > >(a => responseMapper = a));

            await _client.GetMazebotRaceTrack("mapUrl");

            var content = new MazebotResponse
            {
                Name             = "name",
                StartingPosition = new [] { 1, 2 },
                EndingPosition   = new [] { 3, 4 },
                MazePath         = "mazePath",
                Map = new char[][] { new char[] { Map.OCCPD, Map.EMPTY, Map.START, Map.DESTN } }
            };

            var stringContent = JsonConvert.SerializeObject(content);
            var response      = new HttpResponseMessage
            {
                Content = new StringContent(stringContent)
            };

            var actual = await responseMapper(response);

            actual.Should().BeEquivalentTo(content);
        }
Ejemplo n.º 2
0
        public async void GetMazebotRaceTrack_Should_Return_Correctly()
        {
            var response = new MazebotResponse();

            _apiClient.SendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <Func <HttpResponseMessage, Task <MazebotResponse> > >()).Returns(response);

            var actual = await _client.GetMazebotRaceTrack("mapUrl");

            actual.Should().Be(response);
        }
Ejemplo n.º 3
0
        private async Task <MazebotResult> PostSolution(MazebotResponse mazebotMaze, NavigationDetails solution)
        {
            MazebotResult result = null;

            if (solution.Arrived)
            {
                result = await _apiClient.SolveMazebotMaze(mazebotMaze.MazePath, solution.PathTaken);
            }
            return(result);
        }
Ejemplo n.º 4
0
        private async Task <NavigationDetails> SolveMaze(MazebotResponse mazebotMaze)
        {
            var startX = mazebotMaze.StartingPosition[0];
            var startY = mazebotMaze.StartingPosition[1];
            var start  = new Coordinates(startX, startY);

            var destinationX = mazebotMaze.EndingPosition[0];
            var destinationY = mazebotMaze.EndingPosition[1];
            var destination  = new Coordinates(destinationX, destinationY);

            var maze = new Map(mazebotMaze.Map);

            _queen.ScanMap(start, destination, maze);

            return(await _queen.Navigate());
        }