public void CreateMines_StringCommandInput_ReturnsMineCount(string boardInput, string stringMineInput, int[] mineInput1, int[] mineInput2, int[] mineInput3, int expectedResult) { var mineServiceStub = new Mock <IMineService>(); mineServiceStub.Setup(x => x.CreateMine(mineInput1)) .Returns(new Mine { Position = new Coordinate { X = mineInput1[0], Y = mineInput1[1] } }); mineServiceStub.Setup(x => x.CreateMine(mineInput2)) .Returns(new Mine { Position = new Coordinate { X = mineInput2[0], Y = mineInput2[1] } }); mineServiceStub.Setup(x => x.CreateMine(mineInput3)) .Returns(new Mine { Position = new Coordinate { X = mineInput3[0], Y = mineInput3[1] } }); var coordinateServiceStub = new Mock <ICoordinateService>(); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create(boardInput); boardService.CreateMines(stringMineInput); var result = boardService.GetBoard().Mines.Count; Assert.Equal(expectedResult, result); }
public async Task <ActionResult <Board> > CreateBoard(Board board) { var userId = httpContextAccessor.HttpContext.User.Identity.Name; var user = userService.GetById(userId); Lane[] lanes = { new Lane { Title = "Wat ging goed?" }, new Lane { Title = "Wat kon beter?" }, new Lane { Title = "Te ondernemen acties" } }; board.Owner = new BoardUser(user.Id, user.Username); boardService.Create(board); foreach (var lane in lanes) { var createdLane = await laneService.Create(lane); await boardService.AddLane(board.Id, createdLane); } return(CreatedAtRoute("GetBoard", new { id = board.Id }, board)); }
public async Task <ActionResult <Session> > Create() { UserModel user = await userManager.GetUserAsync(HttpContext.User); if (user?.UserId == null) { return(StatusCode(StatusCodes.Status403Forbidden)); } Session session = SessionFactory.Create(user); await sessionService.Create(session); Game game = new Game { Id = session.Id }; Board board = BoardFactory.New(session.Id); GameOperations.AddPlayer(game, user.UserId); await gameService.Create(game); await boardService.Create(board); user.AddSession(session); await userManager.UpdateAsync(user); return(CreatedAtRoute("GetSession", new { id = session.Id }, session)); }
public void Create_Zero_ReturnsInvalidException() { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object);; Assert.Throws <InvalidOperationException>(() => boardService.Create("0 0")); }
public void CreateMines_InvalidPosition_ThrowsNullException() { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create("1 1"); Assert.Throws <Exception>(() => boardService.CreateMines("2,2")); }
public int Create(string name) { var map = mapper.CreateMapper(); BoardDTO boardDTO = new BoardDTO { Name = name }; int i = boardDTO.Id = BoardService.Create(boardDTO, User.Identity.GetUserId()); return(i); }
public void GetBoard_StringCommand_ReturnsBoardHeight(string value, int expectedOutput) { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create(value); var board = boardService.GetBoard(); Assert.Equal(board.Height, expectedOutput); }
public void GetBoard_StringCommand_ReturnsBoard(string value) { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create(value); var board = boardService.GetBoard(); Assert.NotNull(board); }
public ActionResult <Board> CreateBoard([FromBody] BoardMessage boardMessage) { Board board = _boardService.Create(boardMessage.title, boardMessage.description, boardMessage.currentProjectId); if (board == null) { return(BadRequest(boardMessage)); } return(Ok(board)); }
public void CreateExit_InvalidPosition_ThrowsException() { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); coordinateServiceStub.Setup(x => x.Create(2, 2)) .Returns(new Coordinate { X = 2, Y = 2 }); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create("1 1"); Assert.Throws <Exception>(() => boardService.CreateExit("2 2")); }
public void CreateExit_StringCommand_ReturnsExitCoordinateY(string exitCoordinate, int exitCoordinateX, int exitCoordinateY, string boardDimension) { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); coordinateServiceStub.Setup(x => x.Create(exitCoordinateX, exitCoordinateY)).Returns(new Coordinate { X = exitCoordinateX, Y = exitCoordinateY }); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create(boardDimension); boardService.CreateExit(exitCoordinate); var result = boardService.GetBoard().ExitPoint.Y; Assert.Equal(exitCoordinateY, result); }
public void CreateExit_StringCommand_ReturnsExitCoordinate() { var mineServiceStub = new Mock <IMineService>(); var coordinateServiceStub = new Mock <ICoordinateService>(); coordinateServiceStub.Setup(x => x.Create(0, 0)).Returns(new Coordinate { X = 0, Y = 0 }); var boardService = new BoardService(mineServiceStub.Object, coordinateServiceStub.Object); boardService.Create("1 1"); boardService.CreateExit("0 0"); var result = boardService.GetBoard().ExitPoint; Assert.NotNull(result); }
public void Create_saves_a_board_via_context() { var mockSet = new Mock <DbSet <Board> >(); var mockContext = new Mock <TrelloDbContext>(); mockContext.Setup(m => m.tblBoard).Returns(mockSet.Object); var service = new BoardService(mockContext.Object); service.Create(new Board() { Name = "BoardTest" }); mockSet.Verify(m => m.Add(It.IsAny <Board>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }