public async Task AttackResult_InValidBoardId_ShouldReturnBadRequest() { //Arrange var board = new Board(10); int row = 0; int column = 0; var redisServiceMock = new Mock <IRedisService>(); redisServiceMock.Setup(r => r.Get <Board>(It.IsAny <string>())).ReturnsAsync(default(Board)); redisServiceMock.Setup(r => r.Set <It.IsAnyType>(It.IsAny <string>(), It.IsAny <It.IsAnyType>())).ReturnsAsync(true); var helperServiceMock = new Mock <IGameHelperService>(); var controller = new BoardGameController(redisServiceMock.Object, helperServiceMock.Object); //Act IActionResult result = await controller.AttackResult(board.BoardId, row, column); var badRequestResult = result as BadRequestObjectResult; //Asset Assert.IsNotNull(badRequestResult); Assert.AreEqual(400, badRequestResult.StatusCode); Assert.AreEqual("Unable to get board for request " + board.BoardId.ToString(), badRequestResult.Value); }
public async Task AttackResult_ValidPosition_ShouldReturnOk() { //Arrange var board = new Board(10); int row = 0; int column = 0; var redisServiceMock = new Mock <IRedisService>(); redisServiceMock.Setup(r => r.Get <Board>(It.IsAny <string>())).ReturnsAsync(board); redisServiceMock.Setup(r => r.Set <It.IsAnyType>(It.IsAny <string>(), It.IsAny <It.IsAnyType>())).ReturnsAsync(true); var helperServiceMock = new Mock <IGameHelperService>(); helperServiceMock.Setup(r => r.IsAttacSuccessful(It.IsAny <Board>(), It.IsAny <int>(), It.IsAny <int>())).Returns(true); var controller = new BoardGameController(redisServiceMock.Object, helperServiceMock.Object); //Act IActionResult result = await controller.AttackResult(board.BoardId, row, column); var okResult = result as OkObjectResult; //Asset Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); }