コード例 #1
0
            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
            }
コード例 #2
0
ファイル: MappingTest.cs プロジェクト: dchenier/Linq.Search
        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);
        }
コード例 #3
0
 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");
     });
 }
コード例 #4
0
        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");
            });
        }
コード例 #5
0
ファイル: MappingTest.cs プロジェクト: dchenier/Linq.Search
        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>();
                }
            }
        }
コード例 #6
0
 public LogicalOperatorTest()
 {
     // Just use defaults for search
     SearchConfiguration.ConfigureSearch();
 }
コード例 #7
0
 public EqualityOperatorTest()
 {
     // just use defaults
     SearchConfiguration.ConfigureSearch();
 }