public void TestGenerateReviewTask()
        {
            //Arrange
            var item1Data = new Dictionary<FieldType, string>
            {
                {new FieldType {Type = FieldType.TypEField.Title}, "title1"}
            };

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

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

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

            //Action
            var result = _taskGenerator.GenerateReviewTask(testItem1, criteria);

            //Assert
            Assert.AreEqual(testItem1, result.Paper);
            Assert.AreEqual("expectedName", result.DataFields[0].Name);
            Assert.AreEqual("expectedDescription", result.DataFields[0].Description);
            Assert.AreEqual(DataField.DataType.String, result.DataFields[0].FieldType);
            Assert.AreEqual(true, result.IsEditable);
        }
        public void TestItemsValidWithoutDefinedChecker()
        {
            _fieldDict.Add(new FieldType {Type = FieldType.TypEField.Title}, "Hello World");
            _fieldDict.Add(new FieldType {Type = FieldType.TypEField.Author}, "Christopher");

            _item = new Item(Item.ItemType.PhDThesis, _fieldDict);

            Assert.IsTrue(_iv.IsItemValid(_item));
        }
        public void TestItemsSomeValid()
        {
            _fieldDict.Add(new FieldType {Type = FieldType.TypEField.Booktitle}, "Hello\n World");
            _fieldDict.Add(new FieldType {Type = FieldType.TypEField.Author}, "Christopher");

            _item = new Item(Item.ItemType.Book, _fieldDict);

            Assert.IsFalse(_iv.IsItemValid(_item));
        }
        public void Initialize()
        {
            _validDict.Add(new FieldType {Type = FieldType.TypEField.Booktitle}, "Hello World");
            _validDict.Add(new FieldType {Type = FieldType.TypEField.Author}, "Christopher");

            _invalidDict.Add(new FieldType {Type = FieldType.TypEField.Booktitle}, "Hello World");
            _invalidDict.Add(new FieldType {Type = FieldType.TypEField.Author}, "invalid\n field");

            _validItem = new Item(Item.ItemType.Book, _validDict);
            _invalidItem = new Item(Item.ItemType.Book, _invalidDict);
        }
Exemple #5
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;
        }
        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);
        }
Exemple #7
0
 /// <summary>
 ///     Checks whether or not a given item is valid.
 /// </summary>
 /// <param name="item">The item to Validate.</param>
 /// <returns>true if the item is valid; false otherwise.</returns>
 public bool IsItemValid(Item item)
 {
     return _checkers.ContainsKey(item.Type)
         ? _checkers[item.Type].Validate(item)
         : _defaultChecker.Validate(item);
 }