Example #1
0
        public void CorrectMessage_WhenValidParametersArePassed()
        {
            //Arrange
            var validBoarName = "Valid";
            var validTeamname = "ValidTeam";

            var boardMock = new Mock <IBoard>();

            var teamMock = new Mock <ITeam>();
            // teamMock.Setup(x => x.AddBoardToTeam(It.IsAny<IBoard>()));

            var historyEventWriterMock = new Mock <IHistoryEventWriter>();

            var componentsFactoryMock = new Mock <IComponentsFactory>();

            componentsFactoryMock.Setup(x => x.CreateBoard(validBoarName, teamMock.Object)).Returns(boardMock.Object);

            var gettersMock = new Mock <IGetters>();

            gettersMock.Setup(x => x.GetTeam(validTeamname)).Returns(teamMock.Object);

            var sut        = new CreateBoardCommand(historyEventWriterMock.Object, componentsFactoryMock.Object, gettersMock.Object);
            var parameters = new List <string>()
            {
                validBoarName, validTeamname
            };

            var expectedReturn = string.Format(CommandsConsts.ObjectCreated, nameof(Board), validBoarName);

            //Act
            var actualReturn = sut.Execute(parameters);

            //Assert
            Assert.AreEqual(expectedReturn, actualReturn);
        }
Example #2
0
        public void ThrowArgumentException_WhenNullBoardIsReturned()
        {
            //Arrange
            var validBoarName = "Valid";
            var validTeamname = "ValidTeam";

            var boardMock = new Mock <IBoard>();

            var teamMock = new Mock <ITeam>();

            var historyEventWriterMock = new Mock <IHistoryEventWriter>();

            var componentsFactoryMock = new Mock <IComponentsFactory>();

            var gettersMock = new Mock <IGetters>();

            gettersMock.Setup(x => x.GetTeam(validTeamname)).Returns(teamMock.Object);

            var sut        = new CreateBoardCommand(historyEventWriterMock.Object, componentsFactoryMock.Object, gettersMock.Object);
            var parameters = new List <string>()
            {
                validBoarName, validTeamname
            };

            //Act, Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(parameters));
        }
Example #3
0
        public void ExecuteAllFourMethodsOnce_WhenValidParametersArePassed()
        {
            //Arrange
            var validBoarName = "Valid";
            var validTeamname = "ValidTeam";

            var boardMock = new Mock <IBoard>();

            var teamMock = new Mock <ITeam>();

            var historyEventWriterMock = new Mock <IHistoryEventWriter>();

            var componentsFactoryMock = new Mock <IComponentsFactory>();

            componentsFactoryMock.Setup(x => x.CreateBoard(validBoarName, teamMock.Object)).Returns(boardMock.Object);

            var gettersMock = new Mock <IGetters>();

            gettersMock.Setup(x => x.GetTeam(validTeamname)).Returns(teamMock.Object);

            var sut        = new CreateBoardCommand(historyEventWriterMock.Object, componentsFactoryMock.Object, gettersMock.Object);
            var parameters = new List <string>()
            {
                validBoarName, validTeamname
            };

            //Act
            sut.Execute(parameters);

            //Assert
            gettersMock.Verify(x => x.GetTeam(validTeamname), Times.Once);
            componentsFactoryMock.Verify(x => x.CreateBoard(validBoarName, teamMock.Object), Times.Once);
            teamMock.Verify(x => x.AddBoardToTeam(It.IsAny <IBoard>()), Times.Once);
            historyEventWriterMock.Verify(x => x.AddHistoryEvent(It.IsAny <string>(), null, boardMock.Object, teamMock.Object, null), Times.Once);
        }
Example #4
0
        public void CreateBoard()
        {
            var command = new CreateBoardCommand("A board");
            var id      = command.Execute(_model);
            var board   = _model.Boards.Values.Single();

            Assert.AreEqual(id, board.Id);
            Assert.AreEqual(command.BoardName, board.Name);
        }
Example #5
0
        public void BoardCreation_Execute_Less_Params_ThrowEx()
        {
            //Arrange
            var list = new List <string>();
            var fakeBoardProvider = new FakeBoardProvider();

            var sut = new CreateBoardCommand(list, fakeBoardProvider);

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => sut.Execute(), "Parameters count is not valid!");
        }
Example #6
0
        public void ThrowExeptionWhenCommandParametersAreLessThanItShoul()
        {
            string name  = "BoardName";
            IBoard board = new Board(name);

            database.Boards.Add(board);

            List <string> parameters = new List <string>
            {
            };

            CreateBoardCommand command = new CreateBoardCommand(parameters);

            command.Execute();
            Assert.IsTrue(database.Boards.Any(x => x.Name == name));
        }
Example #7
0
        public void BoardCreation_Execute_BoardWithSameNameAlreadyExists_ThrowEx()
        {
            //Arrange
            Commons.currentTeam = new Team("FakeTeamName");
            var list = new List <string>()
            {
                "BoardName"
            };
            var fakeBoardProvider = new FakeBoardProvider();

            fakeBoardProvider.Add(new Board("BoardName"));

            var sut = new CreateBoardCommand(list, fakeBoardProvider);

            Assert.ThrowsException <ArgumentException>(() => sut.Execute(), "Board with name BoardName already exists." + Environment.NewLine +
                                                       $"You can see all available boards with command listboards.");
        }
Example #8
0
        public void CreateBoardSuccess()
        {
            //Arrange
            Commons.currentTeam = new Team("FakeTeamName");
            var list = new List <string>()
            {
                "BoardName"
            };
            var fakeBoardProvider = new FakeBoardProvider();

            var sut = new CreateBoardCommand(list, fakeBoardProvider);
            //Act
            var result = sut.Execute();

            //Assert
            Assert.IsTrue(result.StartsWith("Created Board"));
        }
Example #9
0
        public void CreateBoardCommand()
        {
            string name  = "BoardName";
            IBoard board = new Board(name);

            database.Boards.Add(board);

            List <string> parameters = new List <string>
            {
                name
            };

            CreateBoardCommand command = new CreateBoardCommand(parameters);

            command.Execute();
            Assert.IsTrue(database.Boards.Any(x => x.Name == name));
        }