public async Task Post_BadRecipe_ExpectError(IngredientType newIngredientType, int statusCodeExpected)
        {
            var response = await _http.PostAsync("api/ingredientType", newIngredientType.GetStringContent());

            Assert.True((int)response.StatusCode == statusCodeExpected, "Status code should be " + statusCodeExpected + " but was " + (int)response.StatusCode);
        }
Beispiel #2
0
        public async Task Post_RecipeIngredient_DifferentType_ExpectRecipe()
        {
            var getAllRecipesResponse = await _http.GetAsync("api/recipe");

            getAllRecipesResponse.EnsureSuccessStatusCode();
            var allRecipes        = JsonConvert.DeserializeObject <Recipe[]>(await getAllRecipesResponse.Content.ReadAsStringAsync());
            var oldRecipe         = allRecipes.First();
            var newIngredientType = new IngredientType {
                Name = "Twinkleberries"
            };
            var newIngredientTypeResponse = await _http.PostAsync("api/ingredienttype", newIngredientType.GetStringContent());

            newIngredientTypeResponse.EnsureSuccessStatusCode();
            var newIngredientTypeWithID = await newIngredientTypeResponse.GetObject <IngredientType>();

            var newIngredient = new Ingredient {
                Weight = 2d, TypeID = newIngredientTypeWithID.ID
            };
            var updatedRecipeResponse = await _http.PostAsync($"api/recipe/{oldRecipe.ID}/ingredients", newIngredient.GetStringContent());

            updatedRecipeResponse.EnsureSuccessStatusCode();
            var updatedRecipe = await updatedRecipeResponse.GetObject <Recipe>();

            Assert.NotNull(updatedRecipe);
            Assert.True(oldRecipe.Ingredients.Count + 1 == updatedRecipe.Ingredients.Count, "Ingredient count should be increased by 1");
            var includesIngredientType = updatedRecipe.Ingredients.SingleOrDefault(i => i.TypeID == newIngredientTypeWithID.ID);

            Assert.False(includesIngredientType == null, "New ingredient should have been added.");
        }