Example #1
0
        public void Execute_ForProductByPriceAndCategoriesAndRating_Succeeds()
        {
            var catalogService = new CatalogService();

            decimal minPrice = 500M;
            decimal maxPrice = 1000M;
            int minRating = 93;
            int maxRating = 96;

            Catalog catalog = catalogService
                .State("CA")
                .PriceFilter(minPrice, maxPrice)
                .CategoriesFilter(124, 7155)
                .RatingFilter(minRating, maxRating)
                .SortBy(SortOptions.Price, SortDirection.Descending)
                .SortBy(SortOptions.Rating, SortDirection.Descending)
                .Execute();

            Assert.That(catalog, Is.Not.Null);
            Assert.That(catalog.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(catalog.Status.Messages, Has.Length.EqualTo(0));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Retail != null ? p.Retail.Price >= minPrice : true));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Retail != null ? p.Retail.Price <= maxPrice : true));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Ratings.HighestScore >= minRating));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Ratings.HighestScore <= maxRating));
        }
Example #2
0
        public void Execute_ForComplexProductQuery_Succeeds()
        {
            var catalogService = new CatalogService();

            decimal minPrice = 100M;
            decimal maxPrice = 200M;

            Catalog catalog = catalogService
                .State("CA")
                .PriceFilter(minPrice, maxPrice)
                .SortBy(SortOptions.Price, SortDirection.Descending)
                .InStock()
                .Offset(10)
                .Size(5)
                .Execute();

            Assert.That(catalog, Is.Not.Null);
            Assert.That(catalog.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(catalog.Status.Messages, Has.Length.EqualTo(0));
            Assert.That(catalog.Products.Offset, Is.EqualTo(10));
            Assert.That(catalog.Products.List, Has.Length.EqualTo(5));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Retail != null ? p.Retail.Price >= minPrice : true));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Retail != null ? p.Retail.Price <= maxPrice : true));
            Assert.That(catalog.Products.List, Is.All.Matches<Product>(p => p.Retail != null ? p.Retail.InStock : true));
            // ordered descending
        }
Example #3
0
        public void Execute_MerlotNapaValleyProducts_Succeeds()
        {
            var stubUrlInvoker = MockRepository.GenerateStub<IUrlInvoker>();

            stubUrlInvoker.Stub(stub => stub.InvokeUrl(string.Empty))
                .IgnoreArguments()
                .Return(Utils.GetTestData("MerlotNapaValleyProducts"));

            var catalogService = new CatalogService();
            catalogService.UrlInvoker = stubUrlInvoker;

            Catalog catalog = catalogService.CategoriesFilter(138, 2398).Execute();

            stubUrlInvoker.AssertWasCalled(
                stub => stub.InvokeUrl(
                    Arg<string>.Matches(url => url.Contains("categories(138+2398)"))));

            Assert.That(catalog, Is.Not.Null);
            Assert.That(catalog.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(catalog.Status.Messages, Has.Length.EqualTo(0));

            Assert.That(catalog.Products, Is.Not.Null);
            Assert.That(catalog.Products.List, Has.Length.EqualTo(10));

            Assert.That(catalog.Products.List[0].Id, Is.EqualTo(108074));
            Assert.That(catalog.Products.List[0].Name, Is.EqualTo("Duckhorn Napa Merlot 2008"));
            Assert.That(catalog.Products.List[0].Appellation.Id, Is.EqualTo(2398));
            Assert.That(catalog.Products.List[0].Appellation.Name, Is.EqualTo("Napa Valley"));
            Assert.That(catalog.Products.List[0].Appellation.Region.Id, Is.EqualTo(101));
            Assert.That(catalog.Products.List[0].Appellation.Region.Name, Is.EqualTo("California"));
            Assert.That(catalog.Products.List[0].Appellation.Region.Area, Is.Null);
        }
Example #4
0
        public void Execute_SearchForOneThing_Succeeds()
        {
            var catalogService = new CatalogService();

            Catalog catalog = catalogService
                .Search("Merlot")
                .Execute();

            Assert.That(catalog, Is.Not.Null);
            Assert.That(catalog.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(catalog.Status.Messages, Has.Length.EqualTo(0));
        }
Example #5
0
        public void Execute_WithProductFilterForOneSpecificProduct_Succeeds()
        {
            var catalogService = new CatalogService();

            Catalog catalog = catalogService.ProductFilter(95457).Execute();

            Assert.That(catalog, Is.Not.Null);
            Assert.That(catalog.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(catalog.Status.Messages, Has.Length.EqualTo(0));
        }
Example #6
0
        public void Execute_SortingByPriceDescending_Succeeds()
        {
            var catalogService = new CatalogService();

            Catalog catalog = catalogService
                .State("CA")
                .Search("Merlot")
                .SortBy(SortOptions.Price, SortDirection.Descending)
                .Execute();

            Assert.That(catalog, Is.Not.Null);
            Assert.That(catalog.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(catalog.Status.Messages, Has.Length.EqualTo(0));
        }
Example #7
0
        private Products LoadNextChunkOfProducts(int offset, int size)
        {
            var catalogService = new CatalogService();

            var categories = new List<int>();

            if (SelectedWineType != null && SelectedWineType.Id != FAUX_CATEGORY_NO_SELECTION) {
                categories.Add(SelectedWineType.Id);
            }

            if (SelectedVarietal != null && SelectedVarietal.Id != FAUX_CATEGORY_NO_SELECTION) {
                categories.Add(SelectedVarietal.Id);
            }

            if (SelectedRegion != null && SelectedRegion.Id != FAUX_CATEGORY_NO_SELECTION) {
                categories.Add(SelectedRegion.Id);
            }

            if (SelectedAppellation != null && SelectedAppellation.Id != FAUX_CATEGORY_NO_SELECTION) {
                categories.Add(SelectedAppellation.Id);
            }

            var catalog = catalogService
                .CategoriesFilter(categories.ToArray())
                .SortBy(_selectedSearchSortOption.SortOption, _selectedSearchSortOption.SortDirection)
                .State("CA")
                .InStock()
                .Offset(offset)
                .Size(size)
                .Execute();

            return catalog.Products;
        }