Workflow Services Testing and Moq -


i'm trying unit test workflow service using microsoft.activities.unittesting goal mock service's extensions in order ensure steps executed.

the mock objects don't seem called though extensions registered in host. expected, if extensions not registered exception thrown.

        workflowservicetesthost host = null;          try         {             mock<isubscriber> publisher = new mock<isubscriber>();             mock<iwebworker> webworker = new mock<iwebworker>();              var voucher = new voucher();              using (host = new workflowservicetesthost(workflowservicefile, serviceaddress))             {                 host.workflowextensions.add<isubscriber>(() => publisher.object);                 host.workflowextensions.add<iwebworker>(() => webworker.object);                  host.open();                 using (var factory = new channelfactory<iserviceinterface>(clientbinding, serviceaddress))                 {                     var proxy = factory.createchannel() iserviceinterface;                      proxy.process(voucher);                 }             }              **//these validations fail...**              publisher.verify(m => m.push(it.isany<voucher>()), times.once(), "isubscriber.push not called.");             webworker.verify(m => m.done(it.isany<voucher>()), times.once(), "iwebworker.done not called.");              // host must closed before asserting tracking             // explicitly call host.close or exit using block this.         }                 {             if (host != null)             {                 host.tracking.trace(trackingoptions.all);             }         } 

the workflow runs expected in iis.

thanks!

edit: error being written in workflow host output:

workflowinstance "sequential service" unhandled exception source "receive process message"  exception <system.notsupportedexception: expression activity type 'csharpreference`1' requires compilation in order run.   please ensure workflow has been compiled. @ system.activities.expressions.compiledexpressioninvoker.invokeexpression(activitycontext activitycontext) @ microsoft.csharp.activities.csharpreference`1.execute(codeactivitycontext context) @ system.activities.codeactivity`1.internalexecuteinresolutioncontext(codeactivitycontext context) @ system.activities.runtime.activityexecutor.executeinresolutioncontext[t](activityinstance parentinstance, activity`1 expressionactivity) @ system.activities.outargument`1.trypopulatevalue(locationenvironment targetenvironment, activityinstance targetactivityinstance, activityexecutor executor) @ system.activities.runtimeargument.trypopulatevalue(locationenvironment targetenvironment, activityinstance targetactivityinstance, activityexecutor executor, object argumentvalueoverride, location resultlocation, boolean skipfastpath) @ system.activities.activityinstance.internaltrypopulateargumentvalueorscheduleexpression(runtimeargument argument, int32 nextargumentindex, activityexecutor executor, idictionary`2 argumentvalueoverrides, location resultlocation, boolean isdynamicupdate) @ system.activities.activityinstance.resolvearguments(activityexecutor executor, idictionary`2 argumentvalueoverrides, location resultlocation, int32 startindex) @ system.activities.runtime.activityexecutor.executeactivityworkitem.executebody(activityexecutor executor, bookmarkmanager bookmarkmanager, location resultlocation)> 

i've realized workflowservicetesthost microsoft.activities.unittesting class , not yours.

so, let's see if possible. saw on source code can pass constructor workflowservice's object instead of xamlx file. this:

// load workflowservice .xamlx // method workflowservicetesthost uses when pass // .xamlx we're taking step able compile body var wfservice = xamlservices.load("c:\\workflowservice.xamlx") workflowservice;  // compile workflow body compileexpressions(wfservice.body);  // can use workflowservicetesthost using (host = new workflowservicetesthost(wfservice, serviceaddress)) {     // ... thing } 

compileexpressions taken link gave earlier.


that being said, seems odd consider testing wcf service unit-testing. unit tests should focused on small activities of service, unit-testable. integration tests (or functional tests) test services dependencies (iis\was, network, dbs, etc).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -