예제 #1
0
        public async Task RecommendedStrategyTest()
        {
            var product1 = "Product 1";
            var product2 = "Product 2";
            var product3 = "Product 3";

            var shopperHistories = new List <ShopperHistory>
            {
                new ShopperHistory
                {
                    CustomerId = 1,
                    Products   = new [] { new Product {
                                              Name = product2, Quantity = 1
                                          }, new Product {
                                              Name = product3, Quantity = 1
                                          } }
                },
                new ShopperHistory
                {
                    CustomerId = 2,
                    Products   = new [] { new Product {
                                              Name = product2, Quantity = 1
                                          } }
                }
            };

            var mockResourceProvider = SetupMockResourceProviderWithShoppingHistory(shopperHistories);

            var sortingStrategy = new RecommendedSortingStrategy(mockResourceProvider);

            Assert.AreEqual(SortOption.Recommended, sortingStrategy.GetSortType);

            var testUnsortedProducts = new List <Product>
            {
                new Product {
                    Name = product1
                },
                new Product {
                    Name = product2
                },
                new Product {
                    Name = product3
                }
            };

            var sortedProducts = (await sortingStrategy.GetSortedProducts(testUnsortedProducts)).ToList();

            Assert.AreEqual(testUnsortedProducts.Count, sortedProducts.Count);

            Assert.AreEqual(product2, sortedProducts[0].Name);
            Assert.AreEqual(product3, sortedProducts[1].Name);
            Assert.AreEqual(product1, sortedProducts[2].Name);
        }
예제 #2
0
 public SortingStrategyFactory(
     AscendingSortingStrategy ascendingSortingStrategy,
     DescendingSortingStrategy descendingSortingStrategy,
     HighSortingStrategy highSortingStrategy,
     LowSortingStrategy lowSortingStrategy,
     RecommendedSortingStrategy recommendedSortingStrategy)
 {
     _ascendingSortingStrategy   = ascendingSortingStrategy ?? throw new ArgumentNullException(nameof(ascendingSortingStrategy));
     _descendingSortingStrategy  = descendingSortingStrategy ?? throw new ArgumentNullException(nameof(descendingSortingStrategy));
     _highSortingStrategy        = highSortingStrategy ?? throw new ArgumentNullException(nameof(highSortingStrategy));
     _lowSortingStrategy         = lowSortingStrategy ?? throw new ArgumentNullException(nameof(lowSortingStrategy));
     _recommendedSortingStrategy = recommendedSortingStrategy ?? throw new ArgumentNullException(nameof(recommendedSortingStrategy));
 }