MOQ unit test
C#
2
Posts
2
Posters
0
Views
1
Watching
-
Hello, I am writing unit test to a method named methodName for example. The tested class extends another base class. The tested method uses a method that is implemented in the base class, But i want to use Mock in order to Mock this method. How can i do it?
-
Hello, I am writing unit test to a method named methodName for example. The tested class extends another base class. The tested method uses a method that is implemented in the base class, But i want to use Mock in order to Mock this method. How can i do it?
Something like this;
class MyBaseClass { public virtual string methodName() { return "This is base calling"; } } class MyTestedClass: MyBaseClass { public override string methodName() { return "This is the testing value calling"; } } class MyTestedClassMock: MyBaseClass { public override string methodName() { return "Whaahaha, I'm not the real one, just a mock-stand in."; } }
//..in the test-bit
MyBaseClass someObject = new MyTestedClassMock();
// or new MyTestedClass();
MessageBox.Show(someObject.methodName());Bastard Programmer from Hell :suss: