I’m writing mock unit test code that will Test a class method that downcasts an input argument interface as a concrete class.
Here is the “System Under Test(SUT)” class called CarWrapperFactory:
public class CarWrapperFactory : ICarWrapperFactory { public ICarWrapper CreateCarWrapper(ICarConfigurationWrapper carConfigurationWrapper) { CarConfiguration loggerConfiguration = ((CarConfigurationWrapper)carConfigurationWrapper).GetCarConfigurationAdaptee(); return new CarWrapper(carConfiguration.CreateCar()); } }
In the aforementioned CarWrapperFactory SUT class, there is downcasting code because it invokes a “protected internal” method called GetCarConfigurationAdaptee.
In my NSubstitute-based Mock Unit Test code, I start off with the following:
ICarConfigurationWrapper carConfigurationWrapperMock = Substitute.For<ICarConfigurationWrapper>(); // Fill-in-blank code….how to mock the “protected internal” method called GetCarConfigurationAdaptee ICarWrapperFactory carWrapperFactorySUT = new CarWrapperFactory(); ICarWrapper carWrapper = carWrapperFactorySUT. CreateCarWrapper(carConfigurationWrapperMock);
Could someone please provide code for the “Fill-in-blank” code above?