Moq callback with invoking parameter -


i have these 3 lines of c# code using moq, how can write single line?

  jobqueuerepository.setup(r => r.updatejobqueuestatus(defaultjobid, jobstatus.success)).callback(() => statuses.add(jobstatus.success));   jobqueuerepository.setup(r => r.updatejobqueuestatus(defaultjobid, jobstatus.failed)).callback(() => statuses.add(jobstatus.failed));   jobqueuerepository.setup(r => r.updatejobqueuestatus(defaultjobid, jobstatus.running)).callback(() => statuses.add(jobstatus.running)); 

thanks help.

there piece of code asking for

    jobqueuerepository         .setup(it => it.updatejobqueuestatus(defaultjobid, it.isany<jobstatus>()))         .callback<int, jobstatus>((id, status) => statuses.add(status)); 

and test tests how works

[testclass] public class testclass {     [testmethod]     public void testmethod()     {         var statuses = new list<jobstatus>();         var jobqueuerepository = new mock<ijobqueuerepository>();         int defaultjobid = 100500;          jobqueuerepository             .setup(it => it.updatejobqueuestatus(defaultjobid, it.isany<jobstatus>()))             .callback<int, jobstatus>((id, status) => statuses.add(status));          jobqueuerepository.object.updatejobqueuestatus(defaultjobid, jobstatus.failed);         jobqueuerepository.object.updatejobqueuestatus(defaultjobid, jobstatus.running);         jobqueuerepository.object.updatejobqueuestatus(defaultjobid, jobstatus.success);          statuses.should().havecount(3);         statuses.should().contain(jobstatus.failed);         statuses.should().contain(jobstatus.running);         statuses.should().contain(jobstatus.success);     }      public enum jobstatus     {         success,         failed,         running     }      public interface ijobqueuerepository     {         void updatejobqueuestatus(int id, jobstatus status);     } } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -