/// <summary>
        /// Deliver a task
        /// </summary>
        /// <param name="studyId">Id of the study to deliver a task to</param>
        /// <param name="taskId">Id of the task to deliver</param>
        /// <param name="taskDto">TaskDTO containing the properties of the task be delivered</param>
        public void DeliverTask(int studyId, int taskId, TaskSubmissionDto taskDto)
        {
            var currentStudy = _studyStorageManager.GetAll()
                .Where(s => s.ID == studyId)
                .Include(s => s.Stages.Select(t => t.Tasks))
                .FirstOrDefault();

            if (currentStudy == null)
            {
                throw new NullReferenceException("Study not found");
            }
            if (!currentStudy.Team.Users.Select(u => u.ID).Contains(taskDto.UserId))
            {
                throw new ArgumentException("The user is not part of this study");
            }

            _taskManager.DeliverTask(taskId, taskDto);

            //Determine if the stage is finished
            if (currentStudy.CurrentStage().
                Tasks.TrueForAll(t => t.IsFinished()))
            {
                MoveToNextPhase(currentStudy);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Deliver a task by submitting the data for that task
        /// </summary>
        /// <param name="taskId">Id of the task to deliver</param>
        /// <param name="task">The taskDTO with properties to be delivered</param>
        /// <returns></returns>
        public bool DeliverTask(int taskId, TaskSubmissionDto task)
        {
            var taskToUpdate = _storageManager.GetTask(taskId);

            if (!taskToUpdate.IsEditable)
            {
                throw new ArgumentException("The task is not editable");
            }

            taskToUpdate.SubmitData(task);
            _storageManager.UpdateTask(taskToUpdate);

            return true;
        }
        public void DeliverTask()
        {
            //Arrange
            InitializeStudyDb();

            var taskDto = new TaskSubmissionDto
            {
                UserId = 1,
                SubmittedFields = new[]
                {
                    new DataFieldDto {Data = new[] {"updatedData"}, Name = "Year"}
                }
            };
            //Action
            _manager.DeliverTask(1, 1, taskDto);
            var result = _manager.GetTasks(1, 1, 1, TaskRequestDto.Filter.Editable, TaskRequestDto.Type.Review).ToList();
            var actualTask = result.First();

            //Assert
            Assert.AreEqual(1, actualTask.Id);
            Assert.AreEqual(true, actualTask.IsDeliverable);
            Assert.AreEqual("updatedData", actualTask.RequestedFields[0].Data[0]);
        }
Beispiel #4
0
        public StudyTask SubmitData(TaskSubmissionDto taskToDeliver)
        {
            var userId = taskToDeliver.UserId;

            var newDataFields = taskToDeliver.SubmittedFields.ToList();

            //TODO for now we use the dataField name to update the data.
            foreach (var field in newDataFields)
            {
                DataField fieldToUpdate;

                try
                {
                    fieldToUpdate = DataFields.First(d => d.Name.Equals(field.Name));
                }
                catch (Exception)
                {
                    throw new ArgumentException("A Corresponding dataField is not found in the task");
                }

                fieldToUpdate.SubmitData(userId, field.Data);
            }

            return this;
        }
Beispiel #5
0
        public void TestDeliverTask()
        {
            //Arrange
            var taskDto = new TaskSubmissionDto
            {
                UserId = 1,
                SubmittedFields = new[]
                {
                    new DataFieldDto {Data = new[] {"updatedData"}, Name = "Year"}
                }
            };

            //Action
            _manager.DeliverTask(1, taskDto);

            //Assert
            _dbMock.Verify(d => d.Read<StudyTask>(1), Times.Once);
            _dbMock.Verify(d => d.Update(It.IsAny<StudyTask>()), Times.Once);
        }
Beispiel #6
0
        public void TestTaskSubmitDataSingleUser()
        {
            //Arrange
            var expectedData = new[] {"testData"};
            var dataFields = new DataFieldDto[1] {new DataFieldDto {Data = expectedData, Name = "testField"}};
            var dataSubmit = new TaskSubmissionDto
            {
                SubmittedFields = dataFields,
                UserId = 1
            };

            //Action
            var actualTask = _testTask.SubmitData(dataSubmit);

            //Assert
            var actualData = actualTask.DataFields.First(d => d.Name.Equals("testField"));
            var actualUserData = actualData.UserData.First(d => d.UserId.Equals(1));

            Assert.AreEqual(expectedData[0], actualUserData.Data[0].Value);
        }
Beispiel #7
0
        public void TestTaskSubmitDataMultipleUsers()
        {
            //Arrange
            var expectedData = new[] {"testData"};

            var dataFields = new DataFieldDto[1] {new DataFieldDto {Data = expectedData, Name = "testField2"}};
            var dataSubmit = new TaskSubmissionDto
            {
                SubmittedFields = dataFields,
                UserId = 2
            };

            //Action
            var actualTask = _testTaskMultipleUsers.SubmitData(dataSubmit);

            //Assert
            var actualData = actualTask.DataFields.First(d => d.Name.Equals("testField2"));
            var actualUserData1 = actualData.UserData.First(d => d.UserId.Equals(1));
            var actualUserData2 = actualData.UserData.First(d => d.UserId.Equals(2));

            Assert.AreEqual("initialData", actualUserData1.Data[0].Value);
            Assert.AreEqual("testDescription2", actualData.Description);
            Assert.AreEqual(expectedData[0], actualUserData2.Data[0].Value);
        }
Beispiel #8
0
        public void TestTaskSubmitDataInvalidUser()
        {
            //Arrange
            var expectedData = new[] {"testData"};
            var dataFields = new DataFieldDto[1] {new DataFieldDto {Data = expectedData, Name = "testField"}};
            var dataSubmit = new TaskSubmissionDto
            {
                SubmittedFields = dataFields,
                UserId = 2
            };

            //Action
            _testTask.SubmitData(dataSubmit);
        }
Beispiel #9
0
        public void PostTaskInvalidUser()
        {
            var expectedData = "updatedData";

            //Arrange
            var taskSubmission = new TaskSubmissionDto
            {
                UserId = 100,
                SubmittedFields = new[]
                {
                    new DataFieldDto {Data = new[] {expectedData}, Name = "Year"}
                }
            };

            //Action
            var result = _api.Post(1, 1, taskSubmission);

            //Assert
            Assert.IsInstanceOfType(result, typeof (BadRequestResult));
        }
Beispiel #10
0
        public void PostTask()
        {
            var expectedData = "updatedData";

            //Arrange
            var taskSubmission = new TaskSubmissionDto
            {
                UserId = 1,
                SubmittedFields = new[]
                {
                    new DataFieldDto {Data = new[] {expectedData}, Name = "Year"}
                }
            };

            //Action
            var result = _api.Post(1, 1, taskSubmission);
            var taskResult = _api.GetTasks(1, 1, 1, TaskRequestDto.Filter.Editable);

            //Assert
            Assert.IsInstanceOfType(result, typeof (StatusCodeResult));
            var negotiatedResult = taskResult as OkNegotiatedContentResult<IEnumerable<TaskRequestDto>>;
            Assert.IsNotNull(negotiatedResult);
            var resultTask = negotiatedResult.Content.ToList();
            Assert.AreEqual(1, resultTask.First().Id);
            Assert.AreEqual(expectedData, resultTask.First().RequestedFields.First().Data[0]);
        }