Guest User

Untitled

a guest
Dec 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public class Adder
  2. {
  3. public virtual int Add(int operand1, int operand2)
  4. {
  5. return operand1 + operand2;
  6. }
  7. }
  8.  
  9. public class AdvancedAdder : Adder
  10. {
  11. }
  12.  
  13. public abstract class AdderUnitTestsBase
  14. {
  15. protected static Adder Adder;
  16.  
  17. [DataTestMethod]
  18. [DataRow(2, 2, 4)]
  19. [DataRow(-1, 2, 1)]
  20. [DataRow(2, -3, -1)]
  21. [DataRow(0, 0, 0)]
  22. public void Add_ReturnsCorrectResult(
  23. int operand1, int operand2, int result)
  24. {
  25. Assert.AreEqual(result, Adder.Add(operand1, operand2));
  26. }
  27. }
  28.  
  29.  
  30. [TestClass]
  31. public class AdderUnitTests : AdderUnitTestsBase
  32. {
  33. [ClassInitialize]
  34. public static void ClassInit(TestContext context)
  35. {
  36. Adder = new Adder();
  37. }
  38. }
  39.  
  40. [TestClass]
  41. public class AdvancedAdderUnitTests : AdderUnitTestsBase
  42. {
  43. [ClassInitialize]
  44. public static void ClassInit(TestContext context)
  45. {
  46. Adder = new AdvancedAdder();
  47. }
  48. }
  49.  
  50. public class AdvancedAdder : Adder
  51. {
  52. public int Add(int operand1, int operand2, int operand3)
  53. {
  54. return operand1 + operand2 + operand3;
  55. }
  56.  
  57. public uint Add(uint operand1, uint operand2)
  58. {
  59. return operand1 + operand2;
  60. }
  61. }
  62.  
  63. public class AdvancedAdder : Adder
  64. {
  65. public override int Add(int operand1, int operand2)
  66. {
  67. return operand1 - operand2;
  68. }
  69. }
  70.  
  71. public void method()
  72. {
  73. switch (this.getType().Name)
  74. {
  75. case "Square":
  76. // do the square thing
  77. break;
  78. case "Rectangle":
  79. // do the rectangle thing
  80. break;
  81. }
  82. }
  83.  
  84. PARENT
  85. ^
  86. |
  87. CHILD
Add Comment
Please, Sign In to add comment