コード例 #1
0
ファイル: BLLTest.cs プロジェクト: mueller04/Cart
        public void WhenAddIsCalledOnHandDecrements()
        {
            var orderItemRepo = new OrderItemRepository();
            List<Product> catalogProducts = new List<Product>()
            {
                new Product(){Name = "cable", OnHand = 5},
                new Product(){Name = "charger", OnHand = 4},
                new Product() {Name = "battery", OnHand = 3}
            };

            //Act
            var message = orderItemRepo.Add("battery", 2, catalogProducts);

            //Assert
            Assert.AreEqual(1, catalogProducts[2].OnHand);
        }
コード例 #2
0
ファイル: BLLTest.cs プロジェクト: mueller04/Cart
        public void WhenAddIsCalledNotEnoughInventoryCausesStringReturn()
        {
            //Arrange
            //var mockOrderItemRepo = new Mock<IOrderItemRepository>();
            var orderItemRepo = new OrderItemRepository();
            List<Product> catalogProducts = new List<Product>()
            {
                new Product(){Name = "cable", OnHand = 5},
                new Product(){Name = "charger", OnHand = 4},
                new Product() {Name = "battery", OnHand = 3}
            };

            //Act
            var message = orderItemRepo.Add("battery", 4, catalogProducts);

            //Assert
            Assert.AreEqual("Not enough inventory.", message);
        }
コード例 #3
0
        public async Task <IActionResult> Create(OrderItem orderItem)
        {
            try
            {
                _repo.Add(orderItem);

                if (await _repo.SaveChangesAsync())
                {
                    return(Ok());
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode
                       (
                           StatusCodes.Status500InternalServerError,
                           "Erro ao inserir as informações do banco de dados\n"
                           + ex.InnerException
                       ));
            }

            return(BadRequest());
        }
コード例 #4
0
ファイル: BLLTest.cs プロジェクト: mueller04/Cart
        public void WhenAddisCalledOnOnlyOneTypeofItemItRestrictsAddPerTheRightOnHand()
        {
            var orderItemRepo = new OrderItemRepository();
            List<Product> catalogProducts = new List<Product>()
            {
                new Product(){Name = "cable", OnHand = 5},
                new Product(){Name = "charger", OnHand = 4},
                new Product() {Name = "battery", OnHand = 3}
            };

            //Act

            var message = orderItemRepo.Add("battery", 1, catalogProducts);
            var messagetwo = orderItemRepo.Add("battery", 1, catalogProducts);
            var messagethree = orderItemRepo.Add("battery", 1, catalogProducts);
            var messagefour = orderItemRepo.Add("battery", 1, catalogProducts);

            //Assert
            Assert.AreEqual(0, catalogProducts[2].OnHand);
            Assert.AreEqual("Not enough inventory.", messagefour);
        }