Note that there are some explanatory texts on larger screens.

plurals
  1. POResolution for Model View Presenter Testing... Do I use DTO's or Domain objects or both?
    primarykey
    data
    text
    <p>The basic issue is how to test a presenter.</p> <p>Take: Domain object (will eventually be persisted to DB) Base attributes are Id (DB ID, Int/GUID/Whatever) and TransientID (Local ID until saved, GUID)</p> <p>DomainObject</p> <pre> <Code> namespace domain { public class DomainObject { private int _id; private Guid transientId; public DomainObject() { _transient_Id = Guid.NewGuid(); } } } </Code> </pre> <p>PresenterTest:</p> <pre> <code> var repository = Mock.StrictMock(); var view = Mock.StrictMock(); view.Save += null; var saveEvent = LastCall.Ignore().GetEventRaiser(); var domainObject = new DomainObject() {Id = 0, Attribute = "Blah"}; Mock.ExpectCall(Repository.Save(domainObject)).Returns(True); Mock.ReplayAll(); var sut = new Presenter(repository, view); Save_Event.raise(view, EventArgs.Empty); Mock.Verify() </code> </pre> <p>So the problem here is that the domain object identity is calculated with ID and failing that it's calculated with transientID, there's no way to know what the transientID will be so I can't have the mock repository check for equality.</p> <p>The workarounds so far are:</p> <p>1) LastCall.Ignore and content myself with jsut testing that the method got called but not test the content of the call.</p> <p>2) Write a DTO to test against and save to a service. The service than handles the mapping to domain.</p> <p>3) Write a fake testRepository that uses custom logic to determine success.</p> <p>--1 doesn't test the majority of the logic. --2 is a lot of extra code for no good purpose --3 Seems potentially brittle.</p> <p>Right now I'm leaning towards DTO's and a service in the theory that it gives the greatest isolation between tiers but is probably 75% unnecessary...</p>
    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. 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