Example #1
0
        public void Should_list_products_with_filters()
        {
            // arrange
            var tablet     = Fixture.Create <Category>();
            var smartPhone = Fixture.Create <Category>();

            var iphone = Fixture.Create <Product>(x => x.Category = smartPhone);
            var galaxy = Fixture.Create <Product>(x => x.Category = smartPhone);
            var ipad   = Fixture.Create <Product>(x => x.Category = tablet);

            SaveAll(tablet, smartPhone, iphone, galaxy, ipad);

            // act
            var query = new ProductList.Query
            {
                Categories = new[] { smartPhone.Id },
                Name       = iphone.Name.Substring(1, 10)
            };

            var result = Send(query);

            // assert
            result.Products.Count().ShouldBe(1);

            result.Products.At(0).Name.ShouldBe(iphone.Name);
            result.Products.At(0).CategoryName.ShouldBe(smartPhone.Name);

            result.Categories.ShouldBe(query.Categories);
            result.Name.ShouldBe(query.Name);
        }
Example #2
0
        public void Should_list_products()
        {
            // arrange
            var iphone   = new Product("iPhone", 599.99m);
            var galaxy   = new Product("Galaxy", 499.49m);
            var motorola = new Product("Motorola", 355.55m);

            using (var db = new DatabaseContext())
            {
                db.Products.Add(iphone);
                db.Products.Add(galaxy);
                db.Products.Add(motorola);

                db.SaveChanges();
            }

            var query  = new ProductList.Query();
            var result = Send(query);

            // assert
            result.Count().ShouldBe(3);
            result.ShouldContain(iphone);
            result.ShouldContain(galaxy);
            result.ShouldContain(motorola);
        }
Example #3
0
        public ActionResult Index(ProductList.Query query)
        {
            var result = _mediator.Send(query);

            return(View(result));
        }