You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to express my SUT as a parameter to my NUnit test case via AutoData. My SUT is an abstract class with virtual methods. The resulting proxy was created via Substitute.For<T>(), which means that methods I invoke on it do not actually call the real code in that abstract class. The solution to this for abstract classes to use Substitute.ForPartsOf<T>() instead.
Example:
publicabstractclassBaseCommand{publicvirtualvoidDoThing(){// Do meaningful things}}
In my test:
[TestFixture]publicclassBaseCommandTest{[Test,AutoMockData]publicasync Task All_directories_are_created(BaseCommandsut){
sut.DoThing();// This does NOT execute code in `BaseCommand.DoThing()`!}}
For completeness, my AutoMockData class is as follows:
Rather than doing this automatically for abstract classes, which likely would be disruptive and break existing tests, perhaps it would be better to introduce a new PartialAttribute or something that can be used like this:
[Partial] BaseCommand sut
This would ultimately result in Substitute.ForPartsOf<T>().
I want to express my SUT as a parameter to my NUnit test case via AutoData. My SUT is an abstract class with virtual methods. The resulting proxy was created via
Substitute.For<T>()
, which means that methods I invoke on it do not actually call the real code in that abstract class. The solution to this for abstract classes to useSubstitute.ForPartsOf<T>()
instead.Example:
In my test:
For completeness, my
AutoMockData
class is as follows:The text was updated successfully, but these errors were encountered: