Пример #1
0
        public void Handle_when_valid_auctionPrice_filter_params_returns_valid_auctions_page()
        {
            //arrange
            var stubAuctions = GetFakeAuctionsReadModels();

            stubAuctions[0]
            .ActualPrice = 99;
            foreach (var auction in stubAuctions)
            {
                auction.BuyNowPrice = 0;
            }
            _dbContext.AuctionsReadModel.InsertMany(stubAuctions.AsSpan(0, AuctionsByCategoryQueryHandler.PageSize)
                                                    .ToArray());

            var queryHandler = new AuctionsByCategoryQueryHandler(_dbContext, new CategoryBuilder(_categoryTreeService));
            var query1       = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                },
                MinAuctionPrice = 0,
                MaxAuctionPrice = 40
            };


            var query2 = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                }
                ,
                MinAuctionPrice = 90,
                MaxAuctionPrice = 99
            };

            //act
            var results1 = queryHandler.Handle(query1, CancellationToken.None)
                           .Result;
            var results2 = queryHandler.Handle(query2, CancellationToken.None)
                           .Result;

            //assert
            results1.Auctions.Count().Should()
            .Be(AuctionsByCategoryQueryHandler.PageSize - 1);
            results1.Total.Should().Be(AuctionsByCategoryQueryHandler.PageSize - 1);
            results2.Auctions.Count().Should()
            .Be(1);
            results2.Total.Should().Be(1);
        }
Пример #2
0
        public void Handle_when_given_valid_condition_filter_params_returns_valid_auctions_page()
        {
            //arrange
            var stubAuctions = GetFakeAuctionsReadModels();

            stubAuctions[0]
            .Product.Condition = Condition.New;
            _dbContext.AuctionsReadModel.InsertMany(stubAuctions.AsSpan(0, AuctionsByCategoryQueryHandler.PageSize)
                                                    .ToArray());

            var queryHandler = new AuctionsByCategoryQueryHandler(_dbContext, new CategoryBuilder(_categoryTreeService));
            var query1       = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                },
                ConditionQuery = ConditionQuery.New
            };


            var query2 = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                },
                ConditionQuery = ConditionQuery.Used
            };

            //act
            var results1 = queryHandler.Handle(query1, CancellationToken.None)
                           .Result;
            var results2 = queryHandler.Handle(query2, CancellationToken.None)
                           .Result;

            //assert
            results1.Auctions.Count().Should()
            .Be(1);
            results1.Total.Should().Be(1);
            results2.Auctions.Count().Should()
            .Be(AuctionsByCategoryQueryHandler.PageSize - 1);

            results2.Total.Should()
            .Be(AuctionsByCategoryQueryHandler.PageSize - 1);
        }
Пример #3
0
 public void SetUp()
 {
     _categoryTreeService    = TestDepedencies.Instance.Value.CategoryTreeService;
     _dbContext              = TestDepedencies.Instance.Value.DbContext;
     _byCategoryQueryHandler = new AuctionsByCategoryQueryHandler(_dbContext, new CategoryBuilder(_categoryTreeService));
 }
Пример #4
0
        public void Handle_when_given_valid_type_filter_params_returns_valid_auctions_page()
        {
            //arrange
            var stubAuctions = GetFakeAuctionsReadModels();

            stubAuctions[0]
            .BuyNowOnly = true;
            stubAuctions[1]
            .BuyNowOnly = false;
            stubAuctions[1]
            .BuyNowPrice = 0;
            _dbContext.AuctionsReadModel.InsertMany(stubAuctions.AsSpan(0, AuctionsByCategoryQueryHandler.PageSize)
                                                    .ToArray());

            var queryHandler = new AuctionsByCategoryQueryHandler(_dbContext, new CategoryBuilder(_categoryTreeService));
            var query1       = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                },
                AuctionTypeQuery = AuctionTypeQuery.BuyNowOnly,
            };


            var query2 = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                },
                AuctionTypeQuery = AuctionTypeQuery.Auction,
            };

            var query3 = new AuctionsByCategoryQuery()
            {
                Page          = 0,
                CategoryNames = new List <string>()
                {
                    "Fake category", "Fake subcategory", "Fake subsubcategory 0"
                },
                AuctionTypeQuery = AuctionTypeQuery.AuctionAndBuyNow,
            };

            //act
            var results1 = queryHandler.Handle(query1, CancellationToken.None)
                           .Result;
            var results2 = queryHandler.Handle(query2, CancellationToken.None)
                           .Result;
            var results3 = queryHandler.Handle(query3, CancellationToken.None)
                           .Result;

            //assert
            results1.Auctions.Count().Should()
            .Be(1);
            results1.Total.Should().Be(1);
            results2.Auctions.Count().Should()
            .Be(1);
            results2.Total.Should().Be(1);
            results3.Auctions.Count().Should()
            .Be(AuctionsByCategoryQueryHandler.PageSize - 2);

            results3.Total.Should()
            .Be(AuctionsByCategoryQueryHandler.PageSize - 2);
        }