예제 #1
0
        public async Task PostShoeAsync_WhenCalled_AddShoeAndInventoryToDatabase()
        {
            var unitOfWork = new Mock <IUnitOfWork>();

            unitOfWork.Setup(u => u.Shoes.Add(It.IsAny <Shoe>())).Verifiable();
            unitOfWork.Setup(u => u.Inventory.Add(It.IsAny <Inventory>())).Verifiable();
            var controller = new ShoesController(unitOfWork.Object, _mapper);

            var saveShoeResource = new SaveShoeResource
            {
                BrandId = 1,
                Name    = "New Shoe",
                Styles  = new List <int> {
                    1, 2
                },
                Colors = new List <int> {
                    1, 2
                },
                Sizes = new List <int> {
                    1, 2, 3
                }
            };

            await controller.PostShoesAsync(saveShoeResource);

            unitOfWork.Verify(s => s.Shoes.Add(It.IsAny <Shoe>()));
            unitOfWork.Verify(s => s.Inventory.Add(It.IsAny <Inventory>()));
        }
예제 #2
0
        public async Task PostShoeAsync_WhenCalled_ReturnsOk()
        {
            var unitOfWork = new Mock <IUnitOfWork>();

            unitOfWork.Setup(u => u.Shoes.Add(It.IsAny <Shoe>())).Verifiable();
            unitOfWork.Setup(u => u.Inventory.Add(It.IsAny <Inventory>())).Verifiable();
            var controller = new ShoesController(unitOfWork.Object, _mapper);

            var saveShoeResource = new SaveShoeResource
            {
                BrandId = 1,
                Name    = "New Shoe",
                Styles  = new List <int> {
                    1, 2
                },
                Colors = new List <int> {
                    1, 2
                },
                Sizes = new List <int> {
                    1, 2, 3
                }
            };

            var result = await controller.PostShoesAsync(saveShoeResource) as OkObjectResult;

            Assert.IsInstanceOf <OkObjectResult>(result);
        }
예제 #3
0
        public async Task PostShoeAsync_NullPassed_ReturnsBadRequest()
        {
            var unitOfWork = new Mock <IUnitOfWork>();
            var controller = new ShoesController(unitOfWork.Object, _mapper);

            var result = await controller.PostShoesAsync(null);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);
        }
예제 #4
0
        public async Task DeleteShoeAsync_ShoeNotInDatabase_ReturnsNotFound()
        {
            var unitOfWork = new Mock <IUnitOfWork>();

            unitOfWork.Setup(u => u.Shoes.GetShoeAsync(It.IsAny <int>(), false)).Returns(Task.FromResult <Shoe>(null));
            var controller = new ShoesController(unitOfWork.Object, _mapper);

            var result = await controller.DeleteShoeAsync(It.IsAny <int>());

            Assert.IsInstanceOf <NotFoundResult>(result);
        }