public void TestMealIdReturnsDesignationPassedOnConstructorAsMealID() { string designation = "Stone Soup"; MealType type = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[0]); List <Ingredient> ingredients = new List <Ingredient>(); ingredients.Add(Ingredient.ValueOf(ExistingIngredientsService.ExistingIngredients[0])); List <Descriptor> descriptors = new List <Descriptor>(); descriptors.Add(Descriptor.ValueOf("Calorie", 50, "cal")); List <Allergen> allergens = new List <Allergen>(); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); Meal meal = new Meal(designation, type, ingredients, descriptors, allergens); string mealID = meal.Id().Id; Assert.Equal(designation, mealID); }
public void TestMealDescriptorsReturnsCopyOfDescriptorsPassedOnConstructor() { string designation = "Stone Soup"; MealType type = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[0]); List <Ingredient> ingredients = new List <Ingredient>(); ingredients.Add(Ingredient.ValueOf(ExistingIngredientsService.ExistingIngredients[0])); List <Descriptor> descriptors = new List <Descriptor>(); descriptors.Add(Descriptor.ValueOf("Calorie", 50, "cal")); List <Allergen> allergens = new List <Allergen>(); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); Meal meal = new Meal(designation, type, ingredients, descriptors, allergens); List <Descriptor> mealDescriptors = meal.Descriptors; // now lets add a new descriptor to returned list mealDescriptors.Add(Descriptor.ValueOf("Salt", 50, "g")); List <Descriptor> expectedDescriptors = meal.Descriptors; Assert.NotEqual(expectedDescriptors, mealDescriptors); }
public void MealWithDuplicatedAllergensListElementsThrowsArgumentException() { string designation = "Stone Soup"; MealType type = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[0]); List <Ingredient> ingredients = new List <Ingredient>(); ingredients.Add(Ingredient.ValueOf(ExistingIngredientsService.ExistingIngredients[0])); List <Descriptor> descriptors = new List <Descriptor>(); descriptors.Add(Descriptor.ValueOf("Calorie", 50, "cal")); List <Allergen> allergens = new List <Allergen>(); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); Action newMeal = () => new Meal(designation, type, ingredients, descriptors, allergens); Assert.Throws <ArgumentException>(newMeal); }
public void MealWithDescriptorsWhichQuantitySumIsGreaterThanOneHundredGramsThrowsArgumentException() { string designation = "Stone Soup"; MealType type = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[0]); List <Ingredient> ingredients = new List <Ingredient>(); ingredients.Add(Ingredient.ValueOf(ExistingIngredientsService.ExistingIngredients[0])); List <Descriptor> descriptors = new List <Descriptor>(); descriptors.Add(Descriptor.ValueOf("Salt", 50, "g")); descriptors.Add(Descriptor.ValueOf("Fat", 50.1, "g")); List <Allergen> allergens = new List <Allergen>(); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); Action newMeal = () => new Meal(designation, type, ingredients, descriptors, allergens); Assert.Throws <ArgumentException>(newMeal); }
public void TestMealTypeWithNameThatDoesNotExistsThrowsArgumentException() { string name = "this meal type does not exist"; Action valueOf = () => MealType.ValueOf(name); Assert.Throws <ArgumentException>(valueOf); }
public void TestMealTypeWithNullNameThrowsArgumentNullException() { string name = null; Action valueOf = () => MealType.ValueOf(name); Assert.Throws <ArgumentNullException>(valueOf); }
public void TestMealTypeDoesNotProveEqualityToMealTypeWithDifferentName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType differentMealType = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[1]); Assert.NotEqual(mealType, differentMealType); }
public void TestMealTypeProvesEqualityToMealTypeWithEqualName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType equalMealType = MealType.ValueOf(name); Assert.Equal(mealType, equalMealType); }
public void TestMealTypeDoesNotProveEqualityToDifferentClassObject() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); object differentClassObject = ""; Assert.NotEqual(mealType, differentClassObject); }
public void TestMealTypeNameReturnsStringPassedOnValueOf() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType type = MealType.ValueOf(name); string mealTypeName = type.Name; Assert.Equal(name, mealTypeName); }
public void TestMealTypeHasSameHashCodeAsMealTypeWithEqualName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType equalMealType = MealType.ValueOf(name); int mealTypeHashCode = mealType.GetHashCode(); int equalMealTypeHashCode = equalMealType.GetHashCode(); Assert.Equal(mealTypeHashCode, equalMealTypeHashCode); }
public void TestMealTypeHasDifferentHashCodeAsMealTypeWithEqualName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType differentMealType = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[1]); int mealTypeHashCode = mealType.GetHashCode(); int differentMealTypeHashCode = differentMealType.GetHashCode(); Assert.NotEqual(mealTypeHashCode, differentMealTypeHashCode); }
public IActionResult CreateMeal([FromBody] CreateMealModelView createModelView) { try { string designation = createModelView.Designation; MealType type = MealType.ValueOf(createModelView.Type); List <Ingredient> ingredients = createModelView.Ingredients.Select((ingredient) => Ingredient.ValueOf(ingredient)).ToList(); List <Allergen> allergens = createModelView.Allergens.Select((allergen) => Allergen.ValueOf(allergen)).ToList(); List <Descriptor> descriptors = createModelView.Descriptors.Select((descriptor) => Descriptor.ValueOf(descriptor.Name, descriptor.Quantity, descriptor.QuantityUnit)).ToList(); Meal meal; if (allergens.Count == 0) { meal = new Meal(designation, type, ingredients, descriptors); } else { meal = new Meal(designation, type, ingredients, descriptors, allergens); } meal = factory.MealRepository().Save(meal); GetDetailedMealInformationModelView modelview = new GetDetailedMealInformationModelView(meal); return(Created("api/meals", modelview)); } catch (InvalidOperationException argumentException) { // TODO: Log exception return(BadRequest(new ErrorModelView(argumentException.Message))); } catch (ArgumentException argumentException) { // TODO: Log exception return(BadRequest(new ErrorModelView(argumentException.Message))); } catch (Exception databaseException) { // TODO: Log exception return(StatusCode(500, null)); } }
public void MealThatCompliesWithRulesCompletesSuccessfully() { string designation = "Stone Soup"; MealType type = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[0]); List <Ingredient> ingredients = new List <Ingredient>(); ingredients.Add(Ingredient.ValueOf(ExistingIngredientsService.ExistingIngredients[0])); List <Descriptor> descriptors = new List <Descriptor>(); descriptors.Add(Descriptor.ValueOf("Calorie", 50, "cal")); List <Allergen> allergens = new List <Allergen>(); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); new Meal(designation, type, ingredients, descriptors, allergens); }
public void MealWithNullDescriptorsListThrowsArgumentNullException() { string designation = "Stone Soup"; MealType type = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[0]); List <Ingredient> ingredients = new List <Ingredient>(); ingredients.Add(Ingredient.ValueOf(ExistingIngredientsService.ExistingIngredients[0])); List <Descriptor> descriptors = null; List <Allergen> allergens = new List <Allergen>(); allergens.Add(Allergen.ValueOf(ExistingAllergensService.ExistingAllergens[0])); Action newMeal = () => new Meal(designation, type, ingredients, descriptors, allergens); Assert.Throws <ArgumentNullException>(newMeal); }
public void TestMealTypeWithNameThatExistsCompletesSuccessfully() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType type = MealType.ValueOf(name); }