public void ReturnFoodCategory_WhenPassedNameIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); Guid foodcategoryId = Guid.NewGuid(); string name = "FoodCategoryName"; FoodCategory foodCategory = new FoodCategory() { Id = foodcategoryId, Name = name, FoodType = FoodType.Mushroom, MeasuringUnit = MeasuringUnitType.Kg, }; var collection = new List <FoodCategory>() { foodCategory }; dataMock.Setup(c => c.FoodCategories.All).Returns(() => { return(collection.AsQueryable()); }); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act FoodCategory foodCategoryResult = foodCategoriesService.GetFoodCategoryByName(name); //Assert Assert.AreSame(foodCategory, foodCategoryResult); }
public void CallDataCommitMethodOnce_WhenParameterIngredientIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var quantityInMeasuringUnit = 1.5; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, QuantityInMeasuringUnit = quantityInMeasuringUnit }; var foodCategoryName = "Food Category Name"; var quantityOfAllIngredientsInTheCategory = 0; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, QuantityOfAllCategoryIngredients = quantityOfAllIngredientsInTheCategory }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); //Act foodCategoriesService.AddIngredientQuantityToFoodCategory(ingredient); //Assert dataMock.Verify(x => x.SaveChanges(), Times.Once); }
public void RemoveIngredientsPriceFromFoodCategory() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var ingredientPricePerMeasuringUnit = 1.5m; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, PricePerMeasuringUnit = ingredientPricePerMeasuringUnit }; var foodCategoryName = "Food Category Name"; var costOfAllCategoryIngredients = 1.5m; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, CostOfAllCategoryIngredients = costOfAllCategoryIngredients }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); var expectedResult = 0; //Act foodCategoriesService.RemoveIngredientCostFromFoodCategory(ingredient); //Assert Assert.AreEqual(expectedResult, foodCategory.CostOfAllCategoryIngredients); }
public void CallDataCommitMethodOnce_WhenParameterIngredientIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var ingredientPricePerMeasuringUnit = 1.5m; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, PricePerMeasuringUnit = ingredientPricePerMeasuringUnit }; var foodCategoryName = "Food Category Name"; var costOfAllCategoryIngredients = 0; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, CostOfAllCategoryIngredients = costOfAllCategoryIngredients }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); //Act foodCategoriesService.RemoveIngredientCostFromFoodCategory(ingredient); //Assert dataMock.Verify(x => x.SaveChanges(), Times.Once); }
public void RemoveIngredientsQuantityFromFoodCategory() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); var ingredientId = Guid.NewGuid(); var ingredientName = "Ingredient name"; var quantityInMeasuringUnit = 1.5; var foodCategoryId = Guid.NewGuid(); Ingredient ingredient = new Ingredient() { Id = ingredientId, Name = ingredientName, FoodCategoryId = foodCategoryId, QuantityInMeasuringUnit = quantityInMeasuringUnit }; var foodCategoryName = "Food Category Name"; var quantityOfAllIngredientsInTheCategory = 1.5; FoodCategory foodCategory = new FoodCategory() { Id = foodCategoryId, Name = foodCategoryName, QuantityOfAllCategoryIngredients = quantityOfAllIngredientsInTheCategory }; dataMock.Setup(x => x.FoodCategories.GetById(foodCategoryId)).Returns(foodCategory); //Act foodCategoriesService.RemoveIngredientQuantityFromFoodCategory(ingredient); //Assert Assert.AreEqual(foodCategory.QuantityOfAllCategoryIngredients, 0); }
public void ShouldThrow_WhenGuidIdParameterIsEmpty() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act&Assert Assert.Throws <ArgumentException>(() => foodCategoriesService.GetFoodCategoryById(Guid.Empty)); }
public void Throw_WhenThePassedParameter_Ingredient_IsNull() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); Ingredient ingredient = null; //Act & Assert Assert.Throws <ArgumentNullException>(() => foodCategoriesService.RemoveIngredientCostFromFoodCategory(ingredient)); }
public void Throw_WhenThePassedFoodCategoryIsNull() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); FoodCategory foodCategory = null; //Act & Assert Assert.Throws <ArgumentNullException>(() => foodCategoriesService.AddFoodCategory(foodCategory)); }
public void ShouldThrow_WhenNameParameterIsEmpty() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); string name = string.Empty; //Act&Assert Assert.Throws <ArgumentException>(() => foodCategoriesService.GetFoodCategoryByName(name)); }
public void Throw_WhenThePassedFoodCategoryIsNull() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); dataMock.Setup(x => x.FoodCategories.Update(It.IsAny <FoodCategory>())); //Act & Assert Assert.Throws <ArgumentNullException>(() => foodCategoriesService.EditFoodCategory(null)); }
public void Invoke_TheDataFoodCategoriesRepositoryMethodGetAll_Once() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); dataMock.Setup(x => x.FoodCategories.All); //Act IEnumerable <FoodCategory> foodCategories = foodCategoriesService.GetAllFoodCategories(); //Assert dataMock.Verify(x => x.FoodCategories.All, Times.Once); }
public void ReturnsNull_WhenIdIsValidButThereIsNoSuchFoodCategoryInDatabase() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); Guid foodcategoryId = Guid.NewGuid(); dataMock.Setup(c => c.FoodCategories.GetById(foodcategoryId)).Returns <FoodCategory>(null); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act FoodCategory foodCategoryResult = foodCategoriesService.GetFoodCategoryById(foodcategoryId); //Assert Assert.IsNull(foodCategoryResult); }
public void ReturnNull_WhenDataFoodCategoryReposityMethodGetAll_ReturnsNull() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); dataMock.Setup(c => c.FoodCategories.All).Returns(() => { return(null); }); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act IEnumerable <FoodCategory> foodCategoriesResult = foodCategoriesService.GetAllFoodCategories(); //Assert Assert.IsNull(foodCategoriesResult); }
public void ReturnResultOfCorrectTypeIEnumerableOfFoodCategory() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); dataMock.Setup(c => c.FoodCategories.All).Returns(() => { IEnumerable <FoodCategory> expectedResultCollection = new List <FoodCategory>(); return(expectedResultCollection.AsQueryable()); }); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act IEnumerable <FoodCategory> foodCategoriesResult = foodCategoriesService.GetAllFoodCategories(); //Assert Assert.That(foodCategoriesResult, Is.InstanceOf <IEnumerable <FoodCategory> >()); }
public void ReturnResult_WhenInvokingDataFoodCategoriesRepositoryMethod_GetAll() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); IEnumerable <FoodCategory> expectedResultCollection = new List <FoodCategory>(); dataMock.Setup(c => c.FoodCategories.All).Returns(() => { return(expectedResultCollection.AsQueryable()); }); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act IEnumerable <FoodCategory> foodCategoriesResult = foodCategoriesService.GetAllFoodCategories(); //Assert Assert.That(foodCategoriesResult, Is.EqualTo(expectedResultCollection)); }
public void ReturnNull_WhenPassedArgumentNameIsValidButThereIsNoSuchFoodCategoryInDatabase() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); string name = "FoodCategoryName"; var collection = new List <FoodCategory>(); dataMock.Setup(c => c.FoodCategories.All).Returns(() => { return(collection.AsQueryable()); }); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act FoodCategory foodCategoryResult = foodCategoriesService.GetFoodCategoryByName(name); //Assert Assert.IsNull(foodCategoryResult); }
public void InvokeDataCommitOnce_WhenThePassedArgumentIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); Guid foodcategoryId = Guid.NewGuid(); string name = "FoodCategoryName"; FoodCategory foodCategory = new FoodCategory() { Id = foodcategoryId, Name = name, FoodType = FoodType.Mushroom, MeasuringUnit = MeasuringUnitType.Kg, }; dataMock.Setup(x => x.FoodCategories.Update(foodCategory)); //Act foodCategoriesService.EditFoodCategory(foodCategory); //Assert dataMock.Verify(x => x.SaveChanges(), Times.Once); }
public void InvokeDataFoodCategoryRepositoryMethodUpdateOnce_WhenThePassedFoodCategoryIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); dataMock.Setup(x => x.FoodCategories.Update(It.IsAny <FoodCategory>())); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); Guid foodcategoryId = Guid.NewGuid(); string name = "FoodCategoryName"; FoodCategory foodCategory = new FoodCategory() { Id = foodcategoryId, Name = name, FoodType = FoodType.Mushroom, MeasuringUnit = MeasuringUnitType.Kg, }; //Act foodCategoriesService.EditFoodCategory(foodCategory); //Assert dataMock.Verify(x => x.FoodCategories.Update(foodCategory), Times.Once); }
public void ReturnFoodCategory_WhenIdIsValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); Guid foodcategoryId = Guid.NewGuid(); FoodCategory foodCategory = new FoodCategory() { Id = foodcategoryId, Name = "FoodCategoryName", FoodType = FoodType.Mushroom, MeasuringUnit = MeasuringUnitType.Kg, }; dataMock.Setup(c => c.FoodCategories.GetById(foodcategoryId)).Returns(foodCategory); FoodCategoriesService foodCategoriesService = new FoodCategoriesService(dataMock.Object); //Act FoodCategory foodCategoryResult = foodCategoriesService.GetFoodCategoryById(foodcategoryId); //Assert Assert.AreSame(foodCategory, foodCategoryResult); }