public bool ValidateAddShopListRecipe(ShopListRecipe shopListRecipe, int shopListId, int recipeId, out string errorMessage) { var result = _repository.GetAllShopListRecipes().Where(slr => slr.ShopListId == shopListId && slr.RecipeId == recipeId); if (result.Any()) { errorMessage = $"There is already an existing ShopListRecipe with shopListId {shopListId} and recipeId {recipeId}"; return(false); } _repository.Add(shopListRecipe); errorMessage = string.Empty; return(true); }
public void ReturnTrue_ValidateAddShopListRecipe(int shopListId, int recipeId) { ShopListRecipe shopListRecipe = new ShopListRecipe { ShopListId = shopListId, RecipeId = recipeId }; _mockRepository.Setup(x => x.GetAllShopListRecipes(0, 0)).Returns(new List <ShopListRecipe> { new ShopListRecipe { ShopListId = 1, RecipeId = 1 } }); bool result = _shopListRecipeService.ValidateAddShopListRecipe(shopListRecipe, shopListId, recipeId, out string errorMessage); _mockRepository.Verify(x => x.Add(shopListRecipe), Times.Once); Assert.True(errorMessage == string.Empty); Assert.True(result); }