开发者

Using NUnit to test that an IEnumerable was sorted correctly (uses nested sort)

开发者 https://www.devze.com 2023-01-12 15:49 出处:网络
I\'m using MVP with ASP.NET Web Forms. Being a good TDDer, I want to test 开发者_StackOverflowall the important behaviors in my Presenter, including the default sort it applies to the result set retri

I'm using MVP with ASP.NET Web Forms. Being a good TDDer, I want to test 开发者_StackOverflowall the important behaviors in my Presenter, including the default sort it applies to the result set retrieved from the service layer. The Presenter will be applying a nested sort via LINQ to Objects of the style:

public IEnumerable<ViewModel> MyModel{
   get
      {
          return _myService.GetResults().OrderBy(r=>r.PropertyA).ThenBy(r1=>r1.PropertyB);
      }
}

I've looked at the IsOrderedBy extension method described in this SO question, but I'm not sure how to extend it to work with the nested sort I describe above. Ditto for the code posted by Jon Skeet in this SO question.


When unit testing I use to be as explicit as possible. Let your mock service return a list with some items with different values for PropertyA and PropertyB. Then manually sort that list into a "right answer list". Finally compare with .SequenceEqual<>.

0

精彩评论

暂无评论...
验证码 换一张
取 消