Exemplo n.º 1
0
        private void CreateCatalogGraf()
        {
            var client         = GetCatalogRepository();
            var catalogBuilder = CatalogBuilder.BuildCatalog("Test catalog").WithCategory("category").WithProducts(2);
            var catalog        = catalogBuilder.GetCatalog();
            var items          = catalogBuilder.GetItems();

            client.Add(catalog);

            foreach (var item in items)
            {
                client.Add(item);
            }

            client.UnitOfWork.Commit();
        }
        public void Can_query_catalog_items()
        {
            var repository = GetRepository();

            var          items     = new Item[] { };
            const string catalogId = "testCatalog";

            var catalogBuilder = CatalogBuilder.BuildCatalog(catalogId).WithCategory("category").WithProducts(200);

            for (int i = 0; i < 10; i++)
            {
                catalogBuilder = catalogBuilder.WithCategory("category " + i, "code-" + i);
            }
            var catalog = catalogBuilder.GetCatalog();

            items = catalogBuilder.GetItems();

            repository.Add(catalog);
            foreach (var item in items)
            {
                repository.Add(item);
            }

            repository.UnitOfWork.Commit();

            RefreshRepository(ref repository);

            var beginTime = DateTime.Now;
            var query     = repository.Items.Where(i => i.CategoryItemRelations.Any(x => x.CatalogId == catalogId || x.Category.LinkedCategories.Any(y => y.CatalogId == catalogId)));

            var overallCount = query.Count();
            var orderedItems = query.OrderBy(x => x.ItemId);

            items = orderedItems.Skip(0).Take(25).ToList().ToArray();

            var queryTime = DateTime.Now - beginTime;

            Assert.True(queryTime < new TimeSpan(0, 0, 1, 2));
        }