Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. public abstract class Example
  2. {
  3. public abstract string Foo();
  4.  
  5. public List<string> Bar()
  6. {
  7. PreMethod();
  8.  
  9. var list = new List<string>();
  10.  
  11. var stack = new Stack<string>();
  12. foreach (var item in Stuff)
  13. {
  14. stack.Push(item);
  15. }
  16.  
  17. while (stack.Any())
  18. {
  19. SomeThing = stack.Pop();
  20. var f = Foo();
  21. list.Add(f);
  22. }
  23.  
  24. PostMethod();
  25. return list;
  26. }
  27.  
  28. public abstract void PreMethod();
  29.  
  30. public abstract void PostMethod();
  31.  
  32. public abstract IEnumerable<string> Stuff { get; }
  33.  
  34. public abstract string SomeThing { set; get; }
  35. }
  36.  
  37. [TestClass]
  38. public class ExampleTest
  39. {
  40. private Example example;
  41.  
  42. private MockRepository mocks;
  43.  
  44. [TestInitialize]
  45. public void InitializeTest()
  46. {
  47. mocks = new MockRepository();
  48. example = MockRepository.GeneratePartialMock<Example>();
  49. }
  50.  
  51. [TestMethod]
  52. public void BarTest()
  53. {
  54. using (mocks.Ordered())
  55. {
  56. example.Expect(e => e.PreMethod());
  57. example.Expect(e => e.Stuff).Return(new[] { "One", "Two" });
  58.  
  59. using (mocks.Unordered())
  60. {
  61. using (mocks.Ordered())
  62. {
  63. example.Expect(e => e.SomeThing).SetPropertyWithArgument("One");
  64. example.Expect(e => e.Foo()).Return("one");
  65. }
  66.  
  67. using (mocks.Ordered())
  68. {
  69. example.Expect(e => e.SomeThing).SetPropertyWithArgument("Two");
  70. example.Expect(e => e.Foo()).Return("two");
  71. }
  72. }
  73.  
  74.  
  75. example.Expect(e => e.PostMethod());
  76. }
  77.  
  78. mocks.ReplayAll();
  79.  
  80.  
  81. var actual = example.Bar();
  82. Assert.AreEqual(2, actual.Count);
  83. Assert.AreEqual("two", actual[0]);
  84. Assert.AreEqual("one", actual[1]);
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement