/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalID">The portal ID</param> /// <param name="userID">ID of the user is searching</param> /// <param name="searchString">The text to search</param> /// <param name="searchField">The fields where perfoming the search</param> /// <returns> /// The SELECT sql to perform a search on the current module /// </returns> public override string SearchSqlSelect(int portalID, int userID, string searchString, string searchField) { SearchDefinition s = new SearchDefinition("rb_Discussion", "Title", "Body", "CreatedByUser", "CreatedDate", searchField); return(s.SearchSqlSelect(portalID, userID, searchString)); }
public void NonTypedTests_Multiple_Criteria_Per_Condition_Should_Error() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("NonTypedTests_Multiple_Criteria_Per_Condition_Should_Error") .Options; using (var context = new TestContext(options)) { var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter.Criteria.Add(new Criteria.CriteriaContainer <TestEntity>() { SingleCriterion = new Criteria.SingleCriterion <TestEntity>(), RangeCriterion = new Criteria.RangeCriterion() }); // Act Action action = () => { var searcher = new Searcher <TestEntity>(context.TestEntities); var searchResults = searcher.Search(searchDefinition); }; // Assert Assert.Throws <NotSupportedException>(action); } }
/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalId"> /// The portal ID /// </param> /// <param name="userId"> /// ID of the user is searching /// </param> /// <param name="searchString"> /// The text to search /// </param> /// <param name="searchField"> /// The fields where performing the search /// </param> /// <returns> /// The SELECT SQL to perform a search on the current module /// </returns> /// <remarks> /// </remarks> public override string SearchSqlSelect(int portalId, int userId, string searchString, string searchField) { // For better performance is necessary to add in // method FillPortalDS from PortalSearch.ascx.cs the // next case: // case "875254B7-2471-491F-BAF8-4AFC261CC224": //EnhancedHtml // strLink = HttpUrlBuilder.BuildUrl("~/DesktopDefault.aspx", Convert.ToInt32(strTabID), strLocate); // break; var dbTable = "rb_EnhancedHtml"; if (this.Version == WorkFlowVersion.Staging) { dbTable += "_st"; } var s = new SearchDefinition(dbTable, "Title", "DesktopHtml", "CreatedByUser", "CreatedDate", searchField); var retorno = s.SearchSqlSelect(portalId, userId, searchString); if (HttpContext.Current != null && HttpContext.Current.Items["PortalSettings"] != null) { var pS = (PortalSettings)HttpContext.Current.Items["PortalSettings"]; retorno += string.Format( " AND ((itm.CultureCode = '{0}') OR (itm.CultureCode = '{1}'))", pS.PortalUILanguage.LCID, CultureInfo.InvariantCulture.LCID); } return(retorno); }
public void Serialization_PreFilter_And_Filter_And_Sort_And_Page() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("Serialization_PreFilter_And_Filter_And_Sort_And_Page") .Options; using (var context = new TestContext(options)) { // 510 entities: 255 true and 255 false for (int i = 0; i < byte.MaxValue; i++) { context.TestEntities.Add(new TestEntity() { ByteProperty = (byte)i, BoolProperty = true }); } for (int i = 0; i < byte.MaxValue; i++) { context.TestEntities.Add(new TestEntity() { ByteProperty = (byte)i, BoolProperty = false }); } context.SaveChanges(); // Act var searchDefinition = new SearchDefinition <TestEntity>(page: 1, recordsPerPage: 50); searchDefinition.PreFilter.Where(i => i.BoolProperty).IsTrue(); searchDefinition.Filter.Where(i => i.ByteProperty).GreaterThan(100); searchDefinition.Sort.DescendingBy(i => i.ByteProperty); var jsonString = JsonConvert.SerializeObject(searchDefinition); var jsonDefintion = JsonConvert.DeserializeObject <SearchDefinition <TestEntity> >(jsonString); var searchResults = new Searcher <TestEntity>(context.TestEntities).Search(jsonDefintion); var preFilteredResults = context.TestEntities .Where(i => i.BoolProperty) .ToList(); var filteredResults = preFilteredResults .Where(i => i.BoolProperty) .Where(i => i.ByteProperty > 100) .OrderByDescending(i => i.ByteProperty) .ToList(); var pagedResults = filteredResults .Skip(50) .Take(50) .ToList(); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(filteredResults.Count, searchResults.FilteredRecordCount); Assert.Equal(pagedResults.Count, searchResults.ResultSet.Count); Assert.Equal(pagedResults[0].ByteProperty, searchResults.ResultSet[0].ByteProperty); Assert.Equal(pagedResults[pagedResults.Count - 1].ByteProperty, searchResults.ResultSet[searchResults.ResultSet.Count - 1].ByteProperty); } }
public void AdvancedFilter_And_Filter() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { BoolProperty = false, ByteProperty = 123, DateTimeProperty = new DateTime(2004, 4, 14), GuidProperty = Guid.NewGuid(), IntProperty = 1, StringProperty = "Awesome sauce" }, new TestEntity() { BoolProperty = true, ByteProperty = 221, DateTimeProperty = new DateTime(2008, 8, 18), GuidProperty = Guid.NewGuid(), IntProperty = 1, StringProperty = "Bond. James Bond." }, new TestEntity() { BoolProperty = false, ByteProperty = 56, DateTimeProperty = new DateTime(2002, 2, 12), GuidProperty = Guid.NewGuid(), IntProperty = 1, StringProperty = "Onomatopoeia" }, new TestEntity() { BoolProperty = true, ByteProperty = 32, DateTimeProperty = new DateTime(2006, 6, 16), GuidProperty = Guid.NewGuid(), IntProperty = 2, StringProperty = "Noon racecar sagas" } }; // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.ByteProperty).GreaterThan(100) .And(i => i.BoolProperty).IsTrue(); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition); var expectedResults = testCollection .Where(i => i.ByteProperty > 100 && i.BoolProperty) .ToList(); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count, searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count, searchResults.FilteredRecordCount); }
public void Search_Single_Navigation_Property_One_Level_Deep_Should_Succeed() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; using (var context = new TestContext(options)) { context.TestParentEntities.Add(new TestParentEntity() { ParentId = 1, Title = "Parent 1" }); context.TestParentEntities.Add(new TestParentEntity() { ParentId = 2, Title = "Parent 2" }); context.TestParentEntities.Add(new TestParentEntity() { ParentId = 3, Title = "Parent 3" }); context.SaveChanges(); context.TestChildEntities.Add(new TestChildEntity() { ChildId = 4, ParentId = 1, Title = "Child 4" }); context.TestChildEntities.Add(new TestChildEntity() { ChildId = 5, ParentId = 2, Title = "Child 5" }); context.TestChildEntities.Add(new TestChildEntity() { ChildId = 6, ParentId = 3, Title = "Child 6" }); context.SaveChanges(); } using (var context = new TestContext(options)) { var dataset = context.TestParentEntities .Include("Child"); // Act var searchDefinition = new SearchDefinition <TestParentEntity>(); searchDefinition.Filter .Where(i => i.Child.ChildId).IsEqualTo(5); var searchResults = new Searcher <TestParentEntity>(dataset) .Search(searchDefinition); var expectedResults = dataset.Where(i => i.Child.ChildId == 5); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); Assert.True(searchResults.ResultSet[0].ParentId == 2); Assert.True(searchResults.ResultSet[0].Child.ChildId == 5); } }
public void NonTypedTests_Missing_Property_Name_Should_Error() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("NonTypedTests_Missing_Property_Name_Should_Error") .Options; using (var context = new TestContext(options)) { var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter.Criteria.Add(new Criteria.CriteriaContainer <TestEntity>() { SingleCriterion = new Criteria.SingleCriterion <TestEntity>() }); // Act Action action = () => { var searcher = new Searcher <TestEntity>(context.TestEntities); var searchResults = searcher.Search(searchDefinition); }; // Assert Assert.Throws <ArgumentNullException>(action); } }
public bool GetBSBReport() { _uow = new UnitOfWork(bsbtacContext); Random rnd = new Random(); SearchDefinition searchDefinition = new SearchDefinition(); ApplSummary applSummary = new ApplSummary(); Cameo2006 cameo2006 = new Cameo2006(); try { lock (this) { var lastUpdatedDatetime = new SqlParameter("@LastUpdatedDatetime", DateTime.Now); searchDefinition = _uow.Repository<SearchDefinition>().SqlQuery("spGetNextBSBSearch @LastUpdatedDatetime", lastUpdatedDatetime).First(); } Thread.Sleep(rnd.Next(3000, 10000)); applSummary.SearchDefinitionId = searchDefinition.SearchDefinitionId; applSummary.AccountInformation = "AccountInformation" + searchDefinition.DebtCode; applSummary.NumberOfDisputes = searchDefinition.DebtCode; cameo2006.SearchDefinitionId = searchDefinition.SearchDefinitionId; cameo2006.LocalityInformation = "LocalityInformation" + searchDefinition.DebtCode; cameo2006.CouncilTaxBand = searchDefinition.DebtCode; lock (this) { applSummary.ObjectState = ObjectState.Added; cameo2006.ObjectState = ObjectState.Added; _uow.Repository<ApplSummary>().Insert(applSummary); _uow.Repository<Cameo2006>().Insert(cameo2006); _uow.Save(); searchDefinition.Status = 3; searchDefinition.LastUpdatedDatetime = DateTime.Now; _uow.Repository<SearchDefinition>().Update(searchDefinition); _uow.Save(); } return true; } catch (EntityCommandExecutionException) { _log.Info("No new search found"); return false; } catch (Exception ex) { lock(this) { searchDefinition.Status = 4; searchDefinition.LastUpdatedDatetime = DateTime.Now; _uow.Repository<SearchDefinition>().Update(searchDefinition); _uow.Save(); } _log.Error(ex.Message); return false; } }
/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalID">The portal ID</param> /// <param name="userID">ID of the user is searching</param> /// <param name="searchString">The text to search</param> /// <param name="searchField">The fields where perfoming the search</param> /// <returns>The SELECT sql to perform a search on the current module</returns> public override string SearchSqlSelect(int portalID, int userID, string searchString, string searchField) { SearchDefinition s = new SearchDefinition("rb_Announcements", "Title", "Description", "CreatedByUser", "CreatedDate", searchField); return(s.SearchSqlSelect(portalID, userID, searchString)); }
public ElasticSearchHelper() { var settings = new ConnectionSettings(WebConfigHelper.ElasticSearchUri, indexName); settings.ThrowOnElasticsearchServerExceptions(); elasticClient = new ElasticClient(settings); searchDefinition = ElasticSearchHelper.GetSearchDefinition(); }
public void SearchDefinition_Paging_Page_And_RecordsPerPage_Too_Low() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("SearchDefinition_Paging_Page_And_RecordsPerPage_Too_Low") .Options; using (var context = new TestContext(options)) { context.TestEntities.Add(new TestEntity() { BoolProperty = false, ByteProperty = 123, DateTimeProperty = new DateTime(2000, 4, 12), GuidProperty = Guid.NewGuid(), IntProperty = 89234, StringProperty = "Awesome sauce" }); context.TestEntities.Add(new TestEntity() { BoolProperty = true, ByteProperty = 221, DateTimeProperty = new DateTime(2008, 8, 18), GuidProperty = Guid.NewGuid(), IntProperty = 6485, StringProperty = "Bond. James Bond." }); context.TestEntities.Add(new TestEntity() { BoolProperty = false, ByteProperty = 56, DateTimeProperty = new DateTime(2000, 4, 12), GuidProperty = Guid.NewGuid(), IntProperty = 159753, StringProperty = "Onomatopoeia" }); context.SaveChanges(); // Act var searchDefinition = new SearchDefinition <TestEntity>() { Page = -7, RecordsPerPage = -49 }; var searchResults = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition); var expectedResults = context.TestEntities .Skip(-7) .Take(-49) .ToList(); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(-7, searchResults.Page); Assert.Equal(-49, searchResults.RecordsPerPage); Assert.Equal(expectedResults.Count, searchResults.ResultSet.Count); Assert.Equal(context.TestEntities.Count(), searchResults.FilteredRecordCount); } }
public void Search_Single_Navigation_Property_N_Levels_Deep_Should_Succeed() { // Arrange var testCollection = new List <TestParentEntity>() { new TestParentEntity() { ParentId = 1, Title = "Parent 1", Child = new TestChildEntity() { ChildId = 2, Title = "Child 2", NChild = new TestChildEntity() { ChildId = 3, Title = "Child 3", NChild = new TestChildEntity() { ChildId = 4, Title = "Child 4", NChild = new TestChildEntity() { ChildId = 5, Title = "Child 5", NChild = new TestChildEntity() { ChildId = 6, Title = "Child 6" } } } } } } }; // Act var searchDefinition = new SearchDefinition <TestParentEntity>(); searchDefinition.Filter .Where(i => i.Child.NChild.NChild.NChild.NChild.ChildId).IsEqualTo(6); var searchResults = new Searcher <TestParentEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => i.Child.NChild.NChild.NChild.NChild.ChildId == 6); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); Assert.True(searchResults.ResultSet[0].ParentId == 1); Assert.True(searchResults.ResultSet[0].Child.ChildId == 2); Assert.True(searchResults.ResultSet[0].Child.NChild.ChildId == 3); Assert.True(searchResults.ResultSet[0].Child.NChild.NChild.ChildId == 4); Assert.True(searchResults.ResultSet[0].Child.NChild.NChild.NChild.ChildId == 5); Assert.True(searchResults.ResultSet[0].Child.NChild.NChild.NChild.NChild.ChildId == 6); }
public void NullableGuid_IsNotEqualTo_Null_Search() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("NullableGuid_IsNotEqualTo_Null_Search") .Options; using (var context = new TestContext(options)) { context.TestEntities.Add(new TestEntity() { NullableGuidProperty = new Guid("AF135DF9-5DEA-414C-ADCB-BF743ADC129B") }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = null }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = new Guid("F5A9D2E2-B8E6-4BA8-8E24-1F0201D84283") }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = new Guid("F55FF70A-9C4C-4F48-84B3-04DDB4B83BB7") }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = new Guid("873EAD6C-48CD-4457-99E1-00295D004857") }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = null }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = new Guid("66EFCE02-AC2D-414A-8AB1-F74E07EE83E5") }); context.TestEntities.Add(new TestEntity() { NullableGuidProperty = null }); context.SaveChanges(); // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableGuidProperty).IsNotEqualTo(null); var searchResults = new Searcher <TestEntity>(context.TestEntities) .Search(searchDefinition); var expectedResults = context.TestEntities.Where(i => i.NullableGuidProperty != null); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); } }
/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalID">The portal ID</param> /// <param name="userID">ID of the user is searching</param> /// <param name="searchString">The text to search</param> /// <param name="searchField">The fields where perfoming the search</param> /// <returns> /// The SELECT sql to perform a search on the current module /// </returns> public override string SearchSqlSelect(int portalID, int userID, string searchString, string searchField) { SearchDefinition s = new SearchDefinition("rb_Documents", "FileFriendlyName", "FileNameUrl", "CreatedByUser", "CreatedDate", searchField); //Add extra search fields here, this way s.ArrSearchFields.Add("itm.Category"); return(s.SearchSqlSelect(portalID, userID, searchString)); }
/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalId"> /// The portal ID /// </param> /// <param name="userId"> /// ID of the user is searching /// </param> /// <param name="searchString"> /// The text to search /// </param> /// <param name="searchField"> /// The fields where performing the search /// </param> /// <returns> /// The SELECT SQL to perform a search on the current module /// </returns> public override string SearchSqlSelect(int portalId, int userId, string searchString, string searchField) { var s = new SearchDefinition( "rb_Articles", "Title", "Abstract", "CreatedByUser", "CreatedDate", searchField); // Add extra search fields here, this way s.ArrSearchFields.Add("itm.Description"); return(s.SearchSqlSelect(portalId, userId, searchString)); }
/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalID">The portal ID</param> /// <param name="userID">ID of the user is searching</param> /// <param name="searchString">The text to search</param> /// <param name="searchField">The fields where perfoming the search</param> /// <returns> /// The SELECT sql to perform a search on the current module /// </returns> public override string SearchSqlSelect(int portalID, int userID, string searchString, string searchField) { SearchDefinition s = new SearchDefinition("rb_Events", "Title", "Description", "CreatedByUser", "CreatedDate", searchField); //Add extra search fields here, this way s.ArrSearchFields.Add("itm.WhereWhen"); return(s.SearchSqlSelect(portalID, userID, searchString)); }
public void Serialization_PreFilter_And_Filter_And_Sort_And_Page() { // Arrange // 510 entities: 255 true and 255 false var testCollection = new List <TestEntity>(); for (int i = 0; i < byte.MaxValue; i++) { testCollection.Add(new TestEntity() { ByteProperty = (byte)i, BoolProperty = true }); } for (int i = 0; i < byte.MaxValue; i++) { testCollection.Add(new TestEntity() { ByteProperty = (byte)i, BoolProperty = false }); } // Act var searchDefinition = new SearchDefinition <TestEntity>(page: 1, recordsPerPage: 50); searchDefinition.PreFilter.Where(i => i.BoolProperty).IsTrue(); searchDefinition.Filter.Where(i => i.ByteProperty).GreaterThan(100); searchDefinition.Sort.DescendingBy(i => i.ByteProperty); var jsonString = JsonConvert.SerializeObject(searchDefinition); var jsonDefintion = JsonConvert.DeserializeObject <SearchDefinition <TestEntity> >(jsonString); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(jsonDefintion); var preFilteredResults = testCollection .Where(i => i.BoolProperty) .ToList(); var filteredResults = preFilteredResults .Where(i => i.BoolProperty) .Where(i => i.ByteProperty > 100) .OrderByDescending(i => i.ByteProperty) .ToList(); var pagedResults = filteredResults .Skip(50) .Take(50) .ToList(); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(filteredResults.Count, searchResults.FilteredRecordCount); Assert.Equal(pagedResults.Count, searchResults.ResultSet.Count); Assert.Equal(pagedResults[0].ByteProperty, searchResults.ResultSet[0].ByteProperty); Assert.Equal(pagedResults[pagedResults.Count - 1].ByteProperty, searchResults.ResultSet[searchResults.ResultSet.Count - 1].ByteProperty); }
public void NullableBool_DoesNotEndWith_Search() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("NullableBool_NotIn_Search") .Options; using (var context = new TestContext(options)) { context.TestEntities.Add(new TestEntity() { NullableBoolProperty = true }); context.TestEntities.Add(new TestEntity() { NullableBoolProperty = false }); context.TestEntities.Add(new TestEntity() { NullableBoolProperty = null }); context.TestEntities.Add(new TestEntity() { NullableBoolProperty = true }); context.TestEntities.Add(new TestEntity() { NullableBoolProperty = false }); context.TestEntities.Add(new TestEntity() { NullableBoolProperty = null }); context.TestEntities.Add(new TestEntity() { NullableBoolProperty = true }); context.SaveChanges(); // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableBoolProperty).DoesNotEndWith("ue"); var searchResults = new Searcher <TestEntity>(context.TestEntities) .Search(searchDefinition); var expectedResults = context.TestEntities.Where(i => !i.NullableBoolProperty.ToString().EndsWith("ue")); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); } }
public void NullableGuid_IsNotEqualTo_Null_Search() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { NullableGuidProperty = new Guid("AF135DF9-5DEA-414C-ADCB-BF743ADC129B") }, new TestEntity() { NullableGuidProperty = null }, new TestEntity() { NullableGuidProperty = new Guid("F5A9D2E2-B8E6-4BA8-8E24-1F0201D84283") }, new TestEntity() { NullableGuidProperty = new Guid("F55FF70A-9C4C-4F48-84B3-04DDB4B83BB7") }, new TestEntity() { NullableGuidProperty = new Guid("873EAD6C-48CD-4457-99E1-00295D004857") }, new TestEntity() { NullableGuidProperty = null }, new TestEntity() { NullableGuidProperty = new Guid("66EFCE02-AC2D-414A-8AB1-F74E07EE83E5") }, new TestEntity() { NullableGuidProperty = null } }; // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableGuidProperty).IsNotEqualTo(null); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => i.NullableGuidProperty != null); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); }
public void NullableInt_LessThanOrEqualTo_Search() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { NullableIntProperty = 1 }, new TestEntity() { NullableIntProperty = 2 }, new TestEntity() { NullableIntProperty = 3 }, new TestEntity() { NullableIntProperty = 4 }, new TestEntity() { NullableIntProperty = 5 }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null } }; // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableIntProperty).LessThanOrEqualTo(3); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => i.NullableIntProperty <= 3); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); }
public bool SaveQuery(SearchDefinition searchDefinition, SearchParameters searchParameters) { if (typeof(T).Equals(typeof(Contact))) { return(new ContactSearch <T>(searchParameters.AccountId).SaveQuery(searchDefinition, searchParameters)); } else { throw new NotImplementedException("This type of document is not indexed:" + typeof(T).ToString()); } }
/// <summary> /// Searchable module implementation /// </summary> /// <param name="portalID">The portal ID</param> /// <param name="userID">ID of the user is searching</param> /// <param name="searchString">The text to search</param> /// <param name="searchField">The fields where perfoming the search</param> /// <returns> /// The SELECT sql to perform a search on the current module /// </returns> public override string SearchSqlSelect(int portalID, int userID, string searchString, string searchField) { SearchDefinition s = new SearchDefinition("rb_EnhancedLinks", "Title", "Description", "CreatedByUser", "CreatedDate", searchField); s.ArrSearchFields.Add("itm.Url"); s.ArrSearchFields.Add("itm.ImageUrl"); return(s.SearchSqlSelect(portalID, userID, searchString, true)); }
public void NullableInt_NotIn_Search() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { NullableIntProperty = 1 }, new TestEntity() { NullableIntProperty = 2 }, new TestEntity() { NullableIntProperty = 3 }, new TestEntity() { NullableIntProperty = 4 }, new TestEntity() { NullableIntProperty = 5 }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null } }; // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableIntProperty).NotIn(2, 3, 4); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => !(new int?[] { 2, 3, 4 }.Contains(i.NullableIntProperty))); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); }
public void NullableInt_DoesNotEndWith_Search() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { NullableIntProperty = 1 }, new TestEntity() { NullableIntProperty = 12 }, new TestEntity() { NullableIntProperty = 123 }, new TestEntity() { NullableIntProperty = 1234 }, new TestEntity() { NullableIntProperty = 12345 }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null } }; // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableIntProperty).DoesNotEndWith("3"); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => !i.NullableIntProperty.ToString().EndsWith("3")); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); }
public void SearchDefinition_Paging_Does_Not_Duplicate_Or_Skip_Any_Records() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("SearchDefinition_Paging_Does_Not_Duplicate_Or_Skip_Any_Records") .Options; using (var context = new TestContext(options)) { context.TestEntities.Add(new TestEntity()); // Act var searchDefinition1 = new SearchDefinition <TestEntity>() { Page = 0, RecordsPerPage = 50 }; // 0-50 var searchDefinition2 = new SearchDefinition <TestEntity>() { Page = 1, RecordsPerPage = 50 }; // 51-100 var searchDefinition3 = new SearchDefinition <TestEntity>() { Page = 2, RecordsPerPage = 50 }; // 101-150 var searchDefinition4 = new SearchDefinition <TestEntity>() { Page = 3, RecordsPerPage = 50 }; // 151-200 var searchDefinition5 = new SearchDefinition <TestEntity>() { Page = 4, RecordsPerPage = 50 }; // 201-250 var searchDefinition6 = new SearchDefinition <TestEntity>() { Page = 5, RecordsPerPage = 50 }; // 251-300 var searchResults1 = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition1); var searchResults2 = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition2); var searchResults3 = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition3); var searchResults4 = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition4); var searchResults5 = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition5); var searchResults6 = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition6); var recombinedDataset = new List <TestEntity>(); recombinedDataset.AddRange(searchResults1.ResultSet); recombinedDataset.AddRange(searchResults2.ResultSet); recombinedDataset.AddRange(searchResults3.ResultSet); recombinedDataset.AddRange(searchResults4.ResultSet); recombinedDataset.AddRange(searchResults5.ResultSet); recombinedDataset.AddRange(searchResults6.ResultSet); // Assert Assert.Equal(context.TestEntities.Count(), recombinedDataset.Count); } }
public void NullableDateTime_NotIn_Null_Search() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { NullableDateTimeProperty = null }, new TestEntity() { NullableDateTimeProperty = new DateTime(2000, 4, 12) }, new TestEntity() { NullableDateTimeProperty = new DateTime(2004, 6, 10) }, new TestEntity() { NullableDateTimeProperty = new DateTime(2007, 7, 21) }, new TestEntity() { NullableDateTimeProperty = new DateTime(2012, 9, 15) }, new TestEntity() { NullableDateTimeProperty = new DateTime(2016, 11, 7) }, new TestEntity() { NullableDateTimeProperty = null } }; var two = new DateTime(2004, 6, 10); var three = new DateTime(2007, 7, 21); var four = new DateTime(2012, 9, 15); // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableDateTimeProperty).NotIn(new DateTime?[] { null }); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => !(new DateTime?[] { null }.Contains(i.NullableDateTimeProperty))); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); }
public void NullableInt_NotBetween_Search() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { NullableIntProperty = 1 }, new TestEntity() { NullableIntProperty = 2 }, new TestEntity() { NullableIntProperty = 3 }, new TestEntity() { NullableIntProperty = 4 }, new TestEntity() { NullableIntProperty = 5 }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null }, new TestEntity() { NullableIntProperty = null } }; // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.NullableIntProperty).NotBetween(2, 4); var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()) .Search(searchDefinition); // Assert Assert.NotNull(searchResults.ResultSet); Assert.NotEmpty(searchResults.ResultSet); Assert.Equal(2, searchResults.ResultSet.Count); Assert.Equal(2, searchResults.FilteredRecordCount); }
public void SearchDefinition_Paging_Does_Not_Duplicate_Or_Skip_Any_Records() { // Arrange var testCollection = new List <TestEntity>(); for (int i = 0; i < byte.MaxValue; i++) { testCollection.Add(new TestEntity()); } // Act var searchDefinition1 = new SearchDefinition <TestEntity>() { Page = 0, RecordsPerPage = 50 }; // 0-50 var searchDefinition2 = new SearchDefinition <TestEntity>() { Page = 1, RecordsPerPage = 50 }; // 51-100 var searchDefinition3 = new SearchDefinition <TestEntity>() { Page = 2, RecordsPerPage = 50 }; // 101-150 var searchDefinition4 = new SearchDefinition <TestEntity>() { Page = 3, RecordsPerPage = 50 }; // 151-200 var searchDefinition5 = new SearchDefinition <TestEntity>() { Page = 4, RecordsPerPage = 50 }; // 201-250 var searchDefinition6 = new SearchDefinition <TestEntity>() { Page = 5, RecordsPerPage = 50 }; // 251-300 var searchResults1 = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition1); var searchResults2 = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition2); var searchResults3 = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition3); var searchResults4 = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition4); var searchResults5 = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition5); var searchResults6 = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition6); var recombinedDataset = new List <TestEntity>(); recombinedDataset.AddRange(searchResults1.ResultSet); recombinedDataset.AddRange(searchResults2.ResultSet); recombinedDataset.AddRange(searchResults3.ResultSet); recombinedDataset.AddRange(searchResults4.ResultSet); recombinedDataset.AddRange(searchResults5.ResultSet); recombinedDataset.AddRange(searchResults6.ResultSet); // Assert Assert.Equal(testCollection.Count, recombinedDataset.Count); }
public void SearchDefinition_Paging_Page_And_RecordsPerPage_Too_Low() { // Arrange var testCollection = new List <TestEntity>() { new TestEntity() { BoolProperty = false, ByteProperty = 123, DateTimeProperty = new DateTime(2000, 4, 12), GuidProperty = Guid.NewGuid(), IntProperty = 89234, StringProperty = "Awesome sauce" }, new TestEntity() { BoolProperty = true, ByteProperty = 221, DateTimeProperty = new DateTime(2008, 8, 18), GuidProperty = Guid.NewGuid(), IntProperty = 6485, StringProperty = "Bond. James Bond." }, new TestEntity() { BoolProperty = false, ByteProperty = 56, DateTimeProperty = new DateTime(2000, 4, 12), GuidProperty = Guid.NewGuid(), IntProperty = 159753, StringProperty = "Onomatopoeia" } }; // Act var searchDefinition = new SearchDefinition <TestEntity>() { Page = -7, RecordsPerPage = -49 }; var searchResults = new Searcher <TestEntity>(testCollection.AsQueryable()).Search(searchDefinition); var expectedResults = testCollection .Skip(-7) .Take(-49) .ToList(); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(-7, searchResults.Page); Assert.Equal(-49, searchResults.RecordsPerPage); Assert.Equal(expectedResults.Count, searchResults.ResultSet.Count); Assert.Equal(testCollection.Count, searchResults.FilteredRecordCount); }
public void SearchDefinition_Null_Criteria() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("SearchDefinition_Null_Criteria") .Options; using (var context = new TestContext(options)) { context.TestEntities.Add(new TestEntity() { BoolProperty = false, ByteProperty = 123, DateTimeProperty = new DateTime(2000, 4, 12), GuidProperty = Guid.NewGuid(), IntProperty = 89234, StringProperty = "Awesome sauce" }); context.TestEntities.Add(new TestEntity() { BoolProperty = true, ByteProperty = 221, DateTimeProperty = new DateTime(2008, 8, 18), GuidProperty = Guid.NewGuid(), IntProperty = 6485, StringProperty = "Bond. James Bond." }); context.TestEntities.Add(new TestEntity() { BoolProperty = false, ByteProperty = 56, DateTimeProperty = new DateTime(2000, 4, 12), GuidProperty = Guid.NewGuid(), IntProperty = 159753, StringProperty = "Onomatopoeia" }); context.SaveChanges(); // Act var searchDefinition = new SearchDefinition <TestEntity>() { Filter = null, PreFilter = null, Sort = null }; var searchResults = new Searcher <TestEntity>(context.TestEntities).Search(searchDefinition); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(context.TestEntities.Count(), searchResults.ResultSet.Count); Assert.Equal(context.TestEntities.Count(), searchResults.FilteredRecordCount); } }
public void Search_Range_Navigation_Property_One_Level_Deep_Should_Succeed() { // Arrange var testCollection = new List <TestParentEntity>() { new TestParentEntity() { ParentId = 1, Title = "Parent 1", Child = new TestChildEntity() { ChildId = 4, Title = "Child 4" } }, new TestParentEntity() { ParentId = 2, Title = "Parent 2", Child = new TestChildEntity() { ChildId = 5, Title = "Child 5" } }, new TestParentEntity() { ParentId = 3, Title = "Parent 3", Child = new TestChildEntity() { ChildId = 6, Title = "Child 6" } } }; // Act var searchDefinition = new SearchDefinition <TestParentEntity>(); searchDefinition.Filter .Where(i => i.Child.ChildId).Between(5, 10); var searchResults = new Searcher <TestParentEntity>(testCollection.AsQueryable()) .Search(searchDefinition); var expectedResults = testCollection.Where(i => i.Child.ChildId >= 5 && i.Child.ChildId <= 10); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); }
public void DateTime_NotIn_Search() { // Arrange var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("DateTime_NotIn_Search") .Options; using (var context = new TestContext(options)) { context.TestEntities.Add(new TestEntity() { DateTimeProperty = new DateTime(2000, 4, 12) }); context.TestEntities.Add(new TestEntity() { DateTimeProperty = new DateTime(2004, 6, 10) }); context.TestEntities.Add(new TestEntity() { DateTimeProperty = new DateTime(2007, 7, 21) }); context.TestEntities.Add(new TestEntity() { DateTimeProperty = new DateTime(2012, 9, 15) }); context.TestEntities.Add(new TestEntity() { DateTimeProperty = new DateTime(2016, 11, 7) }); context.SaveChanges(); var two = new DateTime(2004, 6, 10); var three = new DateTime(2007, 7, 21); var four = new DateTime(2012, 9, 15); // Act var searchDefinition = new SearchDefinition <TestEntity>(); searchDefinition.Filter .Where(i => i.DateTimeProperty).NotIn(two, three, four); var searchResults = new Searcher <TestEntity>(context.TestEntities) .Search(searchDefinition); var expectedResults = context.TestEntities.Where(i => !(new DateTime[] { two, three, four }.Contains(i.DateTimeProperty))); // Assert Assert.NotNull(searchResults.ResultSet); Assert.Equal(expectedResults.Count(), searchResults.ResultSet.Count); Assert.Equal(expectedResults.Count(), searchResults.FilteredRecordCount); } }
private void LoadNewUploads() { _uow = new UnitOfWork(bsbtacContext); try { UploadDetail upload; lock (this) { upload = _uow.Repository<UploadDetail>().SqlQuery("spGetNextUploadedFile").First(); /* upload = _uow.Repository<UploadDetail>().Query() .Get() .Where(u => u.Status == 1) .First(); upload.Status = 2; upload.ObjectState = ObjectState.Modified; _uow.Repository<UploadDetail>().Update(upload); _uow.Save(); */ } var filename = upload.Filename; var path = @"C:\_Workspace\Projects\2012\BSBTAC\_Uploads\BSB\" + filename; var file = new StreamReader(path); string line = ""; while((line = file.ReadLine()) != null) { try { SearchDefinition searchDefinition = new SearchDefinition(); string[] data = line.Split(','); if(data[0].Equals("DebtCode")) { continue; } else { searchDefinition.UploadDetailId = upload.UploadDetailId; searchDefinition.DebtCode = Convert.ToInt32(data[0]); searchDefinition.Title = data[1]; searchDefinition.Forename = data[2]; searchDefinition.Surname = data[3]; searchDefinition.Othername = data[4]; searchDefinition.DOB = Convert.ToDateTime(data[5]); searchDefinition.BuildingNo = data[6]; searchDefinition.BuildingName = data[7]; searchDefinition.Locality = data[8]; searchDefinition.Sublocality = data[9]; searchDefinition.Posttown = data[10]; searchDefinition.Postcode = data[11]; searchDefinition.Type = Convert.ToByte(upload.Type); searchDefinition.Status = Convert.ToByte(1); searchDefinition.LastUpdatedDatetime = DateTime.Now; searchDefinition.ObjectState = ObjectState.Added; _uow.Repository<SearchDefinition>().Insert(searchDefinition); _uow.Save(); } } catch (Exception ex) { _log.Error(line + "-" + ex.Message); continue; } } file.Close(); } catch (EntityCommandExecutionException) { _log.Info("No new uploads found"); } catch(Exception ex) { _log.Error(ex.Message); } }