Created
April 23, 2011 12:50
-
-
Save johnnonolan/938579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class AbstractTestBaseClass | |
| { | |
| protected MyAbstractClass AbstractedVariable; | |
| [Fact] | |
| public void Should_return_correct_message() | |
| { | |
| var result= AbstractedVariable.MyMethodOnAbstractClass("input"); | |
| Assert.Equal("I like input in an abstract sense.", result); | |
| } | |
| } | |
| public class TestingAConcreteClass :AbstractTestBaseClass | |
| { | |
| MyConcreteClass ConcreteclassUnderTest; | |
| public TestingAConcreteClass() | |
| { | |
| AbstractedVariable = new MyConcreteClass(); | |
| ConcreteclassUnderTest = new MyConcreteClass(); | |
| } | |
| [Fact] | |
| public void Should_say_Hello() | |
| { | |
| //this is less than ideal as we need to cast to concrete class each time | |
| var result = ((MyConcreteClass) AbstractedVariable).SayHello(); | |
| Assert.Equal("Hello", result); | |
| } | |
| [Fact] | |
| public void StillShould_say_Hello() | |
| { | |
| //this is better although in constructor we still have | |
| //to construct a variable for the abstract tests. | |
| var result = ConcreteclassUnderTest.SayHello(); | |
| Assert.Equal("Hello", result); | |
| } | |
| } | |
| public class MyConcreteClass : MyAbstractClass | |
| { | |
| public string SayHello() | |
| { | |
| return "Hello"; | |
| } | |
| } | |
| public class MyAbstractClass | |
| { | |
| public string MyMethodOnAbstractClass(string input) | |
| { | |
| return "I like " + input + " in an abstract sense."; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment