public async Task Handle_AddBoardCommand_ShouldFailValidation_WhenEmptyBoardTitle()
        {
            // Arrange
            var command = new AddBoardCommand("");

            // Act
            var validationResult = await _boardCommandHandler.Handle(command, CancellationToken.None);

            // Assert
            Assert.False(validationResult.IsValid);
            Assert.Single(validationResult.Errors);
            Assert.Equal(UserMessages.RequiredField.Format("BoardTitle").Message, validationResult.Errors.First().ErrorMessage);
        }
        public async Task <AddBoardResponse> Handle(AddBoardRequest request, CancellationToken cancellationToken)
        {
            if (request.AuthenticatorRole == AppRole.Employee)
            {
                return(new AddBoardResponse()
                {
                    Error = new ErrorModel(ErrorType.Unauthorized)
                });
            }

            var query = new GetEmployeeQuery()
            {
                Id = request.EmployeeId
            };

            var employee = await queryExecutor.Execute(query);

            if (employee == null)
            {
                return(new AddBoardResponse()
                {
                    Error = new ErrorModel(ErrorType.NotFound)
                });
            }

            if (employee.Board != null)
            {
                return(new AddBoardResponse()
                {
                    Error = new ErrorModel(ErrorType.UnsupportedMethod)
                });
            }

            var board   = mapper.Map <Board>(request);
            var command = new AddBoardCommand()
            {
                Parameter = board
            };
            var boardFromDb = await commandExecutor.Execute(command);

            return(new AddBoardResponse()
            {
                Data = mapper.Map <BoardDto>(boardFromDb)
            });
        }
        public async Task Handle_AddBoardCommand_ShouldAddAndCommit_WhenValid()
        {
            // Arrange
            var command = new AddBoardCommand("Personal Board");

            _autoMocker.GetMock <IBoardRepository>()
            .Setup(x => x.UnitOfWork).Returns(_autoMocker.GetMock <IUnitOfWork>().Object);

            _autoMocker.GetMock <IUnitOfWork>()
            .Setup(x => x.Commit()).Returns(Task.FromResult(true));

            // Act
            var validationResult = await _boardCommandHandler.Handle(command, CancellationToken.None);

            // Assert
            _autoMocker.GetMock <IBoardRepository>()
            .Verify(x => x.Add(It.IsAny <Board>()), Times.Once);

            _autoMocker.GetMock <IUnitOfWork>()
            .Verify(x => x.Commit(), Times.Once);

            Assert.True(validationResult.IsValid);
        }
 public async Task <ActionResult <BoardsViewModel> > Add([FromBody] AddBoardCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }