public async Task<HttpResponseMessage> Update(IngredientModel ingredient)
 {
     
     IngredientModel model = new IngredientModel();
     try
     {
         model = await _ingredientService.UpdateAsync(ingredient);
     }
     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 async Task WhenWeDoAPost_WeAddAnIngredient_AndWeWantToBeSureThatTheIngtredientIsReturned()
        {
            //Arrange

            IngredientModel newIngredientModel = new IngredientModel
            {
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Sally Harding",
                IsNut = true,
                MainIngredient = true,
                ModifiedBy = "Paul Jones",
                ModifiedDateTime = DateTime.Now,
                Name = "Beef",
                UnitOfMeasure = (new UnitOfMeasureModel
                {
                    Amount = 12,
                    CreateDateTime = DateTime.Now,
                    CreatedByAuthor = "Sam Smith",
                    ModifiedBy = "Kat Brogan",
                    ModifiedDateTime = DateTime.Now,
                    UnitType = "Spoons"
                })
            };

            //Act
            IngredientModel ingredient = new IngredientModel();
            var result = await ingredientController.Add(newIngredientModel);
            result.TryGetContentValue(out ingredient);

            //Assert
            Assert.IsNotNull(ingredient);
            Assert.AreEqual(ingredient.GetType(), typeof(RecipeModel));
            Assert.IsTrue(ingredient.Id > 1);
        }
        public void ADD_GivenAnIngredientModel_WhenItIsAdded_EnsureThatItIsAddedToTheDatabse()
        {
            //Arrange
            IngredientModel newIngredientModel = new IngredientModel
            {
                Name = "Eggs",
                IsNut = false,
                MainIngredient = true,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Martin Banks",
                ModifiedBy = "Martin Banks",
                ModifiedDateTime = DateTime.Now
            };

            UriLocationModel newUriLocationModel = new UriLocationModel
            {
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Terry Mcpherson",
                Location = "www.google.co.uk",
                ModifiedBy = "Terry Mcpherson",
                ModifiedDateTime = DateTime.Now
            };


            //Act
            List<UriLocationModel> newUriList = new List<UriLocationModel>();
            newUriList.Add(newUriLocationModel);
            newIngredientModel.IngredientLocations = newUriList;

            var result = manager.Add(newIngredientModel);


            //Assert
            Assert.IsInstanceOfType(result, typeof(IngredientModel));
        }
        [TestCategory("Update"), TestMethod()]//FAILING!!
        public void UPDATE_GivenAnExistingIngredient_UpadateTheName()
        {
            //Arrange
            IngredientModel existingIngredientModel = new IngredientModel
            {
                Id = 1,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Sally Harding",
                IsNut = true,
                MainIngredient = true,
                ModifiedBy = "Terry Mcpherson",
                ModifiedDateTime = DateTime.Now,
                Name = "Avocado"
            };

            //Act
            var result = manager.Update(existingIngredientModel);
            repository.Commit();

            //Assert
            Assert.IsInstanceOfType(result, typeof(IngredientModel));
            Assert.IsNotNull(result);
        }
 public async Task<IngredientModel> UpdateAsync(IngredientModel ingredient)
 {
     return await _ingredientManager.UpdateAsync(ingredient);
 }
 public async Task<IngredientModel> AddAsync(IngredientModel ingredient)
 {
     return await _ingredientManager.AddAsync(ingredient);
 }
        public async Task WhenWeDoAGetWithId_WeRetrieve_ASingleIngredient()
        {
            //Arrange
            int existingIngredientId = 1;


            //Act
            IngredientModel ingredient = new IngredientModel();
            var result = await ingredientController.GetById(existingIngredientId);
            result.TryGetContentValue(out ingredient);

            //Assert
            Assert.IsNotNull(ingredient);
            Assert.IsTrue(ingredient.Id == existingIngredientId);
        }
        public async Task WhenWeDoAPut_TheIngredientGetsUpdated()
        {
            //Arrange
            IngredientModel existingIngredientModel = new IngredientModel
            {
                Id = 5,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "INGREDIENT MODEL UPDATE TEST",
                IsNut = true,
                MainIngredient = true,
                ModifiedBy = "Paul Jones",
                ModifiedDateTime = DateTime.Now,
                Name = "Beef",
                UnitOfMeasure = (new UnitOfMeasureModel
                {
                    Amount = 12,
                    CreateDateTime = DateTime.Now,
                    CreatedByAuthor = "Sam Smith",
                    ModifiedBy = "Kat Brogan",
                    ModifiedDateTime = DateTime.Now,
                    UnitType = "Spoons"
                })
            };

            //Act
            IngredientModel changedIngredientModel;
            var result = await ingredientController.Update(existingIngredientModel);
            result.TryGetContentValue(out changedIngredientModel);

            //Arrange
            Assert.IsTrue(changedIngredientModel.CreatedByAuthor == existingIngredientModel.CreatedByAuthor);
            Assert.IsNotNull(changedIngredientModel);
        }