public void DeleteFromExistingPlan() { var testProduct = new Product() { ProductName = "Product1", Energy = 50, ProductId = 1 }; var dietPlan = new DietPlan() { Id = 1 }; var productInDietPlan = new ProductInDietPlan() { Product = testProduct, Id = testProduct.ProductId }; var productListForDay = new List <ProductInDietPlan>(); productListForDay.Add(productInDietPlan); var dailyDietPlan = new DailyDietPlan() { ProductListForDay = productListForDay }; var dailyDietPlanList = new List <DailyDietPlan>() { dailyDietPlan }; dietPlan.DailyDietPlanList = dailyDietPlanList; var listOfDietPlans = new List <DietPlan>() { dietPlan }; var productFromDB = new ProductInDietPlanDb() { DailyDietPlanId = dietPlan.Id, ProductId = testProduct.ProductId }; var productRepositoryMock = new Mock <IProductRepository>(); productRepositoryMock.Setup(repository => repository.GetProductById(1)).Returns(testProduct); var productInPlanServiceMock = new Mock <IProductInPlanService>(); var dietPlanRepositoryMock = new Mock <IDietPlanRepository>(); dietPlanRepositoryMock.Setup(repository => repository.ListAllDietPlans("DummyId")) .Returns(listOfDietPlans); dietPlanRepositoryMock.Setup(repository => repository.ListDailyDietPlans(1)).Returns(dailyDietPlanList); dietPlanRepositoryMock.Setup(repository => repository.ListDbProductsInDailyDietPlan(dailyDietPlan)).Returns(new List <ProductInDietPlanDb>() { productFromDB }); var sut = new ProductService(productRepositoryMock.Object, dietPlanRepositoryMock.Object, productInPlanServiceMock.Object); sut.DeleteById(testProduct.ProductId, "DummyId"); dietPlanRepositoryMock.Verify(repository => repository.DeleteProductInPlan(productFromDB)); }
public void DeleteProductById_DeleteProductCalledInRepository(int id) { var product = new Product { ProductId = id }; var productRepositoryMock = new Mock <IProductRepository>(); productRepositoryMock.Setup(repository => repository.GetProductById(id)).Returns(product); productRepositoryMock.Setup(repository => repository.DeleteProduct(It.IsAny <Product>())); var dietPlanRepositoryMock = new Mock <IDietPlanRepository>(); dietPlanRepositoryMock.Setup(dietPlanRepo => dietPlanRepo.ListAllDietPlans("DummyId")).Returns(new List <DietPlan>()); var productInPlanServiceMock = new Mock <IProductInPlanService>(); var sut = new ProductService(productRepositoryMock.Object, dietPlanRepositoryMock.Object, productInPlanServiceMock.Object); sut.DeleteById(id, "DummyId"); productRepositoryMock.Verify(repository => repository.DeleteProduct(product)); }