Пример #1
0
        public void Past()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleDate>
            {
                new SampleDate
                {//0
                    DocDate = new DateTime(2019, 1, 1)
                },
                new SampleDate
                {//1
                    DocDate = new DateTime(2019, 2, 1)
                },
                new SampleDate
                {//2
                    DocDate = new DateTime(2019, 3, 7)
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleDate>(0, 10);
            var results    = searchData
                             .Should(SearchClause <SampleDate> .LessThan(x => x.DocDate, new DateTime(2019, 1, 7)))
                             .Sort(x => x.DocDate)
                             .Execute();
            var actual = results.Documents.ToList();

            //range
            Assert.Single(actual);
            Assert.Equal(expected[0].DocDate, actual[0].DocDate);
        }
Пример #2
0
 /// <summary>
 /// Create a new ODataUri. This contains the semantic meaning of the
 /// entire uri.
 /// </summary>
 /// <param name="parameterAliasValueAccessor">The ParameterAliasValueAccessor.</param>
 /// <param name="path">The top level path for this uri.</param>
 /// <param name="customQueryOptions">Any custom query options for this uri. Can be null.</param>
 /// <param name="selectAndExpand">Any $select or $expand option for this uri. Can be null.</param>
 /// <param name="filter">Any $filter option for this uri. Can be null.</param>
 /// <param name="orderby">Any $orderby option for this uri. Can be null</param>
 /// <param name="search">Any $search option for this uri. Can be null</param>
 /// <param name="apply">Any $apply option for this uri. Can be null</param>
 /// <param name="skip">Any $skip option for this uri. Can be null.</param>
 /// <param name="top">Any $top option for this uri. Can be null.</param>
 /// <param name="queryCount">Any query $count option for this uri. Can be null.</param>
 internal ODataUri(
     ParameterAliasValueAccessor parameterAliasValueAccessor,
     ODataPath path,
     IEnumerable <QueryNode> customQueryOptions,
     SelectExpandClause selectAndExpand,
     FilterClause filter,
     OrderByClause orderby,
     SearchClause search,
     ApplyClause apply,
     long?skip,
     long?top,
     bool?queryCount)
 {
     this.ParameterAliasValueAccessor = parameterAliasValueAccessor;
     this.Path = path;
     this.CustomQueryOptions = new ReadOnlyCollection <QueryNode>(customQueryOptions.ToList());
     this.SelectAndExpand    = selectAndExpand;
     this.Filter             = filter;
     this.OrderBy            = orderby;
     this.Search             = search;
     this.Apply      = apply;
     this.Skip       = skip;
     this.Top        = top;
     this.QueryCount = queryCount;
 }
Пример #3
0
        public void Nested()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleNest>
            {
                new SampleNest
                {
                    Id    = "1",
                    Title = "Nested Test",
                    Items = new List <NestedEntity>
                    {
                        new NestedEntity
                        {
                            Created = new DateTime(2019, 3, 7),
                            Code    = 3,
                            Data    = "item"
                        }
                    }
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleNest>(0, 10);
            var results    = searchData
                             .Must(SearchClause <SampleNest> .Range(x => x.Items, new DateTime(2019, 2, 7), new DateTime(2019, 6, 1), x => x.Items[0].Created))
                             .Must(SearchClause <SampleNest> .Range(x => x.Items, 2, 5, x => x.Items[0].Code))
                             .Must(SearchClause <SampleNest> .Term(x => x.Items, "item", x => x.Items[0].Data))
                             .Execute();
            var actual = results.Documents.ToList();

            Assert.Equal(expected.Count, actual.Count);
        }
Пример #4
0
        /// <summary>
        /// Parse a full Uri into its contingent parts with semantic meaning attached to each part.
        /// See <see cref="ODataUri"/>.
        /// </summary>
        /// <returns>An <see cref="ODataUri"/> representing the full uri.</returns>
        public ODataUri ParseUri()
        {
            ExceptionUtils.CheckArgumentNotNull(this.configuration.Model, "model");
            ExceptionUtils.CheckArgumentNotNull(this.fullUri, "fullUri");

            ODataPath          path         = this.ParsePath();
            SelectExpandClause selectExpand = this.ParseSelectAndExpand();
            FilterClause       filter       = this.ParseFilter();
            OrderByClause      orderBy      = this.ParseOrderBy();
            SearchClause       search       = this.ParseSearch();
            ApplyClause        apply        = this.ParseApply();
            long?  top        = this.ParseTop();
            long?  skip       = this.ParseSkip();
            bool?  count      = this.ParseCount();
            string skipToken  = this.ParseSkipToken();
            string deltaToken = this.ParseDeltaToken();

            // TODO:  check it shouldn't be empty
            List <QueryNode> boundQueryOptions = new List <QueryNode>();

            ODataUri odataUri = new ODataUri(this.ParameterAliasValueAccessor, path, boundQueryOptions, selectExpand, filter, orderBy, search, apply, skip, top, count);

            odataUri.ServiceRoot = this.serviceRoot;
            odataUri.SkipToken   = skipToken;
            odataUri.DeltaToken  = deltaToken;
            return(odataUri);
        }
Пример #5
0
        public Expression BindSearch(SearchClause searchClause, QueryBinderContext context)
        {
            SearchTermNode node = searchClause.Expression as SearchTermNode;
            Expression <Func <OpsTenant, bool> > exp = p => p.Name == node.Text;

            return(exp);
        }
Пример #6
0
        public void LessThan()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleWeight>
            {
                new SampleWeight
                {//0
                    Weight = 100
                },
                new SampleWeight
                {//1
                    Weight = 110
                },
                new SampleWeight
                {//2
                    Weight = 120
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleWeight>(0, 10);
            var results    = searchData
                             .Should(SearchClause <SampleWeight> .LessThan(x => x.Weight, 110))
                             .Sort(x => x.Weight)
                             .Execute();
            var actual = results.Documents.ToList();

            //range
            Assert.Single(actual);
            Assert.Equal(expected[0].Weight, actual[0].Weight);
        }
Пример #7
0
        public void SearchOptionSetCorrectly()
        {
            SearchClause search = new SearchClause(new SearchTermNode("SearchMe"));
            ExpandedNavigationSelectItem expansion = new ExpandedNavigationSelectItem(new ODataExpandPath(new NavigationPropertySegment(ModelBuildingHelpers.BuildValidNavigationProperty(), null)), HardCodedTestModel.GetPeopleSet(), null, null, null, null, null, null, search, null);

            expansion.SearchOption.Expression.ShouldBeSearchTermNode("SearchMe");
        }
Пример #8
0
        public XmlElement GetUnconfirmatedOrders()
        {
            var manager = Extensions.SiteHelper.GetOrderManageContext().PurchaseOrderManager;

            System.Data.DataSet searchableProperties = manager.GetSearchableProperties(CultureInfo.CurrentUICulture.ToString());
            SearchClauseFactory searchClauseFactory  = manager.GetSearchClauseFactory(searchableProperties, "PurchaseOrder");
            SearchClause        clause  = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "Status", "Submitted");
            DataSet             results = manager.SearchPurchaseOrders(clause, new SearchOptions()
            {
                NumberOfRecordsToReturn = 100, PropertiesToReturn = "OrderGroupId,LastModified,SoldToId"
            });

            int c = results.Tables.Count;

            // Get the value of the OrderGroupId property of each
            // purchase order.
            List <Guid> poIds = new List <Guid>();

            foreach (DataRow row in results.Tables[0].Rows)
            {
                poIds.Add(new Guid(row["OrderGroupId"].ToString()));
            }
            // Get the XML representation of the purchase orders.
            return(manager.GetPurchaseOrdersAsXml(poIds.ToArray()));
        }
        private PurchaseOrder GetCsPurchaseOrderByNumber(string controlNumber)
        {
            System.Data.DataSet searchableProperties = Svc.Impl.Helpers.CommerceServerCore.GetPoManager().GetSearchableProperties(System.Globalization.CultureInfo.CurrentUICulture.ToString());
            SearchClauseFactory searchClauseFactory  = Svc.Impl.Helpers.CommerceServerCore.GetPoManager().GetSearchClauseFactory(searchableProperties, "PurchaseOrder");
            SearchClause        trackingNumberClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "TrackingNumber", controlNumber);

            // Create search options.

            SearchOptions options = new SearchOptions();

            options.PropertiesToReturn      = "SoldToId";
            options.SortProperties          = "SoldToId";
            options.NumberOfRecordsToReturn = 1;
            // Perform the search.
            System.Data.DataSet results = Svc.Impl.Helpers.CommerceServerCore.GetPoManager().SearchPurchaseOrders(trackingNumberClause, options);

            if (results.Tables.Count > 0 && results.Tables[0].Rows.Count > 0)
            {
                try {
                    // Enumerate the results of the search.
                    Guid soldToId = Guid.Parse(results.Tables[0].Rows[0].ItemArray[2].ToString());

                    // get the guids for the customers associated users and loop if necessary
                    PurchaseOrder po = Svc.Impl.Helpers.CommerceServerCore.GetOrderContext().GetPurchaseOrder(soldToId, controlNumber);
                    return(po);
                } catch (Exception ex) {
                    _log.WriteWarningLog("Could not locate POs for user's ID. This is not an exception, just a notice.", ex);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        public Guid?GetSoldToIdForPurchaseOrderByInvoice(string poNumber)
        {
            System.Data.DataSet searchableProperties = Svc.Impl.Helpers.CommerceServerCore.GetPoManager().GetSearchableProperties(System.Globalization.CultureInfo.CurrentUICulture.ToString());
            SearchClauseFactory searchClauseFactory  = Svc.Impl.Helpers.CommerceServerCore.GetPoManager().GetSearchClauseFactory(searchableProperties, "PurchaseOrder");
            SearchClause        poCluase             = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "TrackingNumber", poNumber);
            //SearchClause customerClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "CustomerId", customerNumber);
            //SearchClause branchClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "BranchId", branchId);
            //SearchClause invoiceClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "Masternumber", invoiceNumber);
            //SearchClause joinedClause = searchClauseFactory.IntersectClauses(branchClause, invoiceClause);

            // Create search options.
            SearchOptions options = new SearchOptions();

            options.PropertiesToReturn      = "SoldToId";
            options.SortProperties          = "SoldToId";
            options.NumberOfRecordsToReturn = 1;

            // Perform the search.
            System.Data.DataSet results = Svc.Impl.Helpers.CommerceServerCore.GetPoManager().SearchPurchaseOrders(poCluase, options);

            if (results.Tables.Count > 0 && results.Tables[0].Rows.Count > 0)
            {
                // Enumerate the results of the search.
                return(Guid.Parse(results.Tables[0].Rows[0].ItemArray[2].ToString()));
            }
            else
            {
                return(null);
            }
        }
        public Expression BindSearch(SearchClause searchClause, QueryBinderContext context)
        {
            Expression exp = BindSingleValueNode(searchClause.Expression, context);

            LambdaExpression lambdaExp = Expression.Lambda(exp, context.CurrentParameter);

            return(lambdaExp);
        }
Пример #12
0
 /// <summary>Translates a <see cref="SearchClause"/> into a <see cref="SearchClause"/>.</summary>
 /// <param name="searchClause">The search clause to translate.</param>
 /// <returns>The translated String.</returns>
 internal String TranslateSearchClause(SearchClause searchClause)
 {
     Debug.Assert(searchClause != null, "searchClause != null");
     searchFlag = true;
     string searchStr = this.TranslateNode(searchClause.Expression);
     searchFlag = false;
     return searchStr;
 }
Пример #13
0
 private void ValidateSearchClause(SearchClause search, ODataUrlValidationContext validationContext)
 {
     if (search != null)
     {
         ValidateItem(search, validationContext);
         validationContext.ExpressionValidator.ValidateNode(search.Expression);
     }
 }
        /// <summary>Translates a <see cref="SearchClause"/> into a <see cref="SearchClause"/>.</summary>
        /// <param name="searchClause">The search clause to translate.</param>
        /// <returns>The translated string.</returns>
        internal string TranslateSearchClause(SearchClause searchClause)
        {
            this.searchFlag = true;
            string searchStr = this.TranslateNode(searchClause.Expression);

            this.searchFlag = false;
            return(searchStr);
        }
Пример #15
0
        public void SearchOptionSetCorrectly()
        {
            // Arrange & Act
            SearchClause   search = new SearchClause(new SearchTermNode("SearchMe"));
            PathSelectItem select = new PathSelectItem(new ODataSelectPath(), null, null, null, null, null, null, null, search, null);

            // Assert
            Assert.NotNull(select.SearchOption);
            select.SearchOption.Expression.ShouldBeSearchTermNode("SearchMe");
        }
        public Expression BindSearch(SearchClause searchClause, QueryBinderContext context)
        {
            SearchTermNode node = searchClause.Expression as SearchTermNode;

            if (node != null)
            {
                Expression <Func <SearchProduct, bool> > exp = p => p.Category == node.Text;
                return(exp);
            }

            throw new NotImplementedException();
        }
        /// <summary>
        /// Binds the given filter token.
        /// </summary>
        /// <param name="search">The search token to bind.</param>
        /// <returns>A SearchClause with for given Token.</returns>
        internal SearchClause BindSearch(QueryToken search)
        {
            ExceptionUtils.CheckArgumentNotNull(search, "filter");

            QueryNode expressionNode = this.bindMethod(search);

            SingleValueNode expressionResultNode = expressionNode as SingleValueNode;

            SearchClause searchClause = new SearchClause(expressionResultNode);

            return(searchClause);
        }
Пример #18
0
        public void InRange()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleWeight>
            {
                new SampleWeight
                {//0
                    Weight = 100
                },
                new SampleWeight
                {//1
                    Weight = 110
                },
                new SampleWeight
                {//2
                    Weight = 120
                },
                new SampleWeight
                {//3
                    Weight = 130
                },
                new SampleWeight
                {//4
                    Weight = 200
                },
                new SampleWeight
                {//5
                    Weight = 210
                },
                new SampleWeight
                {//6
                    Weight = 220
                },
                new SampleWeight
                {//7
                    Weight = 230
                },
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleWeight>(0, 10);
            var results    = searchData
                             .Should(SearchClause <SampleWeight> .Range(x => x.Weight, 119, 201))
                             .Sort(x => x.Weight)
                             .Execute();
            var actual = results.Documents.ToList();

            //range
            Assert.Equal(3, actual.Count);
            Assert.Equal(expected[2].Weight, actual[0].Weight);
            Assert.Equal(expected[3].Weight, actual[1].Weight);
            Assert.Equal(expected[4].Weight, actual[2].Weight);
        }
Пример #19
0
        /// <summary>
        /// Writes an ODataPath to string
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string ToString(SearchClause node)
        {
            if (node != null)
            {
                return(tabHelper.Prefix + "SearchQueryOption" +
                       tabHelper.Indent(() =>
                                        tabHelper.Prefix + "Expression = " + ToString(node.Expression)
                                        ));
            }

            return(String.Empty);
        }
Пример #20
0
        public Expression BindSearch(SearchClause searchClause, QueryBinderContext context)
        {
            SearchTermNode node = searchClause.Expression as SearchTermNode;

            if (node != null)
            {
                // Lambda expression methods:
                if (_categories.Contains(node.Text))
                {
                    // Be noted: ToLowerInvariant is not enabled/supported in EF Core.
                    // Switch to use "ToLower()" should work in EF Core.
                    Expression <Func <Product, bool> > exp = p => p.Category.ToString().ToLowerInvariant() == node.Text.ToLowerInvariant();
                    return(exp);
                }
                else if (_colors.Contains(node.Text))
                {
                    Expression <Func <Product, bool> > exp = p => p.Color.ToString().ToLowerInvariant() == node.Text.ToLowerInvariant();
                    return(exp);
                }
                else if (context.ElementClrType == typeof(Sale))
                {
                    try
                    {
                        int year = int.Parse(node.Text);
                        Expression <Func <Sale, bool> > exp = s => s.SaleDate.Year == year;
                        return(exp);
                    }
                    catch
                    {
                        return(Expression.Constant(false, typeof(bool)));
                    }
                }

                throw new InvalidOperationException("Unknown search on product or sale!");
            }
            else
            {
                // Linq expression tree methods:
                Expression exp = BindSingleValueNode(searchClause.Expression, context);

                LambdaExpression lambdaExp = Expression.Lambda(exp, context.CurrentParameter);

                return(lambdaExp);
            }
        }
Пример #21
0
        public void DateRange()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleDate>
            {
                new SampleDate
                {//0
                    DocDate = new DateTime(2019, 1, 1)
                },
                new SampleDate
                {//1
                    DocDate = new DateTime(2019, 2, 1)
                },
                new SampleDate
                {//2
                    DocDate = new DateTime(2019, 3, 7)
                },
                new SampleDate
                {//3
                    DocDate = new DateTime(2019, 4, 7)
                },
                new SampleDate
                {//4
                    DocDate = new DateTime(2019, 5, 7)
                },
                new SampleDate
                {//5
                    DocDate = new DateTime(2019, 6, 7)
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleDate>(0, 10);
            var results    = searchData
                             .Should(SearchClause <SampleDate> .Range(x => x.DocDate, new DateTime(2019, 2, 7), new DateTime(2019, 6, 1)))
                             .Sort(x => x.DocDate)
                             .Execute();
            var actual = results.Documents.ToList();

            //range
            Assert.Equal(3, actual.Count);
            Assert.Equal(expected[2].DocDate, actual[0].DocDate);
            Assert.Equal(expected[3].DocDate, actual[1].DocDate);
            Assert.Equal(expected[4].DocDate, actual[2].DocDate);
        }
Пример #22
0
        /// <summary>
        /// Parses the $search.
        /// </summary>
        /// <returns>SearchClause representing $search.</returns>
        public SearchClause ParseSearch()
        {
            if (this.searchClause != null)
            {
                return(this.searchClause);
            }

            string searchQuery;

            if (!this.TryGetQueryOption(UriQueryConstants.SearchQueryOption, out searchQuery) ||
                searchQuery == null)
            {
                return(null);
            }

            this.searchClause = ParseSearchImplementation(searchQuery, this.Configuration);
            return(searchClause);
        }
        public List <PurchaseOrder> GetPurchaseOrdersByStatus(string queryStatus)
        {
            var manager = CommerceServerCore.GetPoManager();

            System.Data.DataSet searchableProperties = manager.GetSearchableProperties(CultureInfo.CurrentUICulture.ToString());
            // set what to search
            SearchClauseFactory searchClauseFactory = manager.GetSearchClauseFactory(searchableProperties, "PurchaseOrder");
            // Get a list of the returnable properties - debug only
            //DataSet ret = manager.GetReturnableProperties("EN");
            //StringBuilder props = new StringBuilder();
            //foreach (DataRow row in ret.Tables[0].Rows)
            //{
            //    if (props.Length > 0) props.Append(",");
            //    props.Append(row.ItemArray[0].ToString());
            //}
            // set what field/value to search for
            SearchClause clause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "Status", queryStatus);
            // set what fields to return
            DataSet results = manager.SearchPurchaseOrders(clause, new SearchOptions()
            {
                NumberOfRecordsToReturn = 100, PropertiesToReturn = "OrderGroupId,TrackingNumber"
            });

            int c = results.Tables.Count;

            List <PurchaseOrder> Pos   = new List <PurchaseOrder>();
            List <string>        poTNs = new List <string>();

            foreach (DataRow row in results.Tables[0].Rows)
            {
                poTNs.Add(row["TrackingNumber"].ToString());
            }
            // Get the XML representation of the purchase orders.
            if (poTNs.Count > 0)
            {
                foreach (string trackingNumber in poTNs)
                {
                    PurchaseOrder po = ReadPurchaseOrderByTrackingNumber(trackingNumber);
                    Pos.Add(po);
                }
            }
            return(Pos);
        }
        protected QuerySearch ParseSearch(SearchClause x)
        {
            if (x == null)
            {
                return(null);
            }
            var res = new ODataSearchParser(x).Parse();

            if (res == null)
            {
                return(null);
            }
            else
            {
                return new QuerySearch {
                           Value = res
                }
            };
        }
        public void CtorSearchQueryOption_GetQueryNodeParsesQuery()
        {
            // Arrange
            ODataQueryContext context = new ODataQueryContext(_model, typeof(int))
            {
                RequestContainer = new MockServiceProvider()
            };

            // Act
            SearchQueryOption search       = new SearchQueryOption("any", context);
            SearchClause      searchClause = search.SearchClause;

            // Assert
            Assert.NotNull(searchClause);

            SearchTermNode searchTermNode = Assert.IsType <SearchTermNode>(searchClause.Expression);

            Assert.Equal(QueryNodeKind.SearchTerm, searchTermNode.Kind);
            Assert.Equal("any", searchTermNode.Text);
        }
Пример #26
0
        public void Indexing()
        {
            IndexManager.PurgeIndexes();
            var expected = new SampleDocument
            {
                Id      = Guid.NewGuid().ToString().Replace("-", ""),
                Content = @"When be draw drew ye. Defective in do recommend suffering. House it seven in spoil tiled court. Sister others marked fat missed did out use. Alteration possession dispatched collecting instrument travelling he or on. Snug give made at spot or late that mr. ",
                Title   = "Defective recommend"
            };

            IndexManager.IndexEntity(expected, true);
            var searchData = new FindRequest <SampleDocument>(0, 10);
            var results    = searchData
                             .Must(SearchClause <SampleDocument> .Term(x => x.Id, expected.Id))
                             .Execute();
            var actual = results.Documents.FirstOrDefault();

            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.Content, actual.Content);
            Assert.Equal(expected.Title, actual.Title);
        }
Пример #27
0
        public void Get()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleDocument>
            {
                new SampleDocument
                {//0
                    Id      = "1",
                    Content = "my content"
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleDocument>(0, 10);
            var results    = searchData
                             .Get(SearchClause <SampleDocument> .Match(x => x.Content, "my"));
            var actual = results.Documents.ToList();

            Assert.Single(actual);
            Assert.Equal(expected[0].Id, actual[0].Id);
        }
Пример #28
0
        public void GeoSearch()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleLocation>
            {
                new SampleLocation
                {
                    Description = "alpha",
                    Location    = new Nest.GeoLocation(38.044842, 23.728171)
                },
                new SampleLocation
                {
                    Description = "beta",
                    Location    = new Nest.GeoLocation(38.045316, 23.725822)
                },
                new SampleLocation
                {
                    Description = "gama",
                    Location    = new Nest.GeoLocation(38.044378, 23.723365)
                },
                new SampleLocation
                {
                    Description = "out",
                    Location    = new Nest.GeoLocation(37.862905, 22.924569)
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleLocation>(0, 10);
            var results    = searchData
                             .Should(SearchClause <SampleLocation> .Distance(x => x.Location, 38.044631, 23.724513, 500))
                             .GeoSort(x => x.Location, 38.044631, 23.724513)
                             .Execute();
            var actual = results.Documents.ToList();

            Assert.Equal(3, actual.Count);
            Assert.Equal(expected[2].Description, actual[0].Description);
            Assert.Equal(expected[1].Description, actual[1].Description);
            Assert.Equal(expected[0].Description, actual[2].Description);
        }
Пример #29
0
        public void Term()
        {
            IndexManager.PurgeIndexes();
            var expected = new List <SampleItem>
            {
                new SampleItem
                {//0
                    Id       = "1",
                    Code     = "A",
                    Sequence = 1
                },
                new SampleItem
                {//1
                    Id       = "2",
                    Code     = "B",
                    Sequence = 2
                }
            };

            IndexManager.BulkInsert(expected);
            var searchData = new FindRequest <SampleItem>(0, 10);
            var results    = searchData
                             .Must(SearchClause <SampleItem> .Term(x => x.Code, "A"))
                             .Execute();
            var actual = results.Documents.ToList();

            Assert.Single(actual);
            Assert.Equal(expected[0].Id, actual[0].Id);

            searchData = new FindRequest <SampleItem>(0, 10);
            results    = searchData
                         .Must(SearchClause <SampleItem> .Term(x => x.Sequence, 2))
                         .Execute();
            actual = results.Documents.ToList();
            Assert.Single(actual);
            Assert.Equal(expected[1].Id, actual[0].Id);
        }
        public List <PurchaseOrder> ReadPurchaseOrderHeadersByCustomerId(Guid customerId)
        {
            var manager = CommerceServerCore.GetPoManager();

            System.Data.DataSet searchableProperties = manager.GetSearchableProperties(CultureInfo.CurrentUICulture.ToString());
            // set what to search
            SearchClauseFactory searchClauseFactory = manager.GetSearchClauseFactory(searchableProperties, "PurchaseOrder");
            // set what field/value to search for
            SearchClause clause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.Equal, "SoldToId", customerId.ToCommerceServerFormat());
            // set what fields to return
            DataSet results = manager.SearchPurchaseOrders(clause,
                                                           new SearchOptions()
            {
                PropertiesToReturn = "OrderGroupId,TrackingNumber,Created"
            });

            List <PurchaseOrder> Pos   = new List <PurchaseOrder>();
            List <string>        poTNs = new List <string>();

            foreach (DataRow row in results.Tables[0].Rows)
            {
                DateTime created = (DateTime)row["Created"];
                if (created > DateTime.Now.AddDays(int.Parse(Configuration.PurchaseOrdersGetLatestHowManyDays) * -1))
                {
                    poTNs.Add(row["TrackingNumber"].ToString());
                }
            }
            if (poTNs.Count > 0)
            {
                foreach (string trackingNumber in poTNs)
                {
                    PurchaseOrder po = ReadPurchaseOrderByTrackingNumber(trackingNumber);
                    Pos.Add(po);
                }
            }
            return(Pos);
        }