public void Campaign() { var criteria = new[] { new CampaignSearchCriteria { InternalName = CampaignSearchCriteria.DonatedToCampaign, SearchOperator = SearchOperator.StartsWith, Type = SearchFieldType.String, Value = "Christmas" } }; var expr = new SearchQueryService().CompileCampaignCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("Name", reference.GetName()); Assert.AreEqual(SimpleExpressionType.Function, expr.Type); var function = expr.RightOperand as SimpleFunction; Assert.IsNotNull(function); Assert.AreEqual("like", function.Name.ToLowerInvariant()); Assert.AreEqual(1, function.Args.Count); Assert.AreEqual("Christmas%", function.Args.First()); }
public void Campaign() { var criteria = new[] { new CampaignSearchCriteria { InternalName = CampaignSearchCriteria.DonatedToCampaign, SearchOperator = SearchOperator.StartsWith, Type = SearchFieldType.String, Value = "Christmas" } }; var expr = new SearchQueryService().CompileCampaignCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("Name", reference.GetName()); Assert.AreEqual(SimpleExpressionType.Function, expr.Type); var function = expr.RightOperand as SimpleFunction; Assert.IsNotNull(function); Assert.AreEqual("like", function.Name.ToLowerInvariant()); Assert.AreEqual(1, function.Args.Count); Assert.AreEqual("Christmas%", function.Args.First()); }
public void LocationOnPartialPostalCode() { var criteria = new[] { new LocationSearchCriteria { InternalName = LocationSearchCriteria.PostalCode, SearchOperator = SearchOperator.StartsWith, Type = SearchFieldType.String, Value = "N1" } }; var expr = new SearchQueryService().CompileLocationCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("postalcode", reference.GetName()); Assert.AreEqual(SimpleExpressionType.Function, expr.Type); var function = expr.RightOperand as SimpleFunction; Assert.IsNotNull(function); Assert.AreEqual("like", function.Name.ToLowerInvariant()); Assert.AreEqual(1, function.Args.Count); Assert.AreEqual("N1%", function.Args.First()); }
private SearchQueryService SetupSearchQueryService() { ISearchParameterCache ISearchParameterCache = SetupSearchParameterCache(); SearchQueryFactory SearchQueryFactory = SetupSearchQueryFactory(ISearchParameterCache); IResourceTypeSupport IResourceTypeSupport = new ResourceTypeSupport(); var IKnownResourceMock = IKnownResource_MockFactory.Get(); IChainQueryProcessingService IChainQueryProcessingService = new ChainQueryProcessingService(IResourceTypeSupport, IKnownResourceMock.Object, ISearchParameterCache, SearchQueryFactory); SearchQueryService SearchQueryService = new SearchQueryService(ISearchParameterCache, SearchQueryFactory, IResourceTypeSupport, IKnownResourceMock.Object, IChainQueryProcessingService); return(SearchQueryService); }
public async Task get_search_query_by_userId_async() { var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act var x = await service.GetByUserIdAsync("1"); //Assert Assert.AreEqual(1, x.Count()); }
public void get_search_query_by_userId() { var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act var x = service.GetByUserId("1").First(); //Assert Assert.AreEqual(x.UserId, "1"); }
public void remove_query_by_id() { var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act service.RemoveById("1"); //Assert mockContext.Verify(m => m.SaveChanges(), Times.Once()); mockSet.Verify(m => m.Remove(It.IsAny <SearchQueryDB>()), Times.Once()); }
public void get_all_search_queries() { var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act var x = service.GetAll(); //Assert Assert.AreEqual(x.Count(), queries.Select(p => p).ToList().Count()); }
public void remove_all_search_queries() { var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act service.RemoveAll(); //Assert mockContext.Verify(m => m.SaveChanges(), Times.Once()); mockSet.Verify(m => m.RemoveRange(It.IsAny <IEnumerable <SearchQueryDB> >()), Times.Once()); }
public async Task get_all_search_queries_async() { //Arrage var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act var q = await service.GetAllAsync(); //Assert Assert.AreEqual(queries.Select(p => p).ToList().Count(), q.Count()); }
public void Facet() { var search = new SearchQueryService(); var criteria = new[] { new FacetSearchCriteria { InternalName = "freeTextFacet_1", DisplayName = "Test", FacetId = 1, SearchOperator = SearchOperator.StartsWith, Type = SearchFieldType.String, Value = "GiveCamp" } }; var expr = search.CompileFacetCriteria(criteria, null); Assert.AreEqual(SimpleExpressionType.And, expr.Type); var first = expr.LeftOperand as SimpleExpression; Assert.IsNotNull(first); var reference = first.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("FacetId", reference.GetName()); Assert.AreEqual("freeTextFacet_1", reference.GetOwner().GetAlias()); Assert.AreEqual(SimpleExpressionType.Equal, first.Type); Assert.AreEqual(1, first.RightOperand); var second = expr.RightOperand as SimpleExpression; Assert.IsNotNull(second); reference = second.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("FreeTextValue", reference.GetName()); Assert.AreEqual("freeTextFacet_1", reference.GetOwner().GetAlias()); var function = second.RightOperand as SimpleFunction; Assert.IsNotNull(function); Assert.AreEqual("like", function.Name.ToLowerInvariant()); Assert.AreEqual(1, function.Args.Count); Assert.AreEqual("GiveCamp%", function.Args.First()); Assert.AreEqual(SimpleExpressionType.Function, second.Type); }
public void ChainQueryNegative(FhirVersion fhirVersion, ResourceType resourceContext, string parameterName, string parameterValue, string InvalidUnsupported) { //Prepare SearchQueryService SearchQueryService = SetupSearchQueryService(); Dictionary <string, StringValues> QueryDictonary = new Dictionary <string, StringValues> { { parameterName, new StringValues(parameterValue) }, }; FhirSearchQuery FhirSearchQuery = new FhirSearchQuery(); FhirSearchQuery.Parse(QueryDictonary); //Act ISerachQueryServiceOutcome Outcome = SearchQueryService.Process(fhirVersion, resourceContext, FhirSearchQuery).Result; //Assert Assert.NotNull(Outcome); Assert.Null(Outcome.CountRequested); Assert.Equal(0, Outcome.SearchQueryList.Count); Assert.Equal(Common.Enums.ResourceType.Observation, Outcome.ResourceContext); if (InvalidUnsupported.ToLower() == "invalid") { Assert.True(Outcome.InvalidSearchQueryList.Count > 0); } else { Assert.True(Outcome.UnsupportedSearchQueryList.Count > 0); } foreach (var InvalidItem in Outcome.InvalidSearchQueryList) { Assert.Equal(parameterName, InvalidItem.Name); Assert.Equal(parameterValue, InvalidItem.Value); Assert.True(InvalidItem.ErrorMessage.Length > 5); } foreach (var UnsupportedItem in Outcome.UnsupportedSearchQueryList) { Assert.Equal(parameterName, UnsupportedItem.Name); Assert.Equal(parameterValue, UnsupportedItem.Value); Assert.True(UnsupportedItem.ErrorMessage.Length > 5); } }
public void add_search_query() { var DbService = new SearchQueryDbService(mockContext.Object); var mockLogicService = new Mock <SearchQueryService>(); var service = new SearchQueryService(mapper, DbService); //Act var b = new SearchQueryDTO { Id = "1", Date = DateTime.Now, Query = "search query" }; var q = service.Add(b); var all = DbService.GetAll().Count(); //Assert mockContext.Verify(m => m.SaveChanges(), Times.Once()); Assert.AreEqual(q.Query, b.Query); }
public void LocationOnRegion() { var criteria = new[] { new LocationSearchCriteria { InternalName = LocationSearchCriteria.Region, SearchOperator = SearchOperator.NotEqualTo, Type = SearchFieldType.String, Value = "Yorkshire" } }; var expr = new SearchQueryService().CompileLocationCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("region", reference.GetName()); Assert.AreEqual(SimpleExpressionType.NotEqual, expr.Type); Assert.AreEqual("Yorkshire", expr.RightOperand); }
public void DoubleChainQueryPositive(FhirVersion fhirVersion, ResourceType resourceContext, string parameterName, string parameterValue) { //Prepare SearchQueryService SearchQueryService = SetupSearchQueryService(); Dictionary <string, StringValues> QueryDictonary = new Dictionary <string, StringValues> { { parameterName, new StringValues(parameterValue) }, }; FhirSearchQuery FhirSearchQuery = new FhirSearchQuery(); FhirSearchQuery.Parse(QueryDictonary); //Act ISerachQueryServiceOutcome Outcome = SearchQueryService.Process(fhirVersion, resourceContext, FhirSearchQuery).Result; //Assert Assert.NotNull(Outcome); Assert.Equal(0, Outcome.InvalidSearchQueryList.Count); Assert.Null(Outcome.CountRequested); Assert.Equal(1, Outcome.SearchQueryList.Count); Assert.Equal(Common.Enums.ResourceType.Observation, Outcome.ResourceContext); var ChainSearchQuery = Outcome.SearchQueryList[0]; Assert.NotNull(ChainSearchQuery); Assert.Equal("subject", ChainSearchQuery.Name); Assert.NotNull(ChainSearchQuery.ChainedSearchParameter); Assert.Equal("organization", ChainSearchQuery.ChainedSearchParameter !.Name); Assert.NotNull(ChainSearchQuery.ChainedSearchParameter !.ChainedSearchParameter); Assert.Equal("name", ChainSearchQuery.ChainedSearchParameter !.ChainedSearchParameter !.Name); if (ChainSearchQuery.ChainedSearchParameter !.ChainedSearchParameter is SearchQueryString SearchQueryString) { Assert.Single(SearchQueryString.ValueList); Assert.Equal("acmehealth", SearchQueryString.ValueList[0].Value); } }
public void LocationOnRegion() { var criteria = new[] { new LocationSearchCriteria { InternalName = LocationSearchCriteria.Region, SearchOperator = SearchOperator.NotEqualTo, Type = SearchFieldType.String, Value = "Yorkshire" } }; var expr = new SearchQueryService().CompileLocationCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("region", reference.GetName()); Assert.AreEqual(SimpleExpressionType.NotEqual, expr.Type); Assert.AreEqual("Yorkshire", expr.RightOperand); }
public void LocationOnPartialPostalCode() { var criteria = new[] { new LocationSearchCriteria { InternalName = LocationSearchCriteria.PostalCode, SearchOperator = SearchOperator.StartsWith, Type = SearchFieldType.String, Value = "N1" } }; var expr = new SearchQueryService().CompileLocationCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("postalcode", reference.GetName()); Assert.AreEqual(SimpleExpressionType.Function, expr.Type); var function = expr.RightOperand as SimpleFunction; Assert.IsNotNull(function); Assert.AreEqual("like", function.Name.ToLowerInvariant()); Assert.AreEqual(1, function.Args.Count); Assert.AreEqual("N1%", function.Args.First()); }
public void Facet() { var search = new SearchQueryService(); var criteria = new[] { new FacetSearchCriteria { InternalName = "freeTextFacet_1", DisplayName = "Test", FacetId = 1, SearchOperator = SearchOperator.StartsWith, Type = SearchFieldType.String, Value = "GiveCamp" } }; var expr = search.CompileFacetCriteria(criteria, null); Assert.AreEqual(SimpleExpressionType.And, expr.Type); var first = expr.LeftOperand as SimpleExpression; Assert.IsNotNull(first); var reference = first.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("FacetId", reference.GetName()); Assert.AreEqual("freeTextFacet_1", reference.GetOwner().GetAlias()); Assert.AreEqual(SimpleExpressionType.Equal, first.Type); Assert.AreEqual(1, first.RightOperand); var second = expr.RightOperand as SimpleExpression; Assert.IsNotNull(second); reference = second.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("FreeTextValue", reference.GetName()); Assert.AreEqual("freeTextFacet_1", reference.GetOwner().GetAlias()); var function = second.RightOperand as SimpleFunction; Assert.IsNotNull(function); Assert.AreEqual("like", function.Name.ToLowerInvariant()); Assert.AreEqual(1, function.Args.Count); Assert.AreEqual("GiveCamp%", function.Args.First()); Assert.AreEqual(SimpleExpressionType.Function, second.Type); }
public SearchController() { service = new SearchQueryService <SearchableMediaItem>(); }
public void HasQueryPositive(FhirVersion fhirVersion, ResourceType resourceContext, string Query) { //Prepare SearchQueryService SearchQueryService = SetupSearchQueryService(); Dictionary <string, StringValues> QueryDictonary; QueryDictonary = new Dictionary <string, StringValues> { { Query.Split('=')[0], new StringValues(Query.Split('=')[1]) }, }; FhirSearchQuery FhirSearchQuery = new FhirSearchQuery(); FhirSearchQuery.Parse(QueryDictonary); //Act ISerachQueryServiceOutcome Outcome = SearchQueryService.Process(fhirVersion, resourceContext, FhirSearchQuery).Result; //Assert Assert.NotNull(Outcome); Assert.Equal(1, Outcome.HasList.Count); Assert.Equal(0, Outcome.InvalidSearchQueryList.Count); Assert.Equal(0, Outcome.UnsupportedSearchQueryList.Count); Assert.Equal(0, Outcome.SearchQueryList.Count); Assert.Equal(resourceContext, Outcome.ResourceContext); var HasItem = Outcome.HasList[0]; Assert.Equal("Observation", HasItem.TargetResourceForSearchQuery.GetCode()); if (Query.Split("_has").Length == 2) { Assert.Null(HasItem.ChildSearchQueryHas); Assert.NotNull(HasItem.BackReferenceSearchParameter); Assert.Equal("patient", HasItem.BackReferenceSearchParameter !.Name); Assert.NotNull(HasItem.SearchQuery); Assert.Equal("code", HasItem.SearchQuery !.Name); if (HasItem.SearchQuery is SearchQueryString SearchQueryString) { Assert.Equal("1234-5", SearchQueryString.ValueList[0].Value); } } else { Assert.NotNull(HasItem.BackReferenceSearchParameter); Assert.Equal("patient", HasItem.BackReferenceSearchParameter !.Name); Assert.Null(HasItem.SearchQuery); Assert.NotNull(HasItem.ChildSearchQueryHas); Assert.Equal("AuditEvent", HasItem.ChildSearchQueryHas !.TargetResourceForSearchQuery.GetCode()); Assert.NotNull(HasItem.ChildSearchQueryHas !.BackReferenceSearchParameter); Assert.Equal("entity", HasItem.ChildSearchQueryHas !.BackReferenceSearchParameter !.Name); Assert.NotNull(HasItem.ChildSearchQueryHas !.SearchQuery); Assert.Equal("entity-name", HasItem.ChildSearchQueryHas !.SearchQuery !.Name); if (HasItem.ChildSearchQueryHas !.SearchQuery is object) { if (HasItem.ChildSearchQueryHas.SearchQuery is SearchQueryString SearchQueryString) { Assert.Equal("MyUserId".ToLower(), SearchQueryString.ValueList[0].Value); } } } }
public void LocationOnCity() { var criteria = new[] { new LocationSearchCriteria { InternalName = LocationSearchCriteria.City, SearchOperator = SearchOperator.EqualTo, Type = SearchFieldType.String, Value = "London" } }; var expr = new SearchQueryService(new DatabaseProvider()).CompileLocationCriteria(criteria, null); var reference = expr.LeftOperand as ObjectReference; Assert.IsNotNull(reference); Assert.AreEqual("city", reference.GetName()); Assert.AreEqual(SimpleExpressionType.Equal, expr.Type); Assert.AreEqual("London", expr.RightOperand); }
public void IncludeQueryPositive(FhirVersion fhirVersion, ResourceType resourceContext, IncludeType parameterInclude, string isRecurseIterate, ResourceType sourceResource, string searchParameterName, ResourceType?modifierResource) { //Prepare SearchQueryService SearchQueryService = SetupSearchQueryService(); Dictionary <string, StringValues> QueryDictonary; if (!string.IsNullOrWhiteSpace(isRecurseIterate)) { if (modifierResource.HasValue) { QueryDictonary = new Dictionary <string, StringValues> { { $"{parameterInclude.GetCode()}:{isRecurseIterate}", new StringValues($"{sourceResource.GetCode()}:{searchParameterName}:{modifierResource.GetCode()}") }, }; } else { QueryDictonary = new Dictionary <string, StringValues> { { $"{parameterInclude.GetCode()}:{isRecurseIterate}", new StringValues($"{sourceResource.GetCode()}:{searchParameterName}") }, }; } } else { if (modifierResource.HasValue) { QueryDictonary = new Dictionary <string, StringValues> { { $"{parameterInclude.GetCode()}", new StringValues($"{sourceResource.GetCode()}:{searchParameterName}:{modifierResource.GetCode()}") }, }; } else { QueryDictonary = new Dictionary <string, StringValues> { { $"{parameterInclude.GetCode()}", new StringValues($"{sourceResource.GetCode()}:{searchParameterName}") }, }; } } FhirSearchQuery FhirSearchQuery = new FhirSearchQuery(); FhirSearchQuery.Parse(QueryDictonary); //Act ISerachQueryServiceOutcome Outcome = SearchQueryService.Process(fhirVersion, resourceContext, FhirSearchQuery).Result; //Assert Assert.NotNull(Outcome); Assert.Equal(0, Outcome.InvalidSearchQueryList.Count); Assert.Null(Outcome.CountRequested); Assert.Equal(0, Outcome.SearchQueryList.Count); Assert.Equal(Common.Enums.ResourceType.Observation, Outcome.ResourceContext); Assert.Equal(1, Outcome.IncludeList.Count); var IncludeItem = Outcome.IncludeList[0]; if (isRecurseIterate == "recurse") { Assert.True(IncludeItem.IsRecurse); Assert.True(IncludeItem.IsRecurseIterate); } else { Assert.False(IncludeItem.IsRecurse); } if (isRecurseIterate == "iterate") { Assert.True(IncludeItem.IsIterate); Assert.True(IncludeItem.IsRecurseIterate); } else { Assert.False(IncludeItem.IsIterate); } Assert.Equal(parameterInclude, IncludeItem.Type); Assert.Equal(sourceResource, IncludeItem.SourceResourceType); if (modifierResource.HasValue) { Assert.Equal(modifierResource, IncludeItem.SearchParameterTargetResourceType); } else { Assert.Null(IncludeItem.SearchParameterTargetResourceType); } Assert.Single(IncludeItem.SearchParameterList); var SearchParameter = IncludeItem.SearchParameterList[0]; Assert.Equal(searchParameterName, SearchParameter.Name); }