/// <summary> /// Choosing a criteriaChecker based on the criterions datatype. /// </summary> /// <param name="criteria"></param> /// <param name="data"></param> /// <returns>returns true if the Field is valid; false otherwise.</returns> public bool CriteriaIsMet(Criteria criteria, string[] data) { var type = criteria.DataType; return _checkers.ContainsKey(type) ? _checkers[type].Validate(criteria, data) : _defaultChecker.Validate(criteria, data); }
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); }
/// <summary> /// Validate the data using the criterions rules corresponding ruleChekcer. /// </summary> /// <param name="criteria"></param> /// <param name="data"></param> /// <returns></returns> public bool Validate(Criteria criteria, string[] data) { var type = criteria.Rule; var checkData = data; var criteriaData = criteria.DataMatch.Select(s => s.Value).ToArray(); if (_checkers.ContainsKey(type)) { return _checkers[type].IsRuleMet(checkData, criteriaData); } throw new NotImplementedException("No RuleChecker exists for this rule"); }
public void Setup() { _testCriteria1 = new Criteria { Name = "testCriteria", Description = "this is a test Criteria" }; _testCriteria2 = new Criteria { Name = "testCriteria2", Description = "this is a test Criteria" }; }
public void TestCriteriaValidatorCallsCheckerCorrectly() { //Arrange var criteria = new Criteria(); var data = new string[1]; var mockCriteriaChecker = new Mock<ICriteriaChecker>(); var validator = new CriteriaValidator( new Dictionary<DataField.DataType, ICriteriaChecker> { {It.IsAny<DataField.DataType>(), mockCriteriaChecker.Object} }); mockCriteriaChecker.Setup(m => m.Validate(criteria, data)).Returns(true); //Action var result = validator.CriteriaIsMet(criteria, data); //Assert mockCriteriaChecker.Verify(m => m.Validate(criteria, data), Times.Once); Assert.IsTrue(result); }
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); }
public void TestGetExcludedItems() { //Arrange var testCriteria = new Criteria { DataType = DataField.DataType.String, Description = "expectedDescription", Name = "Year", DataMatch = new List<StoredString> {new StoredString("1999")}, Rule = Criteria.CriteriaRule.SmallerThan }; var criteria = new List<Criteria> {testCriteria}; var tasks = new List<StudyTask> {_task1, _task2, _task3}; //Action var result = _manager.GetExcludedItems(tasks, criteria); //Assert Assert.AreEqual(2, result.Count()); }
public void TestGenerateReviewTasks() { //Arrange 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 = _manager.GenerateReviewTasks(_items, criteria); //Assert Assert.AreEqual(3, result.Count()); }
/// <summary> /// Create a stage for a study /// </summary> /// <param name="stageDto">The stageDTO to be created</param> /// <returns></returns> private Stage CreateStage(StageDto stageDto) { var stage = new Stage { Name = stageDto.Name, CurrentTaskType = StudyTask.Type.Review, DistributionRule = (Stage.Distribution) Enum.Parse(typeof (Stage.Distribution), stageDto.DistributionRule.ToString()), VisibleFields = new List<FieldType>(), Users = new List<UserStudies>(), Criteria = new List<Criteria>() }; stageDto.VisibleFields.ForEach( f => stage.VisibleFields.Add(new FieldType(f.ToString()))); stageDto.ReviewerIDs.ForEach(u => stage.Users.Add(new UserStudies { StudyRole = UserStudies.Role.Reviewer, User = _teamStorage.GetUser(u) })); stageDto.ValidatorIDs.ForEach(u => stage.Users.Add(new UserStudies { StudyRole = UserStudies.Role.Validator, User = _teamStorage.GetUser(u) })); var criteria = new Criteria { Name = stageDto.Criteria.Name, DataMatch = stageDto.Criteria.DataMatch.Select(s => new StoredString {Value = s}).ToArray(), DataType = (DataField.DataType) Enum.Parse(typeof (DataField.DataType), stageDto.Criteria.DataType.ToString()), Description = stageDto.Criteria.Description, Rule = (Criteria.CriteriaRule) Enum.Parse(typeof (Criteria.CriteriaRule), stageDto.Criteria.Rule.ToString()) }; if (stageDto.Criteria.TypeInfo != null) { criteria.TypeInfo = stageDto.Criteria.TypeInfo.Select(s => new StoredString {Value = s}).ToArray(); } stage.Criteria.Add(criteria); return stage; }