示例#1
0
        public void Can_Add_Ingredient_To_Pantry()
        {
            var mockIngredientsRepos = new Moq.Mock <IIngredientsRepository>();
            var ingredients          = new System.Collections.Generic.List <Ingredient>
            {
                new Ingredient {
                    IngredientID = 14, Name = "Milk"
                },
                new Ingredient {
                    IngredientID = 27, Name = "Eggs"
                }
            };

            mockIngredientsRepos.Setup(x => x.Ingredients)
            .Returns(ingredients.AsQueryable());

            var pantry     = new Pantry();
            var controller = new PantryController(mockIngredientsRepos.Object);


            RedirectToRouteResult result =
                controller.AddToPantry(pantry, 27, "someReturnUrl");

            Assert.AreEqual(1, pantry.Lines.Count);
            Assert.AreEqual("Eggs", pantry.Lines[0].Ingredient.Name);
            Assert.AreEqual(1, pantry.Lines[0].Quantity);

            // Проверить, что посетитель перенаправлен на экран отображения кладовой
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
        }
        public void When_there_are_no_active_items_GetAllForProduct_should_return_the_default()
        {
            Func <int, string, string, StockItem> createStockItem = (id, size, product) =>
                                                                    StockItem.Create(product, size, new DateTime(2011, 2, 20), "*****@*****.**").SetId(id);

            var stockItems = new System.Collections.Generic.List <StockItem>
            {
                createStockItem(1, "-", "Widget"),
                createStockItem(2, "Error", "Widget"),
                createStockItem(3, "s", "Widget"),
                createStockItem(4, "m", "Widget"),
                createStockItem(5, "l", "Widget"),
                createStockItem(6, "-", "Gadget"),
                createStockItem(7, "Large", "Gadget"),
            };

            stockItems[0].Deactivate(new DateTime(2011, 2, 20), "mike");
            stockItems[1].Deactivate(new DateTime(2011, 2, 20), "mike");
            stockItems[2].Deactivate(new DateTime(2011, 2, 20), "mike");
            stockItems[3].Deactivate(new DateTime(2011, 2, 20), "mike");
            stockItems[4].Deactivate(new DateTime(2011, 2, 20), "mike");

            stockItemRepository.GetAllDelegate = () => stockItems.AsQueryable();

            var returnedItems = stockItemService.GetAllForProduct("Widget");

            returnedItems.Count().ShouldEqual(1);
            returnedItems.First().ShouldBeTheSameAs(stockItems[0]);
        }
        public void GetAllForProduct_should_return_active_stockItems_for_product()
        {
            Func<int, string, string, StockItem> createStockItem = (id, size, product) =>
                StockItem.Create(product, size, new DateTime(2011, 2, 20), "*****@*****.**").SetId(id);

            var stockItems = new System.Collections.Generic.List<StockItem>
            {
                createStockItem(1, "-", "Widget"),
                createStockItem(2, "Error", "Widget"),
                createStockItem(3, "s", "Widget"),
                createStockItem(4, "m", "Widget"),
                createStockItem(5, "l", "Widget"),
                createStockItem(6, "-", "Gadget"),
                createStockItem(7, "Large", "Gadget"),
            };

            stockItems[0].Deactivate(new DateTime(2011, 2, 20), "mike");
            stockItems[1].Deactivate(new DateTime(2011, 2, 20), "mike");

            stockItemRepository.GetAllDelegate = () => stockItems.AsQueryable();

            var returnedItems = stockItemService.GetAllForProduct("Widget");

            returnedItems.Count().ShouldEqual(3);
            returnedItems.First().ShouldBeTheSameAs(stockItems[2]);
            returnedItems.Last().ShouldBeTheSameAs(stockItems[4]);
        }
示例#4
0
        public void Can_Add_Product_To_Cart()
        {
            // Arrange: Set up a mock repository with two products
            var mockProductsRepos = new Moq.Mock <IProductsRepository>();
            var products          = new System.Collections.Generic.List <Product> {
                new Product {
                    ProductID = 14, Name = "Much Ado About Nothing"
                },
                new Product {
                    ProductID = 27, Name = "The Comedy of Errors"
                },
            };

            mockProductsRepos.Setup(x => x.Products).Returns(products.AsQueryable());

            var cart       = new Cart();
            var controller = new CartController(mockProductsRepos.Object, null, null);

            // Act: Try adding a product to the cart
            RedirectToRouteResult result = controller.AddToCart(cart, 27, "someReturnUrl");

            // Assert
            Assert.AreEqual(1, cart.Lines.Count);
            Assert.AreEqual("The Comedy of Errors", cart.Lines[0].Product.Name);
            Assert.AreEqual(1, cart.Lines[0].Quantity);
            // Check that the visitor was redirected to the cart display screen
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
        }
示例#5
0
        public CommentBucketViewModel(Comment comment)
            : this()
        {
            //Convert object to known type so we can REUSE SOME CODE maybe - if God loves us.

            var singleComment = Map(comment);

            var commentTree = new System.Collections.Generic.List<usp_CommentTree_Result> { singleComment };
            DisplayTree = commentTree.AsQueryable();
            CommentTree = commentTree;
            Submission = DataCache.Submission.Retrieve(comment.MessageId);
            Subverse = DataCache.Subverse.Retrieve(Submission.Subverse);
        }
示例#6
0
        public CommentBucketViewModel(Comment comment) : this()
        {
            //Convert object to known type so we can REUSE SOME CODE maybe - if God loves us.

            var singleComment = Map(comment);

            var commentTree = new System.Collections.Generic.List <usp_CommentTree_Result> {
                singleComment
            };

            DisplayTree = commentTree.AsQueryable();
            CommentTree = commentTree;
            Submission  = DataCache.Submission.Retrieve(comment.MessageId);
            Subverse    = DataCache.Subverse.Retrieve(Submission.Subverse);
        }