public HttpResponseMessage GetRestaurant( int id ) {
			using ( Repo repo = new Repo() ) {
				ItemResult<Restaurant> result = repo.GetRestaurantById( id );
				string json = JsonConvert.SerializeObject( result, jss );
				HttpResponseMessage msg = Request.CreateResponse( HttpStatusCode.OK, json );
				return msg;
			}
		}
示例#2
0
		public void ModelTest_GetRestaurantById() {
			// add restaurant to guarantee a find
			Restaurant r = new Restaurant() { Name = "Testaurant", City = "butLEr", State = "PA" };
			using ( SuprContext ctx = new SuprContext() ) {
				ctx.Restaurant.Add( r );
				ctx.SaveChanges();
				int id = r.Id;

				// test the repository
				using ( Repo repo = new Repo() ) {
					ItemResult<Restaurant> restaurant = repo.GetRestaurantById( id );
					Assert.IsNotNull( restaurant, "No restaurant with Id = " + restaurant.Item.Id + " found." );
				}

				// delete the created restaurant
				r = ctx.Restaurant.Where( d => d.Id == id ).First();
				ctx.Restaurant.Remove( r );
				ctx.SaveChanges();
			}
		}