GroupByExecutionMethodRenderer.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace UnityTest
  5. {
  6. public class GroupByExecutionMethodRenderer : AssertionListRenderer<AssertionComponent.CheckMethod>
  7. {
  8. protected override IEnumerable<IGrouping<AssertionComponent.CheckMethod, AssertionComponent>> GroupResult (IEnumerable<AssertionComponent> assertionComponents)
  9. {
  10. var enumVals = Enum.GetValues (typeof (AssertionComponent.CheckMethod)).Cast<AssertionComponent.CheckMethod> ();
  11. var pairs = new List<CheckFunctionAssertionPair> ();
  12. foreach (var checkMethod in enumVals)
  13. {
  14. var components = assertionComponents.Where (c => (c.checkMethods & checkMethod) == checkMethod);
  15. var componentPairs = components.Select ((a) => new CheckFunctionAssertionPair () {checkMethod = checkMethod, assertionComponent = a});
  16. pairs.AddRange (componentPairs);
  17. }
  18. return pairs.GroupBy (pair => pair.checkMethod,
  19. pair => pair.assertionComponent);
  20. }
  21. private class CheckFunctionAssertionPair
  22. {
  23. public AssertionComponent assertionComponent;
  24. public AssertionComponent.CheckMethod checkMethod;
  25. }
  26. }
  27. }