/Atlassian.Jira.Test/MoqExtensions.cs

https://bitbucket.org/yyo/atlassian.net-sdk-v2.0 · C# · 33 lines · 31 code · 2 blank · 0 comment · 1 complexity · 284ef24bdbc53da4f6dc683868dbe55e MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Moq.Language.Flow;
  6. using System.Collections;
  7. namespace Atlassian.Jira.Test
  8. {
  9. public static class MoqExtensions
  10. {
  11. public static void ReturnsInOrder<T, TResult>(this ISetup<T, TResult> setup,
  12. params TResult[] results) where T : class
  13. {
  14. setup.Returns(new Queue<TResult>(results).Dequeue);
  15. }
  16. public static void ReturnsInOrder<T, TResult>(this ISetup<T, TResult> setup,
  17. params object[] results) where T : class
  18. {
  19. var queue = new Queue(results);
  20. setup.Returns(() =>
  21. {
  22. var result = queue.Dequeue();
  23. if (result is Exception)
  24. {
  25. throw result as Exception;
  26. }
  27. return (TResult)result;
  28. });
  29. }
  30. }
  31. }