public IHttpActionResult GetRevision(long revision) { RevisionDetailViewModel viewModel = null; UnitOfWork unitOfWork = null; try { unitOfWork = new UnitOfWork(); var commitDiff = new SourceControl().GetRevision(revision); var commentQuery = new CommentQuery(unitOfWork.Context.Comments) { Revision = revision }; var comments = commentQuery.Execute(); // merge data to view model efficiently Commit commit = unitOfWork.Context.Commits.FirstOrDefault(c => c.Revision == revision); viewModel = RevisionDetailViewModel.Create(commit, commitDiff, comments); } catch (Exception ex) { System.Diagnostics.Trace.TraceError("GetRevision: " + ex); return(InternalServerError(ex)); } finally { if (unitOfWork != null) { unitOfWork.Dispose(); } } return(Ok(viewModel)); }
public void By_Revision() { using (var database = new DbCodeReview()) { database.Comments.AddRange(new Comment[] { new Comment() { Revision = 1111, LineId = "1212", User = "******", Text = "1111Comment1" }, new Comment() { Revision = 1111, LineId = "1212", User = "******", Text = "1111Comment2" }, new Comment() { Revision = 3333, LineId = "1212", User = "******", Text = "333Comment1" }, new Comment() { Revision = 11111, LineId = "1212", User = "******", Text = "1111Comment1" }, }); database.SaveChanges(); } using (var database = new DbCodeReview()) { var sut = new CommentQuery(database.Comments) { Revision = 1111 }; var result = sut.Execute(); Assert.AreEqual(2, result.Count <Comment>()); Assert.AreEqual(2, result.Where(c => c.Revision == 1111).Count <Comment>()); } }