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>())); }
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); }
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); }
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); }