public void Two_Of_The_Same_Book_Should_Locate_No_Discounts()
        {
            var cart    = new Cart();
            var repo    = new DiscountSpecificationRepository();
            var locator = new DiscountLocator(repo);

            cart.AddBook(new Book("", 8));
            cart.AddBook(new Book("", 8));

            IEnumerable <IDiscount> discounts = locator.GetDiscountsFor(cart.Books);

            discounts.Count().ShouldEqual(0);
        }
        public void Two_Different_Books_Should_Locate_One_Discount()
        {
            var cart    = new Cart();
            var repo    = new DiscountSpecificationRepository();
            var locator = new DiscountLocator(repo);

            cart.AddBook(new Book("Book 1", 8));
            cart.AddBook(new Book("Book 2", 8));

            IEnumerable <IDiscount> discounts = locator.GetDiscountsFor(cart.Books);

            discounts.Count().ShouldEqual(1);
        }
Exemplo n.º 3
0
        public void When_Calculating_The_Price_Of_Two_Books_Price_Should_Be_The_Sum_Of_Books_Price()
        {
            var cart       = new Cart();
            var discounter = MockRepository.GenerateStub <IDiscounter>();

            discounter.Expect(x => x.ApplyDiscounts(null)).IgnoreArguments().Return(cart.Books);
            var item     = new PriceCalculator(discounter);
            int expected = 20;

            cart.AddBook(new Book("", 10));
            cart.AddBook(new Book("", 10));
            decimal actual = item.CalculatePriceFor(cart);

            actual.ShouldEqual(expected);
        }
        public async Task SubmitOrder_CreatesAnOrderSuccessfully()
        {
            // Set up data through the back door
            var book1 = new Book(
                BookGenre.Detective,
                "No Orchids for Miss Blandish",
                "James Hadley Chase",
                10m);
            var book2 = new Book(
                BookGenre.Detective,
                "Come Easy – Go Easy",
                "James Hadley Chase",
                15m);
            var cart = new Cart(book1, null);

            cart.AddBook(book2);
            DbContext.Add(cart);
            await DbContext.SaveChangesAsync();

            // Set up data through the front door
            // Nothing here, did everything through the back door :)

            // Build inputs
            var command = new SubmitOrderCommand
            {
                CartId      = cart.Id,
                PhoneNumber = "+375291234567"
            };

            // Send inputs to system
            var actualOrder = await Client.SubmitOrder(command);

            // Verify direct outputs
            actualOrder.Id.Should().NotBeEmpty();
            var expectedOrder = new OrderModel
            {
                Id          = actualOrder.Id,
                PhoneNumber = command.PhoneNumber,
                Lines       = cart.Books.Select(book => new OrderLineModel
                {
                    Book = new BookModel
                    {
                        Id     = book.Id,
                        Author = book.Author,
                        Genre  = book.Genre,
                        Price  = book.Price,
                        Title  = book.Title
                    },
                    Price = book.Price
                }).ToList()
            };

            actualOrder.Should().BeEquivalentTo(expectedOrder);

            // Verify side-effects
            cart = DbContext.Carts.SingleOrDefault(x => x.Id == cart.Id);
            cart.Should().BeNull("cart should be deleted after order is submitted");
        }
Exemplo n.º 5
0
        public void Adding_A_Book_To_A_Cart_Should_Add_Book_To_Books_Collection()
        {
            var book = new Book("", 0);
            var cart = new Cart();

            cart.AddBook(book);

            cart.Books.First().ShouldEqual(book);
        }
Exemplo n.º 6
0
        public PartialViewResult AddToCart(Cart cart, int bookId)
        {
            Book book = repository.Books.FirstOrDefault(x => x.BookId == bookId);

            if (book != null)
            {
                cart.AddBook(book, 1);
            }
            return(PartialView("CartInfo", cart));
        }
Exemplo n.º 7
0
        public IActionResult OnPost(long bookId, string returnurl)
        {
            Book book = repository.books.FirstOrDefault(b => b.BookId == bookId);

            // Cart = HttpContext.Session.GetJson<Cart>("cart") ?? new Cart();

            Cart.AddBook(book, 1);

            // HttpContext.Session.SetJson("cart", Cart);

            return(RedirectToPage(new { ReturnUrl = returnurl }));
        }