Reputation: 3428
I am new with using Moq and having some logical Problems atm.
I've a class with two Methods an in that Class Method One Calls Method two like:
public class TestClass
{
public virtual string FindUser(string user)
{
//do some Stuff
string check = UserCheck("some string to check");
//do some stuff
return "some other userstring";
}
protected virtual string UserCheck(string blubb)
{
//do some other stuff
return "some string";
}
}
sometimes I swap out some Functionality to other Functions to encapsulate some Functionality in the same class.
I don't know how to Unit test this with Moq, because I need to Moq my own class what I am testing. I've found this as an "solution",
but thats no Solution for me (I think) because, I try to encapsulate some Functionality in just an other Function. Is that wrong what I am doing or did I have to create a new class everytime to encapsulate one Function?
Upvotes: 0
Views: 208
Reputation: 38468
If your implementation does not use another class inside the method call, there is probably no need to use a mock. It doesn't make sense to mock the implementation (event some part of it) you are testing. If you think it is getting too complex, encapsulate some parts of it inside another class and use it as a dependency.
Upvotes: 1
Reputation: 5773
You're doing it wrong. You should not moq your SUT beacause doing so you get things more complex and don't test the right thing. You should using moq (or any other mocking framework) to mock the collaborator of you SUT.
So in your case you can test FindUser without mocking UserCheck...since that method is needed to complete the functionality.
HTH
Upvotes: 0