Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this particular case you are testing controller in isolation from database. ClientService is abstraction over the database, and should be replaced by test double. You injected fake into controller, but still assert real implementation. This makes no sense.</p> <p>Assert the same object, which was injected into controller.</p> <pre><code> interface IClientService { public void GetNumberOfClients(); public IList&lt;Client&gt; GetAllClients(); public void Insert(Client client); } </code></pre> <p>Fake service implementation:</p> <pre><code> class FakeClientService : IClientService { private IList&lt;CLient&gt; rows = new List&lt;CLient&gt;(); public void GetNumberOfClients() { return list.Count; } public IList&lt;Client&gt; GetAllClients() { return list; } public void Insert(Client client) { client.Add(client); } } </code></pre> <p>Test:</p> <pre><code>[Test] public void ClientIsInserted() { ClientController cc = new ClientController(); FakeClientService fakeService = new FakeClientService(); cc.ClientService = fakeService; cc.Create(new FormCollection (){name="John"}); assert.areEqual(1, fakeService.GetNumberOfClients()); assert.areEqual("John", fakeService.GetAllClients()[0].Name); } </code></pre> <p>If you want to check how controller and service work together - create fake for ClientDatabaseClass. It would be like:</p> <pre><code>[Test] public void ClientIsInserted() { ClientController cc = new ClientController(); IClientDatabaseClass databaseFake = new ClientDatabaseClassFake(); ClientService service= new ClientService(); service.Database = databaseFake; cc.ClientService = service; cc.Create(new FormCollection (){name="John"}); assert.areEqual(1, service.GetNumberOfClients()); assert.areEqual("John", service.GetAllClients()[0].Name); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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