public HttpResponseMessage GetReview( string user ) { using ( Repo repo = new Repo() ) { ListResult<Review> result = repo.GetReviewsByUser( user ); string json = JsonConvert.SerializeObject( result, jss ); HttpResponseMessage msg = Request.CreateResponse( HttpStatusCode.OK, json ); return msg; } }
public void ModelTest_GetReviewsByUser() { // add review to guarantee a find Review r = new Review() { RestaurantId = 1, Comments = "This place is supr AWESOME!", Rating = 5, UserId = usr }; using ( SuprContext ctx = new SuprContext() ) { ctx.Review.Add( r ); ctx.SaveChanges(); // test the repository using ( Repo repo = new Repo() ) { ListResult<Review> result = repo.GetReviewsByUser( usr ); Assert.IsNotNull( result.List, "No review found for user " + usr + "." ); } // delete the created review r = ctx.Review.Where( d => d.Id == r.Id ).First(); ctx.Review.Remove( r ); ctx.SaveChanges(); } }