Created
October 23, 2011 20:42
-
-
Save motowilliams/1307867 to your computer and use it in GitHub Desktop.
Stupid-Linq-Tricks-Record-Rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void multiple_comment_rollup() | |
{ | |
IEnumerable<RawRecords> rawRecords = GetSampleRows(); | |
const string EXPECTED_COMMENT_42 = "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."; | |
const string EXPECTED_COMMENT_69 = "Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante."; | |
IEnumerable<Comment> actualComments = | |
from ncr in rawRecords | |
group ncr by new { ncr.Id, ncr.Timestamp } | |
into g | |
select new Comment | |
{ | |
CommentId = g.Key.Id, | |
CommentTimestamp = g.Key.Timestamp, | |
CommentText = string.Join("", g.OrderBy(x => x.Sequence).Select(x => x.Comment)) | |
}; | |
//If you have multiple asserts in your normal tests, well you know what will happen | |
Assert.AreEqual(EXPECTED_COMMENT_42, actualComments.Single(x => x.CommentId == 42).CommentText); | |
Assert.AreEqual(EXPECTED_COMMENT_69, actualComments.Single(x => x.CommentId == 69).CommentText); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment