public async Task<HttpResponseMessage> Update(UriLocationModel uriLocation)
 {
     UriLocationModel model = new UriLocationModel();
     try
     {
         model = await _uriLocationService.UpdateAsync(uriLocation);
     }
     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_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));
        }
        private UriLocation ConvertModelIngredientToEntityIngredient(UriLocationModel ingredientLocation)
        {
            return new UriLocation
            {

                CreateDateTime = ingredientLocation.CreateDateTime,
                CreatedByAuthor = ingredientLocation.CreatedByAuthor,
                Id = ingredientLocation.Id,
                Location = ingredientLocation.Location,
                ModifiedBy = ingredientLocation.ModifiedBy,
                ModifiedDateTime = ingredientLocation.ModifiedDateTime
            };
        }
        public async Task WhenWeDoAGetWithId_WeRetrieve_ASingleUriLocation()
        {
            //Arrange
            int existingUriLocationsId = 3;

            //Act
            UriLocationModel uriLocation = new UriLocationModel();
            var result = await uriLocationsController.GetById(existingUriLocationsId);
            result.TryGetContentValue(out uriLocation);

            //Assert
            Assert.IsNotNull(uriLocation);
            Assert.IsTrue(uriLocation.Id == existingUriLocationsId);
        }              
        public void ADD_GivenAUriLocation_WhenTheUriLocationIsAdded_EnsureThatTheLocationIsAddedToTheDatabase()
        {
            //Arrange
            UriLocationModel newUriLocationModel = new UriLocationModel
            {
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Joe Walsh",
                Location = "www.Recipes.com",
                ModifiedBy = "MaryPoppins",
                ModifiedDateTime = DateTime.Now
            };

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

            //Assert
            Assert.IsInstanceOfType(result, typeof(UriLocationModel));

        }
        public async Task WhenWeDoAPost_WeAddUriLocation_AndWeWantToBeSureThatTheUriLocationIsReturned()
        {
            //Arrange
            UriLocationModel newUriLocationModel = new UriLocationModel
            {
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Joe Walsh",
                Location = "www.Recipes.com",
                ModifiedBy = "MaryPoppins",
                ModifiedDateTime = DateTime.Now
            };

            //Act
            UriLocationModel uriLocations = new UriLocationModel();
            var result = await uriLocationsController.Add(newUriLocationModel);
            result.TryGetContentValue(out uriLocations);

            //Assert
            Assert.IsNotNull(uriLocations);
            Assert.AreEqual(uriLocations.GetType(), typeof(UriLocationModel));
            Assert.IsTrue(uriLocations.Id > 1);
        }
        public async Task WhenWeDoAPut_TheUriLoactionGetsUpdated()
        {
            //Arrange
            IEnumerable<UriLocationModel> uriLocations = new List<UriLocationModel>();

            var locations = await uriLocationsController.GetAll();
            locations.TryGetContentValue(out uriLocations);

            UriLocationModel existingUriLocationModel = new UriLocationModel
            {
                Id = uriLocations.FirstOrDefault().Id, 
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "UPDATED URILOCATIONCONTROLLER TEST",
                Location = "www.Recipes.com",
                ModifiedBy = "MaryPoppins",
                ModifiedDateTime = DateTime.Now
            };

            //Act
            UriLocationModel changedUriLocationModel = new UriLocationModel();
            var result = await uriLocationsController.Update(existingUriLocationModel);
            result.TryGetContentValue(out changedUriLocationModel);

            //Arrange
            Assert.IsTrue(changedUriLocationModel.CreatedByAuthor == existingUriLocationModel.CreatedByAuthor);
            Assert.IsNotNull(changedUriLocationModel);
        }
 public async Task<UriLocationModel> UpdateAsync(UriLocationModel uriLocation)
 {
     return await _uriLocationManager.UpdateAsync(uriLocation);
 }
 public async Task<UriLocationModel> AddAsync(UriLocationModel uriLocation)
 {
     return await _uriLocationManager.AddAsync(uriLocation);
 }
        public void UPDATE_GivenAnExitingUriLocation_UpadateTheLocation()
        {
            //Arrange
            UriLocationModel existingUriLocationModel = new UriLocationModel
            {
                Id = 5,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Sally Harding",
                Location = "www.BBCRecipes3",
                ModifiedBy = "Terry McPherson",
                ModifiedDateTime = DateTime.Now
            };



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

            //Assert
            Assert.IsInstanceOfType(result, typeof(UriLocationModel));
            Assert.IsNotNull(result);
        }