I am using Moq and I am sort of new to it. I need to test a private method.
I have 2 assemblies. CustomerTest.dll CustomerBusiness.dll
So CustomerTest dll has a class as follows:
[TestFixture]
public class CustomerTestFixture
{
var customerMock=new Mock<ICustomer>()
customerMock.Protected().Setup<bool>("CanTestPrivateMethod").Returns(true);
etc...
}
CustomerBusiness.dll has
public interface ICustomer
{
void Buy();
}
public class Customer:ICustomer
{
public void Buy()
{
etc...
}
protected virtual bool CanTestPrivateMethod()
{
return true;
}
}
I get the following error
System.ArgumentException : Member ICustomer.CannotTestMethod does not exist.
at Moq.Protected.ProtectedMock`1.ThrowIfMemberMissing(String memberName, MethodInfo method, PropertyInfo property)
at Moq.Protected.ProtectedMock`1.Setup(String methodOrPropertyName, Object[] args)
I have also added [assembly: InternalsVisibleTo("CustomerTest.CustomerTestFixture") but with no difference!
What Am I doing wrong. I know my Interface has not such a method.That is the point as my method must be private.Can you help with an example?