Пример #1
0
        public async Task AddItemToOrder_ShouldReturnOkObject_IfItemIsNotInBasket()
        {
            var mockRepo      = new Mock <ICustomerRepository>();
            var mockMapper    = new Mock <IMapper>();
            int mockClientId  = 1;
            int mockProductId = 1;

            List <OrderItem> itemsToOrder = new List <OrderItem> {
                new OrderItem(),
                new OrderItem()
            };

            mockRepo.Setup(repo => repo.BookOrderItemsAsync(itemsToOrder)).ReturnsAsync(itemsToOrder);

            var controller = new OrdersController(mockRepo.Object, mockMapper.Object);

            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] {
                new Claim(ClaimTypes.Name, "Just Name"),
                new Claim(ClaimTypes.NameIdentifier, "1")
            }));

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            var res = await controller.AddItemToOrder(mockClientId, mockProductId, itemsToOrder);

            Assert.IsType <OkObjectResult>(res);
        }
Пример #2
0
        public void Add_to_Order_should_throw_expected_exception_if_item_does_not_exist()
        {
            var inputNames = new List <string>()
            {
                "Coca cola"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            Assert.ThrowsException <ArgumentNullException>(() => controller.AddItemToOrder(1, "Rymdpizza"));
        }
Пример #3
0
        public void Add_to_Order_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Fanta"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            controller.AddItemToOrder(1, "Coca cola");
            var actual = controller.Get(1);

            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(2, actual.Items.Count);
            Assert.AreEqual(40, actual.TotalPrice);
        }