public async Task GetBoard_ValidBoardId_ShouldReturnOk() { //Arrange var redisServiceMock = new Mock <IRedisService>(); var board = new Board(10); redisServiceMock.Setup(r => r.Get <Board>(It.IsAny <string>())).ReturnsAsync(board); var helperServiceMock = new Mock <IGameHelperService>(); var controller = new BoardGameController(redisServiceMock.Object, helperServiceMock.Object); //Act IActionResult result = await controller.GetBoard(board.BoardId); var okResult = result as OkObjectResult; //Asset Assert.IsNotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); Assert.IsInstanceOfType(okResult.Value, typeof(Board)); Assert.AreEqual(board.BoardId, ((Board)okResult.Value).BoardId); }
public async Task GetBoard_InValidBoardId_ShouldReturnNotFound() { //Arrange var redisServiceMock = new Mock <IRedisService>(); redisServiceMock.Setup(r => r.Get <Board>(It.IsAny <string>())).ReturnsAsync(default(Board)); var helperServiceMock = new Mock <IGameHelperService>(); var controller = new BoardGameController(redisServiceMock.Object, helperServiceMock.Object); var invalidBoard = new Board(10); //Act IActionResult result = await controller.GetBoard(invalidBoard.BoardId); var notFoundResult = result as NotFoundObjectResult; //Asset Assert.IsNotNull(notFoundResult); Assert.AreEqual(404, notFoundResult.StatusCode); Assert.AreEqual("Unable to get board for request " + invalidBoard.BoardId.ToString(), notFoundResult.Value); }