public async Task Handle_AnyCardNotBelongsToSameBoard_ThrowsInvalidOperationApplicationException() { var dbName = $"{nameof(ReorderCardsCommandHandlerTests)}_{nameof(Handle_AnyCardNotBelongsToSameBoard_ThrowsInvalidOperationApplicationException)}"; var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board1 = boardFactory.Create("board1-title"); var board2 = boardFactory.Create("board2-title"); var card1 = Card.Create("card1-title"); var card2 = Card.Create("card2-title"); board1.AddCard(card1); board2.AddCard(card2); context.Boards.AddRange(board1, board2); await context.SaveChangesAsync(cancellationToken); var handler = new ReorderCardsCommandHandler(context, new CardService()); var request = new ReorderCardsCommand { CardIds = new List <int> { 1, 2 } }; Task <Unit> action() => handler.Handle(request, cancellationToken); await Assert.ThrowsAsync <InvalidOperationApplicationException>(action); }
public async Task Handle_HasBoards_FiltersByBoardUser() { var factory = new BoardUserFactory(); var dbName = $"{nameof(GetBoardsListQueryHandlerTests)}_{nameof(Handle_HasBoards_FiltersByBoardUser)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var userId = "user-id"; _currentUser.Setup(u => u.UserId).Returns(userId); var boardFactory = new BoardFactory(); var board1 = boardFactory.Create("board1-title"); var board2 = boardFactory.Create("board2-title"); var boardUser = factory.CreateOwner(1, userId); context.Boards.AddRange(board1, board2); context.BoardUsers.Add(boardUser); await context.SaveChangesAsync(cancellationToken); var handler = new GetBoardsListQueryHandler(context, _currentUser.Object); var dto = await handler.Handle(new GetBoardsListQuery(), cancellationToken); Assert.Single(dto.Boards); Assert.Equal(boardUser.BoardId, dto.Boards.First().Id); }
public void Create_WithoutInitialValues_MustSucceed() { // Arrange var configuration = new SudokuConfiguration(); // Act var board = factory.Create(configuration); // Assert board.Sections.Length.Should().Be(9); }
public void Create([NUnit.Framework.Range(1, 5)] int w, [NUnit.Framework.Range(1, 5)] int h) { boardFactory.Create(w, h); Assert.AreEqual(w + h + 2, board.transform.childCount - 1); for (int i = 0; i < board.transform.childCount; ++i) { var child = board.transform.GetChild(i).gameObject; if (child.name == "BoardBase") { Assert.IsTrue(FloatEqualityComparer.Instance.Equals(w, child.transform.localScale.x)); Assert.IsTrue(FloatEqualityComparer.Instance.Equals(h, child.transform.localScale.z)); } else { if (child.transform.localScale.x > 0.01) { Assert.IsTrue(FloatEqualityComparer.Instance.Equals(0, child.transform.position.x)); } else if (child.transform.localScale.z > 0.01) { Assert.IsTrue(FloatEqualityComparer.Instance.Equals(0, child.transform.position.z)); } else { Assert.IsTrue(false, $"Scale/Position of {i}-th child (Line) is not valid."); } } } }
public async Task Handle_AccessCodeFound_CreateBoardUser() { var dbName = $"{nameof(JoinBoardCommandHandlerTests)}_{nameof(Handle_AccessCodeFound_CreateBoardUser)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var userId = "user-id"; _currentUser.Setup(u => u.UserId).Returns(userId); var handler = new JoinBoardCommandHandler(context, _currentUser.Object, new BoardUserFactory()); var command = new JoinBoardCommand { AccessCode = board.AccessCode }; var dto = await handler.Handle(command, cancellationToken); var boardUser = await context.BoardUsers .FirstOrDefaultAsync(bu => bu.BoardId == board.Id && bu.UserId == userId); Assert.NotNull(boardUser); Assert.Equal(board.Id, dto.BoardId); }
public async Task Handle_BoardIdExists_ReturnDto() { var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdExists_ReturnDto)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var card = Card.Create("card-title"); var activity = Activity.Create("activity-title"); board.AddCard(card); card.AddActivity(activity); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var handler = new GetBoardQueryHandler(context); var request = new GetBoardQuery(1); var dto = await handler.Handle(request, cancellationToken); var dtoCard = dto.Cards.FirstOrDefault(); var dtoActivity = dtoCard.Activities.FirstOrDefault(); Assert.NotNull(dto); Assert.Equal(1, dto.Id); Assert.NotNull(dto.Cards); Assert.Single(dto.Cards); Assert.Equal(1, dtoCard.Id); Assert.NotNull(dtoCard.Activities); Assert.Single(dtoCard.Activities); Assert.Equal(1, dtoActivity.Id); }
public async Task Handle_AllCardsExistAndBelongToSameBoard_ReordersCards() { var dbName = $"{nameof(ReorderCardsCommandHandlerTests)}_{nameof(Handle_AllCardsExistAndBelongToSameBoard_ReordersCards)}"; var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var card1 = Card.Create("card1-title"); var card2 = Card.Create("card2-title"); board.AddCard(card1); board.AddCard(card2); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var handler = new ReorderCardsCommandHandler(context, new CardService()); var request = new ReorderCardsCommand { CardIds = new List <int> { 2, 1 } }; await handler.Handle(request, cancellationToken); var card1FromDb = await context.Cards.FirstOrDefaultAsync(c => c.Id == 1, cancellationToken); var card2FromDb = await context.Cards.FirstOrDefaultAsync(c => c.Id == 2, cancellationToken); Assert.NotNull(card1FromDb); Assert.NotNull(card2FromDb); Assert.Equal(0, card2FromDb.Order); Assert.Equal(1, card1FromDb.Order); }
public async Task Handle_BoardIdExists_ReturnsCardsInOrder() { var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdExists_ReturnsCardsInOrder)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var card1 = Card.Create("card1-title", 1); var card2 = Card.Create("card2-title", 0); board.AddCard(card1); board.AddCard(card2); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var orderedCardIds = await context.Cards .Where(c => c.BoardId == board.Id) .OrderBy(c => c.Order) .Select(c => c.Id) .ToListAsync(cancellationToken); var handler = new GetBoardQueryHandler(context); var request = new GetBoardQuery(1); var dto = await handler.Handle(request, cancellationToken); var dtoCardIds = dto.Cards.Select(c => c.Id).ToList(); Assert.Equal(orderedCardIds, dtoCardIds); }
public async Task Handle_BoardIdExists_EditsBoard() { var dbName = $"{nameof(EditBoardCommandHandlerTests)}_{nameof(Handle_BoardIdExists_EditsBoard)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var editedTitle = "edited-title"; var handler = new EditBoardCommandHandler(context); var request = new EditBoardCommand { BoardId = 1, Title = editedTitle }; await handler.Handle(request, cancellationToken); var boardFromDb = await context.Boards.FirstOrDefaultAsync(b => b.Id == 1, cancellationToken); Assert.NotNull(boardFromDb); Assert.Equal(editedTitle, boardFromDb.Title); }
public void Awake() { var tileStyleRepository = new TileStyleRepository(); var tileStyle = tileStyleRepository.ObtainDefault(); var tileFactory = new TileFactory(); var boardFactory = new BoardFactory(tileFactory); var boardSettingsRepository = new BoardSettingsRepository(); var boardSettings = boardSettingsRepository.ObtainDefault(); var board = boardFactory.Create(boardSettings, tileStyle); var boardMouseEventsNotifier = new MouseEventsNotifier(board); boardMouseEventsNotifier.Enable(); var ballSelectionEventsNotifier = new BallSelectionEventsNotifier(boardMouseEventsNotifier); ballSelectionEventsNotifier.Enable(); var pathfinder = new Pathfinder(); var ballMoveControllerFactory = new BallMoveControllerFactory(pathfinder); var ballMoveController = ballMoveControllerFactory.Create(ballSelectionEventsNotifier); ballMoveController.Enable(); var ballBounceManager = new BallBounceManager(board); var ballBounceController = new BallBounceController(ballSelectionEventsNotifier, ballBounceManager); ballBounceController.Enable(); var ballMaterialSettingsRepository = new BallMaterialSettingsRepository(); var ballStyleRepository = new BallStyleRepositoryFactory(ballMaterialSettingsRepository).Create(); var ballLifetimeManagerSettingsRepository = new BallLifetimeManagerSettingsRepository(); var ballLifetimeManagerSettings = ballLifetimeManagerSettingsRepository.ObtainDefault(); var ballFactory = new BallFactory(); var random = new System.Random(); var ballSpawnManagerFactory = new BallSpawnManagerFactory( ballLifetimeManagerSettings, ballStyleRepository, ballFactory, random ); var ballColorPool = new BallColorPoolRepository().ObtainDefault(); ballSpawnManager = ballSpawnManagerFactory.Create(board, ballColorPool); var ballPopManager = new BallPopManager(board); var ballLifespanController = new BallLifespanController(ballSpawnManager, ballPopManager); ballLifespanController.Enable(); var tileColorStyle = new TileColorStyle( TileColorStyleHelper.CreateVariantColorGroup( tileStyle.ColorStyle.ForegroundColorGroup.IdleColor ), tileStyle.ColorStyle.BorderColorGroup ); var boardHighlightController = new BoardHighlightController(boardMouseEventsNotifier, tileColorStyle); boardHighlightController.Enable(); }
public Game(TypeOfGame kindOfGame) { IBoardFactory boardFactory = new BoardFactory(); Chessboard = (ChessboardModel)boardFactory.Create(kindOfGame); PlayerColour = ColourOfPiece.White; }
public async Task HasPermissionForActivity_BoardUserExists_ReturnOutputOfIBoardUserPermissionService() { var userId = "user-id"; _currentUser.Setup(u => u.UserId).Returns(userId); _boardUserPermissionService.Setup(s => s.HasPermission(It.IsAny <BoardUser>(), It.IsAny <BoardUserPermission>())).Returns(true); var dbName = $"{nameof(CurrentUserPermissionServiceTests)}_{nameof(HasPermissionForActivity_BoardUserExists_ReturnOutputOfIBoardUserPermissionService)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var card = Card.Create("card-title"); var activity = Activity.Create("activity-title"); var boardUser = new BoardUserFactory().CreateOwner(1, userId); board.AddCard(card); card.AddActivity(activity); context.Boards.Add(board); context.BoardUsers.Add(boardUser); await context.SaveChangesAsync(cancellationToken); var service = new CurrentUserPermissionService(context, _currentUser.Object, _boardUserPermissionService.Object); var result = await service.HasPermissionForActivity(activity.Id, BoardUserPermission.CAN_VIEW_ACTIVITY, cancellationToken); Assert.True(result); }
public async Task Handle_BoardExists_ReturnsCardCreatedDtoWithCorrectPropValues() { var dbName = $"{nameof(AddCardToBoardCommandHandlerTests)}_{nameof(Handle_BoardExists_ReturnsCardCreatedDtoWithCorrectPropValues)}"; using var context = TestApplicationDbContext.Create(dbName); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var cancellationToken = new CancellationToken(); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var handler = new AddCardToBoardCommandHandler(context); var request = new AddCardToBoardCommand { BoardId = board.Id, Title = "card-title" }; var cardCreatedDto = await handler.Handle(request, cancellationToken); var card = await context.Cards.FirstOrDefaultAsync(c => c.BoardId == board.Id); Assert.NotNull(cardCreatedDto); Assert.Equal(card.Id, cardCreatedDto.CardId); Assert.Equal(card.BoardId, cardCreatedDto.BoardId); }
public async Task Handle_BoardIdExists_ReturnsBoardUserType() { var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdExists_ReturnsBoardUserType)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var boardUserFactory = new BoardUserFactory(); var userId = "user-id"; var board = boardFactory.Create("board-title"); var boardUser = boardUserFactory.CreateOwner(1, userId); var boardUserType = boardUser.Type.ToString().ToLower(); context.Boards.Add(board); context.BoardUsers.Add(boardUser); await context.SaveChangesAsync(cancellationToken); var handler = new GetBoardQueryHandler(context); var request = new GetBoardQuery(1); var dto = await handler.Handle(request, cancellationToken); Assert.Equal(boardUserType, dto.BoardUserType); }
public void Create_ReturnsBoardWithTitle() { var title = "test-title"; var factory = new BoardFactory(); var board = factory.Create(title); Assert.Equal(title, board.Title); }
public void Create_ReturnsBoardWithAccessCode() { var title = "test-title"; var factory = new BoardFactory(); var board = factory.Create(title); Assert.NotNull(board.AccessCode); Assert.NotEmpty(board.AccessCode); }
public void SetUp() { dice = new LoadedDice(); player1 = "Horse"; players = new List<String> { player1 }; banker = new Banker(players, 1500); var boardFactory = new BoardFactory(); var guard = new PrisonGuard(banker, dice); board = boardFactory.Create(banker, players, dice, guard); }
public void CrossoverTest() { //Arrange var boardA = BoardFactory.Create(rows, columns, 0.4); var boardB = BoardFactory.Create(rows, columns, 0.4); //Act var crossover = BoardFactory.Crossover(boardA, boardB, 1); //Assert Assert.AreEqual(boardA.Grid.Count, crossover.Grid.Count); Assert.AreEqual(boardA.Grid[0].Length, crossover.Grid[0].Length); }
public void RunningEmptyGridTest() { //Arrange var board = BoardFactory.Create(rows, columns, 0); _game = new Game(board); //Act _game.Play(maxIterationToPlay); //Assert Assert.AreEqual(1, _game.Generation); }
public void CheckMovies_Start_Positions_Test() { //Arrange var boardFactory = new BoardFactory(); var chessboard = (ChessboardModel)boardFactory.Create(TypeOfGame.Chess); //Act var possibleMovies = chessboard["a2"].Piece.CheckStrategy.CheckMovies(new Position("a2"), chessboard); var actual = possibleMovies.Count(); //Assert Assert.AreEqual(2, actual); }
public void MutationTest() { //Arrange var boardA = BoardFactory.Create(rows, columns, 0.4); const double maxMutationRation = 0.1; //Act var crossover = BoardFactory.Mutation(boardA, 1, maxMutationRation); //Assert var changes = CountChanges(boardA, crossover); var maxChanges = boardA.Rows * boardA.Columns * maxMutationRation; Assert.LessOrEqual(changes, maxChanges); }
public void IfAPlayerLandsOnGoToJailTheyGoToJail() { var jail = 10; var player = "Horse"; var players = new List<String> { player }; var banker = new Banker(players, 1500); var boardFactory = new BoardFactory(); var dice = new LoadedDice(); var guard = new PrisonGuard(banker, dice); var board = boardFactory.Create(banker, players, dice, guard); var goToJail = new GoToJail(board, jail, guard); goToJail.LandOnSpace(player); Assert.That(board.GetPosition(player), Is.EqualTo(10)); }
public static IBoard ParseBoard(string[] boardString, BoardProperties context, PositionManager positions) { if (context.RowSize != boardString.Length || boardString.Any(s => s.Length != context.ColSize)) { throw new ArgumentException("The board string does not consist with the board sizes in context."); } IBoardFactory boardFactory = new BoardFactory(context, positions); IBoard board = boardFactory.Create(); foreach (Position p in positions.Positions) { char pieceChar = boardString[p.Row][p.Col]; PieceType piece = CharToPiece[pieceChar]; board.Set(p, piece); } return(board); }
public async Task Handle_BoardIdExists_DeletesBoard() { var dbName = $"{nameof(DeleteBoardCommandHandlerTests)}_{nameof(Handle_BoardIdExists_DeletesBoard)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var handler = new DeleteBoardCommandHandler(context); var request = new DeleteBoardCommand(1); await handler.Handle(request, cancellationToken); var boardFromDb = await context.Boards.FirstOrDefaultAsync(b => b.Id == 1); Assert.Null(boardFromDb); }
public async Task HasPermissionForBoard_BoardUserNotExists_ReturnFalse() { var dbName = $"{nameof(CurrentUserPermissionServiceTests)}_{nameof(HasPermissionForBoard_BoardUserNotExists_ReturnFalse)}"; using var context = TestApplicationDbContext.Create(dbName); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var userId = "user-id"; _currentUser.Setup(u => u.UserId).Returns(userId); var service = new CurrentUserPermissionService(context, _currentUser.Object, _boardUserPermissionService.Object); var result = await service.HasPermissionForBoard(board.Id, BoardUserPermission.CAN_VIEW_BOARD, cancellationToken); Assert.False(result); }
public async Task SaveChangesAsync_EntityCreatedByUserIdSetToCurrentUserId() { var userId = "test-user-id-1"; _currentUser.Setup(u => u.UserId).Returns(userId); var dbName = $"{nameof(ApplicationDbContextTests)}_{nameof(SaveChangesAsync_EntityCreatedByUserIdSetToCurrentUserId)}"; using var context = CreateContext(dbName, _currentUser.Object); var cancellationToken = new CancellationToken(); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var boardFromDb = await context.Boards.IgnoreQueryFilters().FirstOrDefaultAsync(cancellationToken); Assert.NotNull(boardFromDb); Assert.Equal(userId, boardFromDb.CreatedByUserId); }
public void SetUp() { random = new Random(); dice = new Dice(random); player1 = "Horse"; player2 = "Car"; players = new List<String> { player1, player2 }; banker = new Banker(players, 1500); turns = new PlayerTurnCounter(players); var boardFactory = new BoardFactory(); guard = new PrisonGuard(banker, dice); board = boardFactory.Create(banker, players, dice, guard); game = new Game(players, dice, board, turns, guard); }
public void Setup() { var board = BoardFactory.Create(rows, columns, coverage); _game = new Game(board); }
public static CellularAutomaton CreateGameOfLife(int width, int height, BoardFactory boardFactory, NeighborshipInitializer neighborshipInitializer) { return(new CellularAutomaton(boardFactory.Create(width, height, neighborshipInitializer), new GameOfLifeUpdater())); }