예제 #1
0
        /// <summary>
        /// Generate validation task for every conflicting task
        /// </summary>
        /// <param name="conflictingTask">study task in conflict</param>
        /// <returns></returns>
        public StudyTask GenerateValidateTasks(StudyTask conflictingTask)
        {
            var task = new StudyTask
            {
                Paper = conflictingTask.Paper,
                TaskType = StudyTask.Type.Conflict,
                DataFields = new List<DataField>(),
                IsEditable = true,
                Users = new List<User>()
            };

            foreach (var dataField in conflictingTask.DataFields)
            {
                var newDataField = new DataField
                {
                    Description = dataField.Description,
                    FieldType = dataField.FieldType,
                    Name = dataField.Name,
                    UserData = new List<UserData>(),
                    ConflictingData = new List<UserData>()
                };

                foreach (var userData in dataField.UserData)
                {
                    newDataField.ConflictingData.Add(userData);
                }

                task.DataFields.Add(newDataField);

                var datacount = dataField.UserData.ToArray();
            }

            return task;
        }
예제 #2
0
        public void Initialize()
        {
            var user1 = new User {ID = 1};
            var user2 = new User {ID = 2};
            var user3 = new User {ID = 2};

            _users = new List<User> {user1, user2, user3};
            _users2 = new List<User> {user1};

            var dataField1 = new DataField
            {
                UserData = new List<UserData>()
            };
            var dataField2 = new DataField
            {
                UserData = new List<UserData>()
            };
            var dataField3 = new DataField
            {
                UserData = new List<UserData>()
            };

            var task1 = new StudyTask
            {
                DataFields = new List<DataField> {dataField1, dataField2},
                Users = new List<User>()
            };
            var task2 = new StudyTask
            {
                DataFields = new List<DataField> {dataField3},
                Users = new List<User>()
            };

            _tasks = new List<StudyTask> {task1, task2};
        }
예제 #3
0
 /// <summary>
 ///     Tests get on all tasks in the mock repo
 /// </summary>
 public void TestStorageGetAllTasks()
 {
     _testTaskStorageManager.CreateTask(_testTask);
     var testTask2 = new StudyTask();
     _testTaskStorageManager.CreateTask(testTask2);
     Assert.AreEqual(2, _testTaskStorageManager.GetAllTasks().Count());
 }
예제 #4
0
        /// <summary>
        /// Generate review tasks for every item
        /// </summary>
        /// <param name="item">item to generate a task for</param>
        /// <param name="criteria">lsit of criteria for a task to meet</param>
        /// <returns></returns>
        public StudyTask GenerateReviewTask(Item item, List<Criteria> criteria)
        {
            var task = new StudyTask
            {
                Paper = item,
                TaskType = StudyTask.Type.Review,
                DataFields = new List<DataField>(),
                Users = new List<User>()
            };

            foreach (var criterion in criteria)
            {
                //Trying to parse data from the bib item
                var data = new StoredString {Value = item.FindFieldValue(criterion.Name)};

                var dataField = new DataField
                {
                    Description = criterion.Description,
                    FieldType = criterion.DataType,
                    Name = criterion.Name,
                    UserData = new List<UserData> {new UserData {Data = new List<StoredString> {data}}}
                };

                if (criterion.DataType == DataField.DataType.Enumeration ||
                    criterion.DataType == DataField.DataType.Flags)
                {
                    dataField.TypeInfo = new List<StoredString>();
                    foreach (var s in criterion.TypeInfo)
                    {
                        dataField.TypeInfo.Add(s);
                    }
                }

                //Check if the information was found in the bib item, if yes the task is finished.
                task.IsEditable = data.Value == null;

                task.DataFields.Add(dataField);
            }

            return task;
        }
예제 #5
0
 /// <summary>
 /// Update a task
 /// </summary>
 /// <param name="studyTask"></param>
 /// <returns></returns>
 public bool UpdateTask(StudyTask studyTask)
 {
     return _taskRepo.Update(studyTask);
 }
예제 #6
0
 /// <summary>
 /// Create a task
 /// </summary>
 /// <param name="studyTask"></param>
 /// <returns></returns>
 public int CreateTask(StudyTask studyTask)
 {
     return _taskRepo.Create(studyTask);
 }
예제 #7
0
        public void TestGenerateValidateTask()
        {
            //Arrange
            var item1Data = new Dictionary<FieldType, string>
            {
                {new FieldType {Type = FieldType.TypEField.Title}, "title1"}
            };

            var testItem1 = new Item(Item.ItemType.Book, item1Data);

            _expectedUserData1 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "conflictingData1"}},
                UserId = 1
            };
            _expectedUserData2 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "conflictingData2"}},
                UserId = 2
            };

            _conflictingTask = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        UserData = new List<UserData>
                        {
                            _expectedUserData1,
                            _expectedUserData2
                        },
                        Description = "conflictingFieldDescription",
                        FieldType = DataField.DataType.String,
                        Name = "conflictingField"
                    }
                },
                Paper = testItem1,
                TaskType = StudyTask.Type.Review,
                Users = new List<User> {_user1, _user2}
            };

            var testCriteria = new Criteria
            {
                DataType = DataField.DataType.String,
                Description = "expectedDescription",
                Name = "Title",
                DataMatch = new List<StoredString> {new StoredString("expectedDataMatch")},
                Rule = Criteria.CriteriaRule.Equals
            };

            var criteria = new List<Criteria> {testCriteria};

            //Action
            var result = _taskGenerator.GenerateValidateTasks(_conflictingTask);

            //Assert
            Assert.AreEqual(testItem1, result.Paper);
            Assert.AreEqual("conflictingField", result.DataFields[0].Name);
            Assert.AreEqual("conflictingFieldDescription", result.DataFields[0].Description);
            Assert.AreEqual(DataField.DataType.String, result.DataFields[0].FieldType);
            Assert.AreEqual(true, result.IsEditable);
            Assert.AreEqual(0, result.DataFields[0].UserData.Count);
            Assert.AreEqual("conflictingData1", result.DataFields[0].ConflictingData[0].Data[0].Value);
            Assert.AreEqual("conflictingData2", result.DataFields[0].ConflictingData[1].Data[0].Value);
            Assert.AreEqual(1, result.DataFields[0].ConflictingData[0].UserId);
            Assert.AreEqual(2, result.DataFields[0].ConflictingData[1].UserId);
        }
예제 #8
0
        public void Setup()
        {
            var item1Data = new Dictionary<FieldType, string>
            {
                {new FieldType {Type = FieldType.TypEField.Title}, "title"}
            };

            _testItem1 = new Item(Item.ItemType.Book, item1Data);
            _testItem2 = new Item(Item.ItemType.Book, item1Data);
            _testItem3 = new Item(Item.ItemType.Book, item1Data);

            _items = new List<Item> {_testItem1, _testItem2, _testItem1};

            var testUser1 = new User {Name = "chris"};
            var testUser2 = new User {Name = "ramos"};
            var testUser3 = new User {Name = "kathrin"};
            var testUser4 = new User {Name = "emil"};
            var testUser5 = new User {Name = "user1"};
            var testUser6 = new User {Name = "user2"};
            var testUser7 = new User {Name = "user3"};
            var testUser8 = new User {Name = "user4"};

            var testTeam1 = new Team
            {
                Name = "team1",
                Users = new List<User> {testUser1, testUser2, testUser3, testUser4}
            };
            var testTeam2 = new Team
            {
                Name = "team2",
                Users = new List<User> {testUser5, testUser6, testUser7, testUser8}
            };
            var testTeam3 = new Team
            {
                Name = "team3",
                Users = new List<User> {testUser1, testUser6, testUser3, testUser8}
            };

            var expectedUserData1 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "2015"}},
                UserId = 1
            };
            var expectedUserData2 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "2015"}},
                UserId = 2
            };
            var expectedUserData3 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = "2015"}},
                UserId = 2
            };

            var emptyUserData1 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = null}},
                UserId = 1
            };
            var emptyUserData2 = new UserData
            {
                Data = new List<StoredString> {new StoredString {Value = null}},
                UserId = 2
            };

            //Finished
            _task1 = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        Name = "Year",
                        UserData = new List<UserData> {expectedUserData1, expectedUserData2}
                    }
                },
                Users = new List<User> {testUser1, testUser2},
                TaskType = StudyTask.Type.Review,
                IsEditable = true,
                Paper = _testItem1
            };

            //Unfinished
            _task2 = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        Name = "Year",
                        UserData = new List<UserData> {emptyUserData1, expectedUserData3}
                    }
                },
                Users = new List<User> {testUser1, testUser2},
                TaskType = StudyTask.Type.Review,
                IsEditable = true,
                Paper = _testItem2
            };

            //Not Editable
            _task3 = new StudyTask
            {
                DataFields = new List<DataField>
                {
                    new DataField
                    {
                        Name = "Year",
                        UserData = new List<UserData> {expectedUserData1}
                    }
                },
                Users = new List<User> {testUser1},
                TaskType = StudyTask.Type.Review,
                IsEditable = false,
                Paper = _testItem3
            };

            _dbMock = new Mock<IGenericRepository>();
            _dbMock.Setup(t => t.Read<StudyTask>(1))
                .Returns(_task1);
            _dbMock.Setup(t => t.Read<StudyTask>(3))
                .Returns(_task3);

            _dbMock.Setup(t => t.Update(_task1))
                .Returns(true);

            _manager = new TaskManager(_dbMock.Object);
        }
예제 #9
0
 public void TestStorageUpdateTask()
 {
     var testTask = new StudyTask {ID = 1, TaskType = StudyTask.Type.Review};
     _testTaskStorageManager.CreateTask(testTask);
     testTask.TaskType = StudyTask.Type.Conflict;
     _testTaskStorageManager.UpdateTask(testTask);
     Assert.AreEqual(StudyTask.Type.Conflict, _testTaskStorageManager.GetTask(1).TaskType);
 }
예제 #10
0
        public void Initialize()
        {
            var testItem = new Item(Item.ItemType.Book, new Dictionary<FieldType, string>());
            var testUser1 = new User {ID = 1, Name = "chris"};
            var testUser2 = new User {ID = 2, Name = "ramos"};
            var userData1 = new UserData
            {
                UserId = 1,
                Data = new List<StoredString> {new StoredString {Value = "initialData"}}
            };
            var userData2 = new UserData
            {
                UserId = 2,
                Data = new List<StoredString> {new StoredString {Value = "initialData2"}}
            };
            var userData3 = new UserData {UserId = 2, Data = new List<StoredString> {new StoredString()}};
            var dataFields1 = new List<DataField>
            {
                new DataField
                {
                    UserData = new List<UserData> {userData1},
                    Name = "testField",
                    Description = "testDescription"
                }
            };
            var dataFields2 = new List<DataField>
            {
                new DataField
                {
                    UserData = new List<UserData> {userData2, userData1},
                    Name = "testField2",
                    Description = "testDescription2"
                }
            };
            var dataFields3 = new List<DataField>
            {
                new DataField
                {
                    UserData = new List<UserData> {userData3, userData1},
                    Name = "testField3",
                    Description = "testDescription"
                }
            };

            _testTask = new StudyTask
            {
                Paper = testItem,
                DataFields = new List<DataField>(dataFields1)
            };

            _testTaskMultipleUsers = new StudyTask
            {
                Paper = testItem,
                DataFields = new List<DataField>(dataFields2)
            };

            _testTaskFinished = new StudyTask
            {
                Paper = testItem,
                DataFields = new List<DataField>(dataFields3)
            };
        }
예제 #11
0
 /// <summary>
 /// Create a task
 /// </summary>
 /// <param name="task">StudyTask to be created</param>
 /// <returns></returns>
 public int CreateTask(StudyTask task)
 {
     return _storageManager.CreateTask(task);
 }
예제 #12
0
        /// <summary>
        ///     Checks if a task meets the stages various criteria.
        ///     Each of the tasks fields are checked against the corresponding criteria.
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="task">The task we are checking</param>
        /// <returns></returns>
        private bool TaskMeetsCriteria(ICollection<Criteria> criteria, StudyTask task)
        {
            if (criteria.Count == 0)
            {
                throw new ArgumentException("the stage does not contain any criteria");
            }

            foreach (var criterion  in criteria)
            {
                //Finds the corresponding field for the criteria using the name...
                var correspondingField = task.DataFields.First(f => f.Name.Equals(criterion.Name)).UserData.First();

                if (!_criteriaValidator.CriteriaIsMet(criterion, correspondingField.Data.Select(s => s.Value).ToArray()))
                {
                    return false;
                }
            }
            return true;
        }
예제 #13
0
        public void InitializeTests()
        {
            var user1 = new User {ID = 1};
            var user2 = new User {ID = 2};

            var team1 = new Team {Users = new List<User> {user1, user2}};

            var dataString1 = new StoredString {Value = "someData"};
            var datastring2 = new StoredString {Value = "someOtherData"};
            var nullString = new StoredString {Value = null};

            var userData1 = new UserData {UserId = 1, Data = new List<StoredString> {dataString1, datastring2}};
            var userData2 = new UserData {UserId = 2, Data = new List<StoredString> {nullString, nullString}};
            var userData3 = new UserData {UserId = 2, Data = new List<StoredString> {dataString1, datastring2}};
            var userData4 = new UserData {UserId = 1, Data = new List<StoredString> {nullString, nullString}};

            var dataField = new DataField {UserData = new List<UserData> {userData1, userData3}};
            var dataField2 = new DataField {UserData = new List<UserData> {userData2, userData4}};

            var task1 = new StudyTask
            {
                DataFields = new List<DataField> {dataField},
                Users = new List<User> {user1, user2}
            };
            var task2 = new StudyTask
            {
                DataFields = new List<DataField> {dataField2},
                Users = new List<User> {user1, user2}
            };

            var userstudy1 = new UserStudies {User = user1};
            var userstudy2 = new UserStudies {User = user2};

            var stage1 = new Stage
            {
                Name = "stage1",
                IsCurrentStage = true,
                ID = 1,
                Users = new List<UserStudies> {userstudy1, userstudy2},
                Tasks = new List<StudyTask> {task1, task2}
            };
            var stage2 = new Stage
            {
                Name = "stage2",
                IsCurrentStage = false,
                ID = 2,
                Users = new List<UserStudies> {userstudy1, userstudy2},
                Tasks = new List<StudyTask> {task1, task2}
            };

            _id = 1;
            _mockStudyRepo = new Mock<IGenericRepository>();

            _testStudy = new Study
            {
                ID = 1,
                IsFinished = false,
                Items = new List<Item>(),
                Stages = new List<Stage> {stage1, stage2},
                Team = team1
            };

            _studies = new Dictionary<int, Study> {{1, _testStudy}};

            _testStudyStorageManager = new StudyStorageManager(_mockStudyRepo.Object);

            _testController = new StudyOverview(_testStudyStorageManager, _testTaskStorageManager);

            // Read item
            _mockStudyRepo.Setup(r => r.Read<Study>(It.IsAny<int>()))
                .Returns<int>(id => _studies.First(e => e.Key == id).Value);

            // Read items
            _mockStudyRepo.Setup(r => r.Read<Study>()).Returns(_studies.Values.AsQueryable());

            // Create
            _mockStudyRepo.Setup(r => r.Create(It.IsAny<Study>())).Callback<Study>(study =>
            {
                var nextId = _id++;
                study.ID = nextId;
                _studies.Add(nextId, study);
            });

            // Update
            _mockStudyRepo.Setup(r => r.Update(It.IsAny<Study>())).Callback<Study>(study =>
            {
                if (_studies.ContainsKey(study.ID))
                {
                    _studies[study.ID] = study;
                }
            });

            // Delete
            _mockStudyRepo.Setup(r => r.Delete(It.IsAny<Study>()))
                .Callback<Study>(study => { _studies.Remove(study.ID); });
        }