c# - Mocking Domain Model & Building Tests Without Repetition -


In my service layer looking for some explanation in the test, I have the following method:

  IDomainModelRepository Domain Model Repository Read Only; Edit Public DomainModelDataData (Int DomainModiDind, IPRinational User) {DomainModel myDomainModel = domainModelRepository.Find (DomainModelID); If ((myDomainModel == zero) || (! MyDomainModel.UserCanEdit (user))) throw new UnauthorisedException (); // Other stuff here ...}  

Now I am creating a test suite, but have hit some snaps.

  1. Code> myDomainModel.UserCanEdit (user) can not be switched because DomainModel is not implementing any interface. This becomes even more complicated because the logic contained in UserCanEdit actually checks the fields on other domain models of your domain. So how can I set it easily to return a set value to allow me to test the service?
  2. I'm testing the method correctly responds if repo domainmodel does not search for items, then I test it properly if the user can not be edited (okay i When solving 1 point above)! But after that, for every test that I write for "other stuff here" it is necessary to properly set up the test to pass these first two checks. It sounds cumbersome, and each test repeats the same code. Is there a better way?

Perhaps the problem is that to facilitate easy coding, I need to reapply my code if so, appreciate all the advice!

If you want to test, I think you need to use an interface < Code> myDomainModel otherwise you can not duplicate it.

I know that this is a very controversial opinion , but more and more people feel that the repository press is an anti-bar and more problems are resolved.

I personally use the unit framework and use only the interface to convert TT files to generate context and interface than all my applications.

To make the test, I just make fun of the interface and I am able to check everything. One of the changes I made is DbSet & lt; T & gt; with IDSet T & gt; to change Finally I created a test helper with a function that receives a ObsavableCollection and returns IDbSet and I am able to validate everything.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -