code_junkie

Extend xUnit.NET to use custom code when processing a class and locating test methods

Nov 13th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public class AdditionSpecification
  2. {
  3. static int result;
  4.  
  5. public void Because()
  6. {
  7. result = 2 + 2;
  8. }
  9.  
  10. public void Result_is_non_zero()
  11. {
  12. Assert.True(result <> 0);
  13. }
  14.  
  15. public void Result_is_correct()
  16. {
  17. Assert.Equal(4, result);
  18. }
  19. }
  20.  
  21. public class AdditionFixture : IDisposable
  22. {
  23. public int Because()
  24. {
  25. return 2 + 2;
  26. }
  27.  
  28. public void Dispose()
  29. {
  30. //test tear down code
  31. }
  32. }
  33.  
  34. public class AdditionSpecification : IUseFixture<AdditionFixture>
  35. {
  36. int result;
  37.  
  38. public void SetFixture(AdditionFixture Fixture)
  39. {
  40. result = Fixture.Because();
  41. }
  42.  
  43. [Fact]
  44. public void Result_is_non_zero()
  45. {
  46. Assert.True(result <> 0);
  47. }
  48.  
  49. [Fact]
  50. public void Result_is_correct()
  51. {
  52. Assert.Equal(4, result);
  53. }
  54. }
  55.  
  56. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
  57. public class RunWithMyTestClassCommandAttribute : RunWithAttribute
  58. {
  59. public RunWithMyTestClassCommandAttribute()
  60. : base(typeof(MyTestClassCommand)) {}
  61. }
  62.  
  63. [RunWithMyTestClassCommand]
  64. public class AdditionSpecification
  65. {
  66. static int result;
  67.  
  68. public void Because()
  69. {
  70. result = 2 + 2;
  71. }
  72.  
  73. public void Result_is_non_zero()
  74. {
  75. Assert.True(result <> 0);
  76. }
  77.  
  78. public void Result_is_correct()
  79. {
  80. Assert.Equal(4, result);
  81. }
  82. }
Add Comment
Please, Sign In to add comment