Ejemplo n.º 1
0
        private void addTaskButton_Click(object sender, EventArgs e)
        {
            Task tempTask = new Task(nameTextBox.Text, 'u');

            tempTask.Description = descriptionTextBox.Text;
            tempTask.IsImportant = isImportantCheckBox.Checked;
            tempTask.CategoryId  = 1;
            if (isDeadlineCheckBox.Checked)
            {
                tempTask.Deadline = deadlineDateTimePicker.Value;
            }
            TaskHandler.AddTask(tempTask);
            Close();
            _masterForm.RefreshPanel();
        }
        public void AddTask_Failure_Test()
        {
            TaskViewModel taskVm = new TaskViewModel();

            taskVm.TaskName  = "testTask1";
            taskVm.StartDate = DateTime.Now;
            taskVm.EndDate   = DateTime.Now.AddDays(1);
            taskVm.Priority  = 10;
            taskVm.UserId    = 1;
            taskVm.ProjectId = 1;
            taskVm.TaskId    = 5;

            Task tsk2 = new Task();

            tsk2.TaskName  = "testTask1";
            tsk2.StartDate = DateTime.Now;
            tsk2.EndDate   = DateTime.Now.AddDays(1);
            tsk2.Priority  = 10;
            tsk2.UserId    = 1;
            tsk2.ProjectId = 1;
            tsk2.TaskId    = 6;

            Task tsk3 = new Task();

            tsk3.TaskName  = "testTask3";
            tsk3.StartDate = DateTime.Now;
            tsk3.EndDate   = DateTime.Now.AddDays(1);
            tsk3.Priority  = 10;
            tsk3.UserId    = 1;
            tsk3.ProjectId = 1;
            tsk3.TaskId    = 7;
            List <Task> tskList = new List <Task>();

            tskList.Add(tsk2);
            tskList.Add(tsk3);
            IQueryable <Task> Tasks = tskList.AsQueryable();
            var mockRepo            = new Mock <ITaskRepository>();

            mockRepo.Setup(p => p.GetAllTask()).Returns(Tasks);
            var handler = new TaskHandler(mockRepo.Object);

            Assert.That(() => handler.AddTask(taskVm),
                        Throws.TypeOf <CustomException>());
            mockRepo.Verify(mock => mock.GetAllTask(), Times.Once());
        }