public void CallTheUsersPropertyIndexerOfTheProject_WithThePassedId()
        {
            // Arrange
            var databaseMock = new Mock <IDatabase>();
            var factoryMock  = new Mock <IModelsFactory>();
            var projectMock  = new Mock <IProject>();
            var userMock     = new Mock <IUser>();

            int projectId = 0;
            int userId    = 0;

            IList <string> parameters = new List <string>()
            {
                "0",
                "0",
                "BuildTheStar",
                "Pending"
            };

            databaseMock.Setup(d => d.Projects[projectId]).Returns(projectMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Users[userId]).Returns(userMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Tasks).Returns(new List <ITask>());

            ICommand createTaskCommand = new CreateTaskCommand(databaseMock.Object, factoryMock.Object);

            // Act
            createTaskCommand.Execute(parameters);

            // Assert
            databaseMock.Verify(d => d.Projects[projectId].Users[userId], Times.Exactly(2));
        }
示例#2
0
        public void Execute_CallsUsersIndex_WithCorrectId()
        {
            // Arrange
            var userStub = new Mock <IUser>();

            var projectMock = new Mock <IProject>();

            projectMock.Setup(x => x.Users[0]).Returns(userStub.Object);
            projectMock.Setup(x => x.Tasks.Add(It.IsAny <ITask>()));

            var databaseStub = new Mock <IDatabase>();

            databaseStub.Setup(x => x.Projects[0]).Returns(projectMock.Object);


            var factoryStub   = new Mock <IModelsFactory>();
            var expectedIndex = 0;

            var sut = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };

            // Act
            sut.Execute(validParameters);

            // Assert
            projectMock.Verify(x => x.Users[expectedIndex], Times.Once);
        }
        public void Execute_ShouldInvokeProjectsPropertyIndexer_WhenPassedValidProjectId(int projectId)
        {
            var databaseMock = new Mock <IDatabase>();
            var factoryStub  = new Mock <IModelsFactory>();

            var projectStub = new Mock <IProject>();
            var userStub    = new Mock <IUser>();
            var taskStub    = new Mock <ITask>();

            var users = new List <IUser>()
            {
                userStub.Object
            };
            var tasks = new List <ITask>();

            projectStub.SetupGet(x => x.Users).Returns(users);
            projectStub.SetupGet(x => x.Tasks).Returns(tasks);

            var userId    = 0;
            var taskName  = "Pesho";
            var taskState = "Pending";

            databaseMock.SetupGet(x => x.Projects[projectId]).Returns(projectStub.Object);
            factoryStub.Setup(x => x.CreateTask(userStub.Object, taskName, taskState)).Returns(taskStub.Object);

            var sut        = new CreateTaskCommand(databaseMock.Object, factoryStub.Object);
            var parameters = new List <string>()
            {
                projectId.ToString(), userId.ToString(), taskName, taskState
            };

            sut.Execute(parameters);

            databaseMock.Verify(x => x.Projects[projectId], Times.Once);
        }
示例#4
0
        public void CreateATaskWithExactlyThoseParameters_WhenInvokedWithValidParameters()
        {
            // Arrange
            var databaseStub    = new Mock <IDatabase>();
            var factoryStub     = new Mock <IModelsFactory>();
            var projectMock     = new Mock <IProject>();
            var ownerStub       = new Mock <IUser>();
            var taskMock        = new Mock <ITask>();
            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };
            var createTaskCommand = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            databaseStub.Setup(db => db.Projects).Returns(new List <IProject> {
                projectMock.Object
            });

            projectMock.Setup(p => p.Users).Returns(new List <IUser> {
                ownerStub.Object
            });
            projectMock.Setup(p => p.Tasks).Returns(new List <ITask>());

            // Act
            createTaskCommand.Execute(validParameters);

            // Assert
            Assert.AreEqual("Pending", projectMock.Object.Tasks[0].State);
            Assert.AreEqual("BuildTheStar", projectMock.Object.Tasks[0].Name);
            Assert.AreEqual(ownerStub.Object, projectMock.Object.Tasks[0].Owner);
        }
示例#5
0
        private void NewTaskCommand_Executed(object sender, RoutedEventArgs e)
        {
            CreateTaskCommand CreateClick = new CreateTaskCommand(this);

            CreateClick.Execute();
            ViewableTasks.View.Refresh();
        }
示例#6
0
        public void CallsProjectsPropertyIndexer_WhenInvokedWithValidParameters()
        {
            // Arrange
            var databaseMock    = new Mock <IDatabase>();
            var factoryStub     = new Mock <IModelsFactory>();
            var projectStub     = new Mock <IProject>();
            var ownerStub       = new Mock <IUser>();
            var taskStub        = new Mock <ITask>();
            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };
            var createTaskCommand = new CreateTaskCommand(databaseMock.Object, factoryStub.Object);

            databaseMock.Setup(db => db.Projects).Returns(new List <IProject> {
                projectStub.Object
            });
            databaseMock.SetupGet(db => db.Projects[It.IsAny <int>()]);

            projectStub.Setup(p => p.Users).Returns(new List <IUser> {
                ownerStub.Object
            });
            projectStub.Setup(p => p.Tasks).Returns(new List <ITask> {
                taskStub.Object
            });

            // Act
            createTaskCommand.Execute(validParameters);

            // Assert
            databaseMock.Verify(db => db.Projects[It.IsAny <int>()], Times.Once);
        }
示例#7
0
        public void Execute_AddsTask_ToProject()
        {
            // Arrange
            var taskStub = new Mock <ITask>();

            var userStub = new Mock <IUser>();

            var projectsMock = new Mock <IProject>();

            projectsMock.Setup(x => x.Users[0]).Returns(userStub.Object);
            projectsMock.Setup(x => x.Tasks.Add(It.IsAny <ITask>()));

            var databaseStub = new Mock <IDatabase>();

            databaseStub.Setup(x => x.Projects[0]).Returns(projectsMock.Object);

            var factoryStub = new Mock <IModelsFactory>();

            factoryStub.Setup(x => x.CreateTask(userStub.Object, "BuildTheStar", "Pending")).Returns(taskStub.Object);

            var sut = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };

            // Act
            sut.Execute(validParameters);

            // Assert

            projectsMock.Verify(x => x.Tasks.Add(taskStub.Object), Times.Once);
        }
示例#8
0
        public void ReturnMessegeContainingSuccessfullyCreated_WhenInvokedWithValidParameters()
        {
            // Arrange
            var databaseStub    = new Mock <IDatabase>();
            var factoryStub     = new Mock <IModelsFactory>();
            var projectMock     = new Mock <IProject>();
            var ownerStub       = new Mock <IUser>();
            var taskStub        = new Mock <ITask>();
            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };
            var createTaskCommand = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            databaseStub.Setup(db => db.Projects).Returns(new List <IProject> {
                projectMock.Object
            });

            projectMock.Setup(p => p.Users).Returns(new List <IUser> {
                ownerStub.Object
            });
            projectMock.Setup(p => p.Tasks).Returns(new List <ITask>());

            // Act
            string result = createTaskCommand.Execute(validParameters);

            // Assert
            StringAssert.Contains("Successfully created", result);
        }
示例#9
0
        public void AddTheCreatedTaskToTheProject_WhenInvokedWithValidParameters()
        {
            // Arrange
            var databaseStub    = new Mock <IDatabase>();
            var factoryStub     = new Mock <IModelsFactory>();
            var projectMock     = new Mock <IProject>();
            var ownerStub       = new Mock <IUser>();
            var taskStub        = new Mock <ITask>();
            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };
            var createTaskCommand = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            databaseStub.Setup(db => db.Projects).Returns(new List <IProject> {
                projectMock.Object
            });

            projectMock.Setup(p => p.Users).Returns(new List <IUser> {
                ownerStub.Object
            });
            projectMock.Setup(p => p.Tasks).Returns(new List <ITask>());

            // Act
            createTaskCommand.Execute(validParameters);

            // Assert
            Assert.AreEqual(1, projectMock.Object.Tasks.Count);
        }
示例#10
0
        public void ExecuteMethod_ShouldThrowException_WhenInvalidParametersCountPassed(int parametersCount)
        {
            // Arrange
            var parameters   = new List <string>(parametersCount);
            var dataBaseMock = new Mock <IDatabase>();

            var sut = new CreateTaskCommand(dataBaseMock.Object);

            // Act & Assert
            Assert.Throws <UserValidationException>(() => sut.Execute(parameters));
        }
示例#11
0
        public void ClientCreateTaskRequest(string name, string description, string tags)
        {
            Console.WriteLine("\nReceived request to: Create task " + name);
            User mUser = FindUser(Context.ConnectionId);

            CreateTaskCommand mCreateTask = new CreateTaskCommand(mUser, name, description, tags);

            mCreateTask.Execute();

            Clients.Clients(mUser.ConnectionIDs).ReceiveUpdatedTasks(mUser.Tasks);
        }
示例#12
0
        public void ThrowUserValidationException_WhenEmptyParametersArePassed()
        {
            var databaseStub      = new Mock <IDatabase>();
            var factoryStub       = new Mock <IModelsFactory>();
            var invalidParameters = new List <string>()
            {
                ""
            };
            var createTaskCommand = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            Assert.Throws <UserValidationException>(() => createTaskCommand.Execute(invalidParameters));
        }
        public void Execute_ShouldThrowUserValidationException_WhenPassedInvalidParametersContent()
        {
            var databaseMock = new Mock <IDatabase>();
            var factoryStub  = new Mock <IModelsFactory>();

            var sut        = new CreateTaskCommand(databaseMock.Object, factoryStub.Object);
            var parameters = new List <string>()
            {
                string.Empty, string.Empty, string.Empty, string.Empty
            };

            Assert.Throws <UserValidationException>(() => sut.Execute(parameters));
        }
示例#14
0
        public void ExecuteMethod_ShouldThrowException_WhenEmptyParametersPassed()
        {
            // Arrange
            var parameters   = new List <string>();
            var dataBaseMock = new Mock <IDatabase>();

            var sut = new CreateTaskCommand(dataBaseMock.Object);

            // Act
            string item = String.Empty;

            parameters.Add(item);

            // Act & Assert
            Assert.Throws <UserValidationException>(() => sut.Execute(parameters));
        }
        public void Execute_ShouldThrowUserValidationException_WhenPassedInvalidParametersCount()
        {
            var databaseMock = new Mock <IDatabase>();
            var factoryStub  = new Mock <IModelsFactory>();

            var projectId = 0;
            var userId    = 0;
            var taskName  = "Pesho";

            var sut        = new CreateTaskCommand(databaseMock.Object, factoryStub.Object);
            var parameters = new List <string>()
            {
                projectId.ToString(), userId.ToString(), taskName
            };

            Assert.Throws <UserValidationException>(() => sut.Execute(parameters));
        }
示例#16
0
        public void Execute_Throws_WhenEmptyParametersArePassed()
        {
            // Arrange
            var databaseStub    = new Mock <IDatabase>();
            var factoryStub     = new Mock <IModelsFactory>();
            var expectedMessage = "Some of the passed parameters are empty!";

            var sut = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            var invalidParameters = new List <string>()
            {
                "one", "two", "thre", ""
            };

            // Act and Assert

            Assert.Catch <UserValidationException>(() => sut.Execute(invalidParameters), expectedMessage);
        }
示例#17
0
        public void Execute_Throws_WhenInvalidParametersCountIsPassed()
        {
            // Arrange
            var databaseStub    = new Mock <IDatabase>();
            var factoryStub     = new Mock <IModelsFactory>();
            var expectedMessage = "Invalid command parameters count!";

            var sut = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            var invalidParameters = new List <string>()
            {
                "one"
            };

            // Act and Assert

            Assert.Catch <UserValidationException>(() => sut.Execute(invalidParameters), expectedMessage);
        }
        public void ThrowUserValidationException_WhenTheParametersCountIsInvalid()
        {
            // Arrange
            var databaseMock = new Mock <IDatabase>();
            var factoryMock  = new Mock <IModelsFactory>();

            IList <string> parameters = new List <string>()
            {
                "parameter 1",
                "parameter 2",
                "parameter 3"
            };

            ICommand createTaskCommand = new CreateTaskCommand(databaseMock.Object, factoryMock.Object);

            // Act && Assert
            Assert.Throws <UserValidationException>(() => createTaskCommand.Execute(parameters));
        }
        public void AddTheTaskToTheProjectsTasks()
        {
            // Arrange
            var databaseMock = new Mock <IDatabase>();
            var factoryMock  = new Mock <IModelsFactory>();
            var projectMock  = new Mock <IProject>();
            var userMock     = new Mock <IUser>();
            var taskMock     = new Mock <ITask>();

            int    projectId         = 0;
            int    userId            = 0;
            string taskName          = "BuildTheStar";
            string taskStateAsString = "Pending";

            IList <string> parameters = new List <string>()
            {
                "0",
                "0",
                taskName,
                taskStateAsString
            };

            IList <ITask> tasks = new List <ITask>();

            databaseMock.Setup(d => d.Projects[projectId]).Returns(projectMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Users[userId]).Returns(userMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Tasks).Returns(tasks);

            factoryMock.Setup(f => f.CreateTask(userMock.Object, taskName, taskStateAsString)).Returns(taskMock.Object);

            ICommand createTaskCommand = new CreateTaskCommand(databaseMock.Object, factoryMock.Object);

            // Act
            createTaskCommand.Execute(parameters);

            // Assert
            Assert.AreEqual(1, tasks.Count);
            Assert.That(tasks.Contains(taskMock.Object));
        }
        public void Execute_ShouldAddCreatedTaskToProject_WhenPassedValidParameters()
        {
            var databaseStub = new Mock <IDatabase>();
            var factoryStub  = new Mock <IModelsFactory>();

            var projectMock = new Mock <IProject>();
            var userStub    = new Mock <IUser>();
            var taskStub    = new Mock <ITask>();

            var users = new List <IUser>()
            {
                userStub.Object
            };
            var tasks = new List <ITask>();

            projectMock.SetupGet(x => x.Users).Returns(users);
            projectMock.SetupGet(x => x.Tasks).Returns(tasks);

            var projectId = 0;
            var userId    = 0;
            var taskName  = "Pesho";
            var taskState = "Pending";

            projectMock.SetupGet(x => x.Users[It.IsAny <int>()]).Returns(userStub.Object);
            databaseStub.SetupGet(x => x.Projects[It.IsAny <int>()]).Returns(projectMock.Object);

            factoryStub.Setup(x => x.CreateTask(userStub.Object, taskName, taskState)).Returns(taskStub.Object);

            var sut        = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);
            var parameters = new List <string>()
            {
                projectId.ToString(), userId.ToString(), taskName, taskState
            };

            sut.Execute(parameters);

            Assert.AreEqual(1, tasks.Count);
            Assert.That(tasks.Contains(taskStub.Object));
        }
        public void ReturnSuccessMessage_WhenTheTaskIsAddedToTheProjectTasks()
        {
            // Arrange
            var databaseMock = new Mock <IDatabase>();
            var factoryMock  = new Mock <IModelsFactory>();
            var projectMock  = new Mock <IProject>();
            var userMock     = new Mock <IUser>();
            var taskMock     = new Mock <ITask>();

            int    projectId         = 0;
            int    userId            = 0;
            string taskName          = "BuildTheStar";
            string taskStateAsString = "Pending";
            string successMessage    = "Successfully created";

            IList <string> parameters = new List <string>()
            {
                "0",
                "0",
                taskName,
                taskStateAsString
            };

            IList <ITask> tasks = new List <ITask>();

            databaseMock.Setup(d => d.Projects[projectId]).Returns(projectMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Users[userId]).Returns(userMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Tasks).Returns(tasks);

            factoryMock.Setup(f => f.CreateTask(userMock.Object, taskName, taskStateAsString)).Returns(taskMock.Object);

            ICommand createTaskCommand = new CreateTaskCommand(databaseMock.Object, factoryMock.Object);

            // Act
            string executionResult = createTaskCommand.Execute(parameters);

            // Assert
            StringAssert.Contains(successMessage, executionResult);
        }
        public void Execute_ShouldCreateTaskWithExactPassedParameteres_WhenPassedValidParameters()
        {
            var databaseStub = new Mock <IDatabase>();
            var factoryMock  = new Mock <IModelsFactory>();

            var projectStub = new Mock <IProject>();
            var userStub    = new Mock <IUser>();
            var taskStub    = new Mock <ITask>();

            var users = new List <IUser>()
            {
                userStub.Object
            };
            var tasks = new List <ITask>();

            projectStub.SetupGet(x => x.Users).Returns(users);
            projectStub.SetupGet(x => x.Tasks).Returns(tasks);

            var projectId = 0;
            var userId    = 0;
            var taskName  = "Pesho";
            var taskState = "Pending";

            projectStub.SetupGet(x => x.Users[It.IsAny <int>()]).Returns(userStub.Object);
            databaseStub.SetupGet(x => x.Projects[It.IsAny <int>()]).Returns(projectStub.Object);

            factoryMock.Setup(x => x.CreateTask(userStub.Object, taskName, taskState)).Returns(taskStub.Object);

            var sut        = new CreateTaskCommand(databaseStub.Object, factoryMock.Object);
            var parameters = new List <string>()
            {
                projectId.ToString(), userId.ToString(), taskName, taskState
            };

            sut.Execute(parameters);

            factoryMock.Verify(x => x.CreateTask(userStub.Object, taskName, taskState), Times.Exactly(1));
        }
        public void Execute_ShouldReturnAppropriateMessage_WhenPassedValidParameters()
        {
            var databaseStub = new Mock <IDatabase>();
            var factoryStub  = new Mock <IModelsFactory>();

            var projectStub = new Mock <IProject>();
            var userStub    = new Mock <IUser>();
            var taskStub    = new Mock <ITask>();

            var users = new List <IUser>()
            {
                userStub.Object
            };
            var tasks = new List <ITask>();

            projectStub.SetupGet(x => x.Users).Returns(users);
            projectStub.SetupGet(x => x.Tasks).Returns(tasks);

            var projectId = 0;
            var userId    = 0;
            var taskName  = "Pesho";
            var taskState = "Pending";

            projectStub.SetupGet(x => x.Users[It.IsAny <int>()]).Returns(userStub.Object);
            databaseStub.SetupGet(x => x.Projects[It.IsAny <int>()]).Returns(projectStub.Object);

            factoryStub.Setup(x => x.CreateTask(userStub.Object, taskName, taskState)).Returns(taskStub.Object);

            var sut        = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);
            var parameters = new List <string>()
            {
                projectId.ToString(), userId.ToString(), taskName, taskState
            };

            var executionResult = sut.Execute(parameters);

            Assert.That(executionResult.Contains("Successfully created"));
        }
示例#24
0
        public void Execute_ReturnsCorrectMessage_WhenMethodIsPerformedSuccessfully()
        {
            // Arrange
            var expectedOutput = "Successfully created";

            var taskStub = new Mock <ITask>();

            var userStub = new Mock <IUser>();

            var projectStub = new Mock <IProject>();

            projectStub.Setup(x => x.Users[0]).Returns(userStub.Object);
            projectStub.Setup(x => x.Tasks.Add(It.IsAny <ITask>()));

            var databaseStub = new Mock <IDatabase>();

            databaseStub.Setup(x => x.Projects[0]).Returns(projectStub.Object);

            var factoryStub = new Mock <IModelsFactory>();

            factoryStub.Setup(x => x.CreateTask(userStub.Object, "BuildTheStar", "Pending")).Returns(taskStub.Object);

            var sut = new CreateTaskCommand(databaseStub.Object, factoryStub.Object);

            var validParameters = new List <string>()
            {
                "0", "0", "BuildTheStar", "Pending"
            };

            // Act
            var outputMessage = sut.Execute(validParameters);

            // Assert

            StringAssert.Contains(expectedOutput, outputMessage);
        }
        public void CreateTask_WithExactlyThoseParameters()
        {
            // Arrange
            var databaseMock = new Mock <IDatabase>();
            var factoryMock  = new Mock <IModelsFactory>();
            var projectMock  = new Mock <IProject>();
            var userMock     = new Mock <IUser>();
            var taskMock     = new Mock <ITask>();

            int    projectId         = 0;
            int    userId            = 0;
            string taskName          = "BuildTheStar";
            string taskStateAsString = "Pending";

            IList <string> parameters = new List <string>()
            {
                "0",
                "0",
                taskName,
                taskStateAsString
            };

            databaseMock.Setup(d => d.Projects[projectId]).Returns(projectMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Users[userId]).Returns(userMock.Object);
            databaseMock.Setup(d => d.Projects[projectId].Tasks).Returns(new List <ITask>());

            factoryMock.Setup(f => f.CreateTask(userMock.Object, taskName, taskStateAsString)).Returns(taskMock.Object);

            ICommand createTaskCommand = new CreateTaskCommand(databaseMock.Object, factoryMock.Object);

            // Act
            createTaskCommand.Execute(parameters);

            // Assert
            factoryMock.Verify(f => f.CreateTask(userMock.Object, taskName, taskStateAsString), Times.Once());
        }