public static ICypherFluentQuery Where(this ICypherFluentQuery query, string matchText, bool onlyLive = false) { if (!onlyLive) { return(query.Where(matchText)); } return(query .Where(matchText) .AndWhere(string.Format("p.title in [{0}]", string.Join(", ", PathwaysConfigurationManager.GetLivePathwaysElements().Select(p => string.Format("'{0}'", p.Title)))))); }
public async void GetAllPathways_when_only_using_live_returns_only_live_pathways() { MockPathwaysConfigurationManager.Setup(m => m.UseLivePathways).Returns(true); _pathwayRepository = new PathwayRepository(GraphRepository, MockPathwaysConfigurationManager.Object); var liveOnlyPathways = PathwaysConfigurationManager.GetLivePathwaysElements().Select(e => e.Title); var res = await _pathwayRepository.GetAllPathways(); Assert.AreEqual(res.Count(), Pathways.Count(p => liveOnlyPathways.Contains(p.Title))); }
public async void GetGroupedPathways_when_only_using_live_returns_grouped_pathways() { MockPathwaysConfigurationManager.Setup(m => m.UseLivePathways).Returns(true); _pathwayRepository = new PathwayRepository(GraphRepository, MockPathwaysConfigurationManager.Object); var liveOnlyPathways = PathwaysConfigurationManager.GetLivePathwaysElements().Select(e => e.Title); var liveOnlyDistinctPathways = Pathways.Where(p => p.Module == "1" && liveOnlyPathways.Contains(p.Title)).Select(p => p.Title).Distinct(); var res = await _pathwayRepository.GetGroupedPathways(); Assert.AreEqual(res.Count(), liveOnlyDistinctPathways.Count()); }
public async Task <Pathway> GetIdentifiedPathway(string pathwayTitle, string gender, int age) { var pathwayTitleEquals = string.Format("p.title = {0}", JsonConvert.SerializeObject(pathwayTitle)); var jumptToPathways = PathwaysConfigurationManager.GetJumpToPathwaysElements().Select(e => e.Id); var pathwayIdIn = new Func <IEnumerable <string>, string>(p => string.Format("not p.id in {0}", JsonConvert.SerializeObject(p))); var pathway = await _graphRepository.Client.Cypher .Match("(p:Pathway)") .Where(string.Join(" and ", new List <string> { GenderIs(gender), AgeIsAboveMinimum(age), AgeIsBelowMaximum(age), pathwayIdIn(jumptToPathways), pathwayTitleEquals }), UseWhitelist) .Return(p => Return.As <Pathway>("p")) .ResultsAsync .FirstOrDefault(); return(pathway); }
public async Task <Pathway> GetIdentifiedPathway(IEnumerable <string> pathwayNumbers, string gender, int age) { var genderIs = new Func <string, string>(g => string.Format("(p.gender is null or p.gender = \"\" or p.gender = \"{0}\")", g)); var ageIsAboveMinimum = new Func <int, string>(a => string.Format("(p.minimumAgeInclusive is null or p.minimumAgeInclusive = \"\" or p.minimumAgeInclusive <= {0})", a)); var ageIsBelowMaximum = new Func <int, string>(a => string.Format("(p.maximumAgeExclusive is null or p.maximumAgeExclusive = \"\" or {0} < p.maximumAgeExclusive)", a)); var pathwayNumberIn = new Func <IEnumerable <string>, string>(p => string.Format("p.pathwayNo in {0}", JsonConvert.SerializeObject(p))); var jumptToPathways = PathwaysConfigurationManager.GetJumpToPathwaysElements().Select(e => e.Id); var pathwayIdIn = new Func <IEnumerable <string>, string>(p => string.Format("not p.id in {0}", JsonConvert.SerializeObject(p))); var pathway = await _graphRepository.Client.Cypher .Match("(p:Pathway)") .Where(string.Join(" and ", new List <string> { genderIs(gender), ageIsAboveMinimum(age), ageIsBelowMaximum(age), pathwayNumberIn(pathwayNumbers), pathwayIdIn(jumptToPathways) }), UseWhitelist) .Return(p => Return.As <Pathway>("p")) .ResultsAsync .FirstOrDefault(); return(pathway); }