0

I have an instantiation in constructor in test:

public class Car{

public string Method()
{
 return "test";
}
}

private readonly ICar _classUnderTest;
    public CarTests()
    {
        var collaboratingClass = new CollaboratingClass();
        _classUnderTest = new Car(collaboratingClass );
    }

If I use moq and pass mock instance like this:

    var collaboratingClass = new Mock<ICollaboratingClass>();
    _classUnderTest = new Car(collaboratingClass .Object);

...then I can't call method. The method from this mocked instance is not being called, so I can't use it for calculation. How can I make my mock object to be able to access method and do operation with mock object?

As you can see I don't want to have concrete dependencies here.

sensei
  • 7,044
  • 10
  • 57
  • 125
  • Possible duplicate of [Moq fake one method but use real implementation of another](http://stackoverflow.com/questions/19054563/moq-fake-one-method-but-use-real-implementation-of-another) – Danieboy Oct 18 '16 at 13:21
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask](http://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – Nkosi Oct 18 '16 at 13:32

1 Answers1

0

You can fake a return to your mocked class method. If you need the behavior from your dependency, it's no longer a unit test

Rafael Marques
  • 1,501
  • 15
  • 23