public void SearchCustomers() { // Default Configuration : SearchConfiguration.ConfigureSearch(); Customers.Search("LastName: Smith").Count().Should().Be(2); // returns Joe and Jane Smith Customers.Search("Joe").Count().Should().Be(1); // returns the single record of Joe Smith // Configuring searchable fields SearchConfiguration.ConfigureSearch(options => { options.Entity <Customer>() .AddDefaultSearchField(c => c.FirstName) .AddDefaultSearchField(c => c.LastName) .AddDefaultSearchField(c => c.City.Name) .Map(c => c.FirstName + " " + c.LastName, alias: "name") .Map(c => c.City.Name, alias: "city") .Map(c => c.City.Country, alias: "country") .Map(c => c.City.Population, alias: "citypop") .Map(c => c.City.Name + " " + c.City.Country, alias: "cityinfo"); }); Customers.Search("Name: John OR Edmonton").Count().Should().Be(2); // returns John Doe and Joe Smith (in Edmonton) Customers.Search("name: Joe Smith OR name: John").Count().Should().Be(2); // return Joe Smith and John doe Customers.Search("city = new york").Count().Should().Be(2); // returns the Jane and John Smith (who are in New York) Customers.Search("city: york").Count().Should().Be(2); // returns the Jane and John Smith (who are in New York) Customers.Search("citypop < 5000000").Count().Should().Be(1); // returns Joe Smith in Edmonton }
public void CanSearchByAlias() { SearchConfiguration.ConfigureSearch(options => { options.Entity <Customer>().Map(c => c.City, "location", "place", "town"); }); Customers.Search("location: london").Count().Should().Be(6); Customers.Search("place: lond").Count().Should().Be(6); Customers.Search("town: ondon").Count().Should().Be(6); }
public ComplexQueryTest() { SearchConfiguration.ConfigureSearch(options => { options.Entity <Product>() .Map(p => p.OrderDetails .Select(od => new { od.Order.Customer.ContactTitle, od.Order.Customer.ContactName }) .Select(customerInfo => customerInfo.ContactTitle + " " + customerInfo.ContactName) .LastOrDefault(), "Contact"); }); }
public NavigationPropertyTest() { SearchConfiguration.ConfigureSearch(options => { var employeeConfig = options.Entity <Employee>(); employeeConfig.Map(e => e.Manager.City, alias: "ManagerCity"); employeeConfig.Map(e => e.Manager == null ? "" : e.Manager.FirstName + " " + e.Manager.LastName, "Manager"); var customerConfig = options.Entity <Customer>(); customerConfig.Map(c => c.Orders.Select(y => y.ShipName), alias: "ShipName"); customerConfig.Map(c => c.Orders.Select(y => y.Freight), alias: "Freight"); }); }
public void SearchingNotMappedPropertyThrows(string propertyName) { SearchConfiguration.ConfigureSearch(options => { options.Entity <Customer>().Map(propertyName); }); var searchableProperties = new string[] { "CustomerID", "CompanyName", "ContactName", "ContactTitle", "Address", "City", "Region", "PostalCode", "Country", "Phone", "Fax" }; foreach (var prop in searchableProperties) { if (string.Equals(prop, propertyName, StringComparison.OrdinalIgnoreCase)) { // this should work fine Customers.Search(propertyName + ": whatever").Should().NotBeNull(); } else { // this should throw an exception beacuse it shouldn't know what to do with the property Action searchAction = () => { Customers.Search(prop + ": whatever").ToArray(); }; searchAction.Should().Throw <SearchParseException>(); } } }
public LogicalOperatorTest() { // Just use defaults for search SearchConfiguration.ConfigureSearch(); }
public EqualityOperatorTest() { // just use defaults SearchConfiguration.ConfigureSearch(); }