When I debug the code and read the line with the mockLessonplannerAFactory creation I get the error:
Constructor arguments cannot be passed for interface mocks.
var mockSchoolclassCodeService = new Mock<ISchoolclassCodeService>();
var mockDateService = new Mock<IDateService>();
var mockLessonplannerAFactory = new Mock<ILessonplannerAFactory>(mockDateService.Object);
var mockLessonplannerBFactory = new Mock<ILessonplannerBFactory>(mockDateService.Object);
var service = new TimeTableService(mockUnitOfWork.Object, mockLessonplannerAFactory.Object, mockLessonplannerBFactory.Object, mockSchoolclassCodeService.Object);
My TimeTableService accepts instances of an interface type only. But the mockLessonplannerAFactory and BFactory... want in their constructor also an IDateService passed.
What is wrong with my code?
The mock that is created from the interface will have a default constructor because interfaces don't have a constructor. Remember you are mocking the interface not the concrete class.
"But the mockLessonplannerAFactory and BFactory... want in their constructor also an IDateService passed."
They are both mocked from interfaces, so there is no constructor. The mock class will create a default constructor which doesn't need to be passed anything.
What you simply wanted to do...
1)create a normal interface mock.
var mockDateService = new Mock<IDateService>();
2)Do a set up for accepting thing way that you need as constructor parameter.
mockDateService .Setup(s => s.ConstructorParam).Returns(constructorParamValue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With