public async Task<HttpResponseMessage> Update(NutritionalInformationModel nutritionalInformation)
 {
     
     NutritionalInformationModel model = new NutritionalInformationModel();
     try
     {
         model = await _nutritionalInformationService.UpdateAsync(nutritionalInformation);
     }
     catch (HttpRequestException ex)
     {
         Trace.TraceError(ex.Message);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
     }
     catch (WebException we)
     {
         Trace.TraceError(we.Message);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, we.Message);
     }
     catch (SecurityException se)
     {
         Trace.TraceError(se.Message);
         return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Not Authorised to this server!!");
     }
     catch (Exception ex)
     {
         Trace.TraceError(ex.Message);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
     }
     return Request.CreateResponse(HttpStatusCode.OK, model);
 }
        public void ADD_GiveNutritionalInformationModel_WhenTheNutritionalInformationModelIsAddedBe_EnsureThatItIsAddedToTheDatabase()

        {
            //Arrange            
            NutritionalInformationModel newNutritionalInformation = new NutritionalInformationModel
            {
                CreateDateTime = DateTime.Now,
                ModifiedDateTime = DateTime.Now,
                Calories = 3,
                Carbs = 6,
                CreatedByAuthor = "Harry Lowe",
                Fat = 6,
                Fibre = 6,
                Protein = 11,
                Salt = 8,
                ModifiedBy = "Sally Harding",
                Saturates = 12,
                Sugar = 4
            };

            newNutritionalInformation.RecipeModel = new RecipeModel
            {
                CookingTime = new TimeSpan(3, 00, 00),
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Harry Lowe",
                Difficulty =   Recipes.Business.Models.Enums.DifficultyModel.Average,
                Method = "Bake in the oven for as long as possible!",
                ModifiedDateTime = DateTime.Now,
                PreparationTime = new TimeSpan(2, 20, 15),
                Serves = 5,
                Title = "Irish Stew",
                RecipeType = Recipes.Business.Models.Enums.RecipeTypeModel.Side,
                ModifiedBy = "Sally Harding"
            };

            //Act
            var result = manager.Add(newNutritionalInformation);
            repository.Commit();

            //Assert
            Assert.IsInstanceOfType(result, typeof(NutritionalInformationModel));
        }
        public async Task WhenWeDoAPost_WeAddARecipe_AndWeWantToBeSureThatTheRecipeIsReturned()
        {
            //Arrange
            NutritionalInformationModel newNutritionalInformation = new NutritionalInformationModel
            {
                CreateDateTime = DateTime.Now,
                ModifiedDateTime = DateTime.Now,
                Calories = 3,
                Carbs = 6,
                CreatedByAuthor = "NutritionalInformationController Test",
                Fat = 6,
                Fibre = 6,
                Protein = 11,
                Salt = 8,
                Saturates = 9,
                Sugar = 6,
                RecipeModel = new RecipeModel
                {
                    CookingTime = new TimeSpan(3, 00, 00),
                    CreateDateTime = DateTime.Now,
                    CreatedByAuthor = "Harry Lowe",
                    Difficulty = Recipes.Business.Models.Enums.DifficultyModel.Average,
                    Method = "Test for the NutritionalInformationController",
                    ModifiedDateTime = DateTime.Now,
                    PreparationTime = new TimeSpan(2, 20, 15),
                    Serves = 5,
                    Title = "Irish Stew",
                    RecipeType = Recipes.Business.Models.Enums.RecipeTypeModel.Side
                }
            };

            //Act
            NutritionalInformationModel nutritionalInformation = new NutritionalInformationModel();
            var result = await nutritionalInformationController.Add(newNutritionalInformation);
            result.TryGetContentValue(out nutritionalInformation);

            //Assert
            Assert.IsNotNull(nutritionalInformation);
            Assert.AreEqual(nutritionalInformation.GetType(), typeof(NutritionalInformationModel));
            Assert.IsTrue(nutritionalInformation.Id > 1);
        }
        public void TestMethod()
        {
            RecipeModel newRecipe = new RecipeModel
            {
                CookingTime = new TimeSpan(3, 00, 00),
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Terry Mcpherson",
                Difficulty = Recipes.Business.Models.Enums.DifficultyModel.Difficult,
                Method = "1. Whip the cream",
                ModifiedDateTime = DateTime.Now,
                PreparationTime = new TimeSpan(2, 00, 00),
                Serves = 6,
                Title = "Shepherd Pie",
                RecipeType = RecipeTypeModel.Main
            };

            NutritionalInformationModel newNutritionalInfo = new NutritionalInformationModel
            {
                CreateDateTime = DateTime.Now,
                ModifiedDateTime = DateTime.Now,
                Calories = 3,
                Carbs = 6,
                CreatedByAuthor = "Sally Harding",
                Fat = 6,
                Fibre = 6,
                Protein = 11,
                Salt = 8,
            };

            //Act
            newRecipe.NutritionalInformation = newNutritionalInfo;
            var result = recipeManager.Add(newRecipe);

            //Assert
            Assert.IsNotNull(result);
        }
        public async Task WhenWeDoAGetWithId_WeRetrieve_ASingleNUtritionalInformation()
        {
            //Arrange
            int existingNutritionalInformation = 69;


            //Act
            NutritionalInformationModel nutritionalInformation = new NutritionalInformationModel();
            var result = await nutritionalInformationController.GetById(existingNutritionalInformation);
            result.TryGetContentValue(out nutritionalInformation);

            //Assert
            Assert.IsNotNull(nutritionalInformation);
            Assert.IsTrue(nutritionalInformation.Id == existingNutritionalInformation);
        }
        public async Task WhenWeDoAPut_TheNutritionalInformationGetsUpdated()
        {
            //Arrange
            NutritionalInformationModel existingNutritionalInformation = new NutritionalInformationModel
            {
                Id = 1,
                CreateDateTime = DateTime.Now,
                ModifiedDateTime = DateTime.Now,
                Calories = 3,
                Carbs = 6,
                CreatedByAuthor = "UPDATED !!NutritionalInformationController Test",
                Fat = 6,
                Fibre = 6,
                Protein = 11,
                Salt = 8,
                Saturates = 9,
                Sugar = 6,
                RecipeModel = new RecipeModel
                {
                    CookingTime = new TimeSpan(3, 00, 00),
                    CreateDateTime = DateTime.Now,
                    CreatedByAuthor = "Harry Lowe",
                    Difficulty = Recipes.Business.Models.Enums.DifficultyModel.Average,
                    Method = "Test for the NutritionalInformationController",
                    ModifiedDateTime = DateTime.Now,
                    PreparationTime = new TimeSpan(2, 20, 15),
                    Serves = 5,
                    Title = "Irish Stew",
                    RecipeType = Recipes.Business.Models.Enums.RecipeTypeModel.Side
                }
            };

            //Act
            NutritionalInformationModel changedNutritionalInformationModel = new NutritionalInformationModel();
            var result = await nutritionalInformationController.Update(existingNutritionalInformation);
            result.TryGetContentValue(out changedNutritionalInformationModel);

            //Arrange
            Assert.IsTrue(changedNutritionalInformationModel.CreatedByAuthor == existingNutritionalInformation.CreatedByAuthor);
            Assert.IsNotNull(changedNutritionalInformationModel);
        }
 public async Task<NutritionalInformationModel> UpdateAsync(NutritionalInformationModel nutritionalInformation)
 {
     return await _nutritionalInformationManager.UpdateAsync(nutritionalInformation);
 }