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); }
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); }
public void TestDoubleLookup() { var expected = 12d; var id = new IdResolver().GetIdFor(new DoubleIdClass { Id = expected }); StringAssert.AreEqualIgnoringCase(expected.ToString(), id); }
public void TestCustomLookup() { var expected = new MyCustomClass(); var id = new IdResolver().GetIdFor(new CustomObjectIdClass { Id = expected }); StringAssert.AreEqualIgnoringCase(expected.ToString(), id); }
public void TestLongLookup() { var expected = long.MaxValue; var id = new IdResolver().GetIdFor(new LongIdClass { Id = expected }); StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id); }
public void TestFloatLookup() { var expected = 12f; var id = new IdResolver().GetIdFor(new FloatIdClass { Id = expected }); StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id); }
public void TestAlternateIdLookup() { var expectedGuid = Guid.NewGuid(); var id = new IdResolver().GetIdFor(new AlternateIdClass { Guid = expectedGuid }); StringAssert.AreEqualIgnoringCase(expectedGuid.ToString(), id); }
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); }
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); }
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); }
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); }
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); }
internal virtual string GetIdForObject(IdResolver resolver) { return this._Id; }
public void TestDoubleLookup() { var expected = 12d; var id = new IdResolver().GetIdFor(new DoubleIdClass { Id = expected }); StringAssert.AreEqualIgnoringCase(expected.ToString(CultureInfo.InvariantCulture), id); }