public async Task <Ticket> GetTickets() { Ticket response = new Ticket(); try { using (var client = RestClient.For <IBlipAPI>(BaseUri)) { client.ContentType = "application/json"; client.AuthorizationKey = "Key c2FmcmFwYXl2cG8xOkQwV2hFUlFubUVBd1BpMndOUGth"; var body = new CommandsRequest(); body.Id = Guid.NewGuid().ToString(); body.To = "*****@*****.**"; body.Method = "get"; body.Uri = "/tickets?$take=2"; response = await client.GetTicketes(body); } } catch (Exception ex) { var x = 0; } return(response); }
public void Rover_Encounters_An_Obstacle() { var position = new Position(0, 0, "N"); var obstacles = new List <Coordinates> { new Coordinates(1, 1), new Coordinates(2, 5) }; var grid = new Grid(100, 100, obstacles); var commands = new List <string> { "F", "R", "F", "F", "F", "L" }; var requestBody = new CommandsRequest { startingPosition = position, grid = grid, commands = commands }; Report report = this.GetReport(requestBody); Position expectedPosition = new Position(1, 0, East); this.AssertPositionIsCorrect(expectedPosition, report.FinalPosition); Assert.True(report.EncounteredObstacle); Assert.Equal("An obstacle was encountered at position: X 1, Y 1", report.Message); }
public ActionResult <Report> Post([FromBody] CommandsRequest request) { var rover = new Rover(request.startingPosition, request.grid); this.CheckForValidCommands(request.commands); this.CheckForValidDirection(request.startingPosition.Direction); Report report = rover.Move(request.commands); return(report); }
private Report GetReport(CommandsRequest requestBody) { var request = new RestRequest(Method.POST); request.AddJsonBody(requestBody); IRestResponse response = client.Execute(request); var content = response.Content; Report report = JsonConvert.DeserializeObject <Report>(content); return(report); }
public void Unknown_Direction_Will_Throw_An_Exception() { var position = new Position(0, 0, "Z"); var grid = new Grid(100, 100); var commands = new List <string> { "F" }; var requestBody = new CommandsRequest { startingPosition = position, grid = grid, commands = commands }; var request = new RestRequest(Method.POST); request.AddJsonBody(requestBody); IRestResponse response = client.Execute(request); Assert.Equal(500, (int)response.StatusCode); }
public void Rover_Carries_Out_All_Commands() { var position = new Position(0, 0, "N"); var grid = new Grid(100, 100); var commands = new List <string> { "F", "R", "F", "F", "F", "L" }; var requestBody = new CommandsRequest { startingPosition = position, grid = grid, commands = commands }; Report report = this.GetReport(requestBody); Position expectedPosition = new Position(1, 3, North); this.AssertPositionIsCorrect(expectedPosition, report.FinalPosition); Assert.False(report.EncounteredObstacle); Assert.Equal("Successfully carried out all commands", report.Message); }