Beispiel #1
0
        public void BasketsController_RemoveBasketItem()
        {
            //prepare dataset: a product, a basket and a basket item
            var product = new PhotoProduct {
                Name = "Alpha", Id = "42"
            };
            var basket = new Basket {
                Id = "Aruba", Created = DateTime.Now, Modified = DateTime.Now
            };
            var basketItem = basket.Add(product, 1337);

            //prepare the ceremonies: the repo's, services and the controller
            var productRepo = new PhotoProductMemoryRepository();

            productRepo.Add(product);
            var productService = new PhotoProductService(productRepo);

            var repo = new BasketMemoryRepository();

            repo.Add(basket);

            var service = new BasketService(repo, productService);

            var controller = new BasketsController(service, productService);

            //actual test
            var result = controller.RemoveBasketItem("Aruba", basket.Contents[0].Id);

            Assert.IsNotNull(result, "There should be a result.");
            Assert.IsInstanceOfType(result, typeof(OkResult));

            //check result in original basket
            Assert.AreEqual(0, basket.Contents.Count, "There should be no basket items anymore.");
        }
Beispiel #2
0
        public void BasketsController_RemoveBasketItem_InvalidBasket_BadRequest()
        {
            var productService = new PhotoProductService(new PhotoProductMemoryRepository());
            var repo           = new BasketMemoryRepository();
            var service        = new BasketService(repo, productService);

            var controller = new BasketsController(service, productService);

            var result = controller.RemoveBasketItem("Aruba", "XX");

            Assert.IsNotNull(result, "There should be a result.");
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
        }
Beispiel #3
0
        public void BasketsController_RemoveBasketItem_InvalidBasketItemId_NotFound()
        {
            var productService = new PhotoProductService(new PhotoProductMemoryRepository());
            var basket         = new Basket {
                Id = "Aruba", Created = DateTime.Now, Modified = DateTime.Now
            };
            var repo = new BasketMemoryRepository();

            repo.Add(basket);
            var service = new BasketService(repo, productService);

            var controller = new BasketsController(service, productService);

            var result = controller.RemoveBasketItem("Aruba", "XX");

            Assert.IsNotNull(result, "There should be a result.");
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }