Hi
I am using constructor injection pattern to insert my mocks with moq.
So I have something like this in my nunit test
property UserMock
property IService // interface
public void PreSetup()
{
UserMock = new UserMock;
ITaskService = new Service(UserMock.object);
}
now I have a unit test method like this
public void TestSomething()
{
UserMock.Setup(u => u.SomeMethod(It.IsAny<string>()));
}
Now I thought I always would have to do this after.
public void TestSomething()
{
UserMock.Setup(u => u.SomeMethod(It.IsAny<string>()));
ITaskService.User = UserMock.Object
}
It seems I don't have to do this. Like my thinking was the object gets passed into the constructor and what ever is in it gets set into the "User" property in the TaskServiceClass.
So if I come at a later point and add something to a method it would not get set unless I reset the object.
It does not seem to be the case. So what am I not understanding?
Thanks