public void AddBattleShip_Fails_BattleshipGameException() { var user = MockClaimsPrincipal(); var mockService = new Mock <IBattleshipGameService>(); // var playerList = new List<string> { "alice" }; mockService.Setup(x => x.AddBattleship(It.IsAny <string>(), It.IsAny <Ship>(), It.IsAny <Coordinates>(), It.IsAny <ShipPlacement>())) .Throws(new BattleshipGameException()); var controller = new BattleshipController(_config, mockService.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } } }; var result = controller.AddBattleShip(new BattleshipModel()); var apiResponse = (ApiResponse <string>)result; //Assert Assert.Equal(HttpStatusCode.BadRequest, apiResponse.StatusCode); }
public void AddBattleShip_Returns_Success() { var user = MockClaimsPrincipal(); var mockService = new Mock <IBattleshipGameService>(); mockService.Setup(x => x.AddBattleship(It.IsAny <string>(), It.IsAny <Ship>(), It.IsAny <Coordinates>(), It.IsAny <ShipPlacement>())) .Returns(true); var controller = new BattleshipController(_config, mockService.Object) { ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } } }; var result = controller.AddBattleShip(new BattleshipModel()); var apiResponse = (ApiResponse <string>)result; //Assert Assert.Equal(HttpStatusCode.OK, apiResponse.StatusCode); }