I've found a couple of articles about testing protected methods and have written the appropriate code to do so.
However, now I want to test my class, which includes a public abstract method, to ensure, when the abstract method is called in this particular implementation, that one or more protected methods are called. Something like this ...
01.public abstract class MyBaseClass02.{03. protected void Foo(){ /* stuff */ }04. protected void Bar(){ /* stuff */ }05. 06. public abstract void Stuff();07.}08. 09.public class MyClass : MyBaseClass10.{11. public override void Stuff()12. {13. Bar();14. }15.}
In this trivial example I want my test to ensure that Bar() is called.
Can I actually do this?
private void myMethod(string x, string y, out bool isFound, out string result)
Mock.NonPublic.Arrange<int>(mockedClass, "_prop").Returns(5);
Works as long as my private variable is setup like so:
private int _prop {get; set;}
However these:
private int _prop;
or
private int _prop = 5;
get an error attempting to read it.
Thanks in advance,
Mark
MethodUnderTest(MyClass myClass){ myClass.MyMethod(); // Do some other stuff myClass.MyMethod();}[TestMethod]public void MyTest(){ MyClass mockMyClass = Mock.Create<MyClass>(Behaviour.Strict); mockMyClass.Arrange(x=>x.MyMethod()); // Arrange the other stuff mockMyClass.Arrange(x=>x.MyMethod()); MethodUnderTest(mockMyClass);
mockMyClass.AssertAll();}[TestMethod]public void MyTest(){ MyClass mockMyClass = Mock.Create<MyClass>(Behaviour.Strict); mockMyClass.Arrange(x=>x.MyMethod(), 2); // Arrange the other stuff MethodUnderTest(mockMyClass); mockMyClass.AssertAll();
}