Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You'll need to do some dependency injection to get your mock into your class-under-test (for more information on DI, check out <a href="http://www.martinfowler.com/articles/injection.html" rel="nofollow">this article</a> by Martin Fowler). First your 'dataComponentService' class will need to implement an interface:</p> <pre><code>public interface IDataComponentService { boolean CheckIfUserExist(String user); } </code></pre> <p>Then you can inject classes that implement that interface into your CustomerService class by adding an appropriate constructor:</p> <pre><code>public class CustomerService { private IDataComponentService _dataComponentService // This constructor allows you to inject your dependency into the class public CustomerService(IDataComponentService dataComponentService) { _dataComponentService = dataComponentService; } Public void Register() { Action1(); Action2(); } private action1 () { //this is a call to other dll. var isExist = _dataComponentService.CheckIfUserExist(userName); } private action2() { //do some more work... // Call to dataComponentService. write some data in the database.... } } </code></pre> <p>Now, in your test code your tests you can create a mock of an IDataComponentService...</p> <pre><code>var dataComponentServiceMock = MockRepository.GenerateMock&lt;IDataComponentService&gt;(); //add mock's behavior here... </code></pre> <p>... and pass it into your class-under-test thus...</p> <pre><code>var objUt = new CustomerService(dataComponentServiceMock); objUt.Register(); // check method calls to the mock here... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload