Esempio n. 1
0
        static void Main(string[] args)
        {
            var            helper        = new Helper();
            var            db            = new MyContext();
            var            request       = helper.GenerateQueryRequest();
            ISearchService searchService = new SearchService();
            ISortService   sortService   = new SortService();
            IProjectionMapper <DocumentInfo, DocumentInfoViewModel> projection = new DocumentToViewModelProjectionMapper();
            var predicateBuilder = PredicateBuilder.New <DocumentInfoViewModel>();

            var dt = DateTime.UtcNow.AddMonths(-6);
            Expression <Func <DocumentInfoViewModel, bool> > linqImplementation = predicateBuilder.And(x =>
                                                                                                       !x.Name.Contains("letin") &&
                                                                                                       x.Date > dt &&
                                                                                                       !x.IsDeleted &&
                                                                                                       x.Price > 5 &&
                                                                                                       x.Pages == 2);

            Expression <Func <DocumentInfoViewModel, bool> > searchImplementation = searchService.Filter <DocumentInfoViewModel>(request.Filters);

            var oldWhereImp = db.DocumentInfos.Select(projection.Map()).AsExpandable().Where(linqImplementation);
            var oldSortImp  = oldWhereImp.OrderBy(x => x.Name).ThenByDescending(x => x.Price);
            var oldImp      = oldSortImp.ToList();

            var newWhereImp = db.DocumentInfos.Select(projection.Map()).AsExpandable().Where(searchImplementation);
            var newSortImp  = sortService.Sort(newWhereImp, request.SortBy);
            var newImp      = newSortImp.ToList();

            Console.ReadLine();
        }
        public async Task SortService_ShouldSortByPurchasedQuantities_WhenSortOptionIsRecommended()
        {
            var shopperHistoryJson   = @"[{
                                            'customerId': 23,
                                            'products': [
                                                {
                                                'name': 'Test Product A',
                                                'price': 99.99,
                                                'quantity': 2
                                                },
                                                {
                                                'name': 'Test Product B',
                                                'price': 101.99,
                                                'quantity': 3
                                                },
                                                {
                                                'name': 'Test Product F',
                                                'price': 999999999999,
                                                'quantity': 1
                                                }
                                            ]
                                        }]";
            var shopperHistoryClient = Substitute.For <IShopperHistoryClient>();
            var shopperHistoryData   = JsonConvert.DeserializeObject <IEnumerable <ShopperHistory> >(shopperHistoryJson);

            shopperHistoryClient.GetShopperHistory().Returns(shopperHistoryData);

            var sut            = new SortService(shopperHistoryClient);
            var sortedProducts = await sut.Sort("Recommended", data);

            Assert.AreEqual("Test Product B", sortedProducts.First().Name);
        }
Esempio n. 3
0
        public void Sort_Int_Desc()
        {
            var rnd    = new Random();
            var source = Enumerable.Range(0, 20000)
                         .Select(x => new KeyValuePair <BsonValue, PageAddress>(rnd.Next(1, 30000), PageAddress.Empty))
                         .ToArray();

            var pragmas = new EnginePragmas(null);

            pragmas.Set(Pragmas.COLLATION, Collation.Binary.ToString(), false);

            using (var tempDisk = new SortDisk(_factory, 10 * 8192, pragmas))
                using (var s = new SortService(tempDisk, Query.Descending, pragmas))
                {
                    s.Insert(source);

                    s.Count.Should().Be(20000);
                    s.Containers.Count.Should().Be(3);

                    s.Containers.ElementAt(0).Count.Should().Be(8192);
                    s.Containers.ElementAt(1).Count.Should().Be(8192);
                    s.Containers.ElementAt(2).Count.Should().Be(3616);

                    var output = s.Sort().ToArray();

                    output.Should().Equal(source.OrderByDescending(x => x.Key).ToArray());
                }
        }
Esempio n. 4
0
        public void Sort_String_Asc()
        {
            var source = Enumerable.Range(0, 2000)
                         .Select(x => Guid.NewGuid().ToString())
                         .Select(x => new KeyValuePair <BsonValue, PageAddress>(x, PageAddress.Empty))
                         .ToArray();

            var pragmas = new EnginePragmas(null);

            pragmas.Set("COLLATION", Collation.Binary.ToString(), false);

            using (var tempDisk = new SortDisk(_factory, 10 * 8192, pragmas))
                using (var s = new SortService(tempDisk, Query.Ascending, pragmas))
                {
                    s.Insert(source);

                    s.Count.Should().Be(2000);
                    s.Containers.Count.Should().Be(2);

                    s.Containers.ElementAt(0).Count.Should().Be(1905);
                    s.Containers.ElementAt(1).Count.Should().Be(95);

                    var output = s.Sort().ToArray();

                    output.Should().Equal(source.OrderBy(x => x.Key).ToArray());
                }
        }
Esempio n. 5
0
        public void Sort_Int_Desc()
        {
            var rnd    = new Random();
            var source = Enumerable.Range(0, 20000)
                         .Select(x => new KeyValuePair <BsonValue, PageAddress>(rnd.Next(1, 30000), PageAddress.Empty))
                         .ToArray();


            using (var tempDisk = new SortDisk(_factory, 10 * 8192, false))
                using (var s = new SortService(tempDisk, Query.Descending))
                {
                    s.Insert(source);

                    Assert.AreEqual(20000, s.Count);
                    Assert.AreEqual(3, s.Containers.Count);

                    Assert.AreEqual(8192, s.Containers.ElementAt(0).Count);
                    Assert.AreEqual(8192, s.Containers.ElementAt(1).Count);
                    Assert.AreEqual(3616, s.Containers.ElementAt(2).Count);

                    var output = s.Sort().ToArray();

                    CollectionAssert.AreEqual(source.OrderByDescending(x => x.Key).ToArray(), output);
                }
        }
Esempio n. 6
0
        public void Sort_VariableTest_TestSuccess(string input, string expected)
        {
            var sysUnderTest = new SortService();

            var result = sysUnderTest.Sort(input);

            result.Should().Be(expected);
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            var         basePath    = $"C:\\Users\\{Environment.UserName}\\Downloads";
            FileHandler fileHandler = new FileHandler(basePath);
            SortService sortService = new SortService(fileHandler, basePath);

            sortService.Sort();
        }
        public async Task SortService_ShouldCallShopperHistoryApi_WhenSortOptionIsRecommended()
        {
            var shopperHistoryClient = Substitute.For <IShopperHistoryClient>();

            var sut            = new SortService(shopperHistoryClient);
            var sortedProducts = await sut.Sort("Recommended", data);

            await shopperHistoryClient.Received(1).GetShopperHistory();
        }
        public async Task <string> SortService_ShouldSortByPrice_WhenSortOptionIsLow(string sortOption)
        {
            var shopperHistoryClient = Substitute.For <IShopperHistoryClient>();

            var sut            = new SortService(shopperHistoryClient);
            var sortedProducts = await sut.Sort(sortOption, data);

            return(sortedProducts.First().Name);
        }
Esempio n. 10
0
 public void sortservice_will_update_sort_configuration_lastsortbycolumn_test()
 {
     //given a list
     List<BluRaySummaryInfo> unsortedList = new List<BluRaySummaryInfo>() { new BluRaySummaryInfo() { Eac3ToId = "8)", BluRayTitleInfo = new BluRayTitleInfo() { EpisodeNumber = "8"} }, new BluRaySummaryInfo() { Eac3ToId = "1)",  BluRayTitleInfo = new BluRayTitleInfo() { EpisodeNumber = "1"} },
         new BluRaySummaryInfo() { Eac3ToId = "4)", BluRayTitleInfo = new BluRayTitleInfo() { EpisodeNumber = "4"} } };
     //when i attempt to sort by a column in desc order
     SortConfiguration config = new SortConfiguration() { LastSortByColumnName = string.Empty, SortByColumnName = "EpisodeNumber", SortDirection = EnumSortDirection.Asc };
     ISortService<BluRaySummaryInfo> service = new SortService<BluRaySummaryInfo>(config, unsortedList);
     //list should be ordered by column in desc order
     List<BluRaySummaryInfo> sortedList = service.Sort();
     config.LastSortByColumnName.Should().Be("EpisodeNumber");
 }
        public async Task Sort()
        {
            var products = await _sortService.Sort("Low");

            Assert.IsTrue(products[0].Name == "ProductC");

            products = await _sortService.Sort("High");

            Assert.IsTrue(products[0].Name == "ProductA");

            products = await _sortService.Sort("Ascending");

            Assert.IsTrue(products[0].Name == "ProductA");

            products = await _sortService.Sort("Descending");

            Assert.IsTrue(products[0].Name == "ProductC");

            products = await _sortService.Sort("Recommended");

            Assert.IsTrue(products[0].Name == "ProductB");
        }
Esempio n. 12
0
        public void Sort_String_Asc()
        {
            var source = Enumerable.Range(0, 2000)
                         .Select(x => Guid.NewGuid().ToString())
                         .Select(x => new KeyValuePair <BsonValue, PageAddress>(x, PageAddress.Empty))
                         .ToArray();

            using (var tempDisk = new SortDisk(_factory, 10 * 8192, false))
                using (var s = new SortService(tempDisk, Query.Ascending))
                {
                    s.Insert(source);

                    Assert.AreEqual(2000, s.Count);
                    Assert.AreEqual(2, s.Containers.Count);

                    Assert.AreEqual(1905, s.Containers.ElementAt(0).Count);
                    Assert.AreEqual(95, s.Containers.ElementAt(1).Count);

                    var output = s.Sort().ToArray();

                    CollectionAssert.AreEqual(source.OrderBy(x => x.Key).ToArray(), output);
                }
        }
Esempio n. 13
0
        public void sortservice_will_update_sort_configuration_lastsortbycolumn_test()
        {
            //given a list
            List <BluRaySummaryInfo> unsortedList = new List <BluRaySummaryInfo>()
            {
                new BluRaySummaryInfo()
                {
                    Eac3ToId = "8)", BluRayTitleInfo = new BluRayTitleInfo()
                    {
                        EpisodeNumber = "8"
                    }
                }, new BluRaySummaryInfo()
                {
                    Eac3ToId = "1)", BluRayTitleInfo = new BluRayTitleInfo()
                    {
                        EpisodeNumber = "1"
                    }
                },
                new BluRaySummaryInfo()
                {
                    Eac3ToId = "4)", BluRayTitleInfo = new BluRayTitleInfo()
                    {
                        EpisodeNumber = "4"
                    }
                }
            };
            //when i attempt to sort by a column in desc order
            SortConfiguration config = new SortConfiguration()
            {
                LastSortByColumnName = string.Empty, SortByColumnName = "EpisodeNumber", SortDirection = EnumSortDirection.Asc
            };
            ISortService <BluRaySummaryInfo> service = new SortService <BluRaySummaryInfo>(config, unsortedList);
            //list should be ordered by column in desc order
            List <BluRaySummaryInfo> sortedList = service.Sort();

            config.LastSortByColumnName.Should().Be("EpisodeNumber");
        }
 public async Task <ActionResult <List <ProductModel> > > SortProducts(string sortOption)
 {
     return(await _service.Sort(sortOption));
 }