Consider the following service interfaces:
public interface IServiceA { void DoSomething(string s); void DoSomething(string s, bool b); } public interface IServiceB { void DoSomething(); }
The implementation of IServiceB depends on IServiceA as follows:
public class ServiceB : IServiceB { private IServiceA _serviceA; public ServiceB(IServiceA serviceA) { _serviceA = serviceA; } public void DoSomething() { _serviceA.DoSomething("Hello", true); } }
Those. the dependency is inserted into the constructor.
Now consider unit test for the DoSomething() method. I want to argue that one of the overloaded DoSomething methods in IServiceA is called, but as a general principle that unit tests should not know too much about the internal actions of the tested method, I want to be an agnostic regarding which of the two overloads is called. Consider the following unit test:
[TestFixture] public class ServiceBTests { [Test] public void DoSomething_CallsServiceA() { var serviceAMock = MockRepository.GenerateMock<IServiceA>(); var service = new ServiceB(serviceAMock); service.DoSomething();
How can I say that either one or the other of these two methods was called?
source share