예제 #1
0
 public void TestFloatLookup()
 {
     var client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
     var expected = 12f;
     var id = new IdResolver().GetIdFor(new FloatIdClass { Id = expected });
     StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
 }
예제 #2
0
 public void TestInheritedLookup()
 {
     var client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
     var expected = new InheritedIdClass() { Id = 123 };
     var id = new IdResolver().GetIdFor(expected);
     id = new IdResolver().GetIdFor(expected);
     Assert.AreEqual(expected.Id.ToString(), id);
 }
예제 #3
0
        public void TestDoubleLookup()
        {
            var expected = 12d;
            var id       = new IdResolver().GetIdFor(new DoubleIdClass {
                Id = expected
            });

            StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
        }
예제 #4
0
        public void TestCustomLookup()
        {
            var expected = new MyCustomClass();
            var id       = new IdResolver().GetIdFor(new CustomObjectIdClass {
                Id = expected
            });

            StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
        }
예제 #5
0
        public void TestLongLookup()
        {
            var expected = long.MaxValue;
            var id       = new IdResolver().GetIdFor(new LongIdClass {
                Id = expected
            });

            StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id);
        }
예제 #6
0
        public void TestFloatLookup()
        {
            var expected = 12f;
            var id       = new IdResolver().GetIdFor(new FloatIdClass {
                Id = expected
            });

            StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id);
        }
예제 #7
0
        public void TestAlternateIdLookup()
        {
            var expectedGuid = Guid.NewGuid();
            var id           = new IdResolver().GetIdFor(new AlternateIdClass {
                Guid = expectedGuid
            });

            StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id);
        }
예제 #8
0
        public void TestFloatLookup()
        {
            var client   = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
            var expected = 12f;
            var id       = new IdResolver().GetIdFor(new FloatIdClass {
                Id = expected
            });

            StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
        }
예제 #9
0
        public void TestAlternateIdLookup()
        {
            var client       = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
            var expectedGuid = Guid.NewGuid();
            var id           = new IdResolver().GetIdFor(new AlternateIdClass {
                Guid = expectedGuid
            });

            StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id);
        }
예제 #10
0
        public override string ResolveStudyGroup(string grade)
        {
            if (grade == null)
            {
                logger.LogDebug($"Grade must not be empty.");
                return(null);
            }

            return(gradeStudyGroupsCache.ContainsKey(grade) ? IdResolver.Resolve(gradeStudyGroupsCache[grade]) : null);
        }
예제 #11
0
        public void TestInheritedLookup()
        {
            var expected = new InheritedIdClass()
            {
                Id = 123
            };
            var id = new IdResolver().GetIdFor(expected);

            id = new IdResolver().GetIdFor(expected);
            Assert.AreEqual(expected.Id.ToString(), id);
        }
예제 #12
0
        public override string ResolveStudyGroup(string grade, string subject, string teacher)
        {
            if (grade == null)
            {
                logger.LogDebug($"Grade must not be empty.");
                return(null);
            }

            if (subject == null)
            {
                logger.LogDebug($"Subject must not be empty.");
                return(null);
            }

            if (!tuitionsCache.ContainsKey(grade))
            {
                logger.LogDebug($"Grade {grade} does not exist.");
                return(null);
            }

            var candidates = tuitionsCache[grade].Where(x => x.Subject == subject);

            if (!candidates.Any())
            {
                logger.LogDebug($"Did not find any tuition for grade {grade}, subject {subject} and teacher {teacher}");
                return(null);
            }

            if (candidates.Count() == 1)
            {
                return(IdResolver.Resolve(candidates.First().StudyGroup));
            }

            var teachers = candidates.Select(x => x.Tuition.TeacherRef.Acronym).ToList();

            logger.LogDebug($"Possible teachers are: {string.Join(", ", teachers)}");

            if (string.IsNullOrEmpty(teacher))
            {
                logger.LogDebug($"Ambiguous tuition found for grade {grade} and subject {subject}. Teacher needs to be specified.");
                return(null);
            }

            foreach (var candidate in candidates.Where(x => x.Tuition.TeacherRef != null))
            {
                if (candidate.Tuition.TeacherRef.Acronym == teacher)
                {
                    return(IdResolver.Resolve(candidate.Tuition, candidate.StudyGroup));
                }
            }

            logger.LogDebug($"Did not find any tuition for grade {grade}, subject {subject} and teacher {teacher}");
            return(null);
        }
예제 #13
0
        public void TestInheritedLookup()
        {
            var client   = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
            var expected = new InheritedIdClass()
            {
                Id = 123
            };
            var id = new IdResolver().GetIdFor(expected);

            id = new IdResolver().GetIdFor(expected);
            Assert.AreEqual(expected.Id.ToString(), id);
        }
예제 #14
0
        public void TestHitsCache()
        {
            var expected = 12m;
            var id       = new IdResolver().GetIdFor(new DecimalIdClass {
                Id = expected
            });

            id = new IdResolver().GetIdFor(new DecimalIdClass {
                Id = expected
            });
            StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
        }
        public List <string> Resolve(string tuition, Exam exam, string start, string end)
        {
            var date     = exam.Date;
            var students = new List <string>();
            var section  = GetSectionForDate(date);

            if (section == null)
            {
                logger.LogError($"Cannot find any SchILD section for date {date.ToShortDateString()}. Students will be empty.");
                return(students);
            }

            var key = $"{section.SchoolYear}-{section.Section}";

            if (!tuitionCache.ContainsKey(key))
            {
                logger.LogError($"Did not find any tuitions for {key}. Students will be emtpy.");
                return(students);
            }

            var match = tuitionCache[key].FirstOrDefault(x => IdResolver.Resolve(x.Tuition, x.StudyGroup) == tuition);

            if (match == null)
            {
                logger.LogError($"Did not find any tuitions for {tuition}. Students will be emtpy.");
                return(students);
            }

            foreach (var membership in match.StudyGroup.Memberships)
            {
                var student   = studentCache.ContainsKey(membership.Student.Id.ToString()) ? studentCache[membership.Student.Id.ToString()] : null;
                var candidate = settings.Rules.FirstOrDefault(x => x.Grades.Contains(membership.Grade) && x.Sections.Contains(section.Section) && x.Types.Contains(membership.Type));

                if (candidate == null)
                {
                    logger.LogDebug($"Did not find any rule for student {membership.Student.Id} (Grade: {membership.Grade}, Type: {membership.Type}, Section: {section.Section}. Ignore student.");
                }
                else if (!string.IsNullOrWhiteSpace(start) && !string.IsNullOrWhiteSpace(end) && student != null && (String.Compare(student.Lastname.ToUpper(), start.ToUpper()) < 0 || student.Lastname.ToUpper().Substring(0, end.Length) != end.ToUpper()))
                {
                    logger.LogDebug($"Ignore student with lastname {student.Lastname} because {start} <= {student.Lastname} <= {end} is not true.");
                }
                else
                {
                    students.Add(membership.Student.Id.ToString());
                }
            }

            return(students);
        }
예제 #16
0
 internal virtual string GetIdForObject(IdResolver resolver)
 {
     return this._Id;
 }
예제 #17
0
		public void TestHitsCache()
		{
			var expected = 12m;
			var id = new IdResolver().GetIdFor(new DecimalIdClass { Id = expected });
			id = new IdResolver().GetIdFor(new DecimalIdClass { Id = expected });
			StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
		}
예제 #18
0
		public void TestInheritedLookup()
		{
			var expected = new InheritedIdClass() { Id = 123 };
			var id = new IdResolver().GetIdFor(expected);
			id = new IdResolver().GetIdFor(expected);
			Assert.AreEqual(expected.Id.ToString(), id);
		}
예제 #19
0
		public void TestCustomLookup()
		{
			var expected = new MyCustomClass();
			var id = new IdResolver().GetIdFor(new CustomObjectIdClass { Id = expected });
			StringAssert.AreEqualIgnoringCase(expected.ToString(), id);
		}
예제 #20
0
		public void TestDoubleLookup()
		{
			var expected = 12d;
			var id = new IdResolver().GetIdFor(new DoubleIdClass { Id = expected });
			StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id);
		}
예제 #21
0
		public void TestLongLookup()
		{
			var expected = long.MaxValue;
			var id = new IdResolver().GetIdFor(new LongIdClass { Id = expected });
			StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id);
		}
예제 #22
0
		public void TestAlternateIdLookup()
		{
			var expectedGuid = Guid.NewGuid();
			var id = new IdResolver().GetIdFor(new AlternateIdClass { Guid = expectedGuid });
			StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id);
		}
예제 #23
-1
 public void TestAlternateIdLookup()
 {
     var client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
     var expectedGuid = Guid.NewGuid();
     var id = new IdResolver().GetIdFor(new AlternateIdClass { Guid = expectedGuid });
     StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id);
 }