This project is read-only.

.NET 4.5?

May 16, 2012 at 8:11 AM
Edited May 16, 2012 at 8:11 AM

Any idea when a .NET 4.5 version of the UnitTesting DLL will be available?  I tried using current version but it doesn't seem to work, compiles and runs fine but the workflows never run properly.  I posted this on the WF4 forum if anybody has any ideas:


How does one host a .NET 4.5 XAMLX workflow service in a WorkflowServiceHost?  It doesn't seem to work.

XamlServices.Load("...xamlx") won't work - it doesn't compile the C# expressions and you get this error:

9: WorkflowInstance "Sequential Service" Unhandled Exception Source "ReceiveRequ
est" Exception <System.NotSupportedException: Expression Activity type 'CSharpRe
ference`1' requires compilation in order to run.  Please ensure that the workflo
w has been compiled.

OK, so I find ActivityXamlServices.Load(...,ActivityXamlServicesSettings { CompileExpressions = true}).  Doesn't work - it will only load activities, not a workflowservice instance.

Unhandled Exception: System.ArgumentException: ActivityXamlServices.Load only su
pports Activity-based types.  Invalid type (System.ServiceModel.Activities.Workf
lowService) was provided.

My basic use case is to try unit testing a workflow, and Microsoft.Activities.UnitTesting doesn't seem to support .NET 4.5 (probably same thing broken as described above).  So I'm a bit lost unless anyone has any ideas.

May 25, 2012 at 4:04 PM

Workflows are comprised of unit-testable Activities. Those should be your focus. Testing the WCF Service, the XAMLX via WorkflowServiceHost is not unit testing, that is functional testing or integration testing ~ where dependencies outside of the code itself prohibit unit testing (network, IIS, DB, etc).

Unit test your Activities.

You can find examples of unit testing your custom activites on the internet...

        public void CreateAccessRequest_Execute_Test()
            // Arrange
            var fake = new FakeUserProvEntities();
            CreateAccessRequest activity = new CreateAccessRequest();
            activity.Entities = fake;
            var host = new WorkflowInvokerTest(activity);
            host.InArguments.OriginatorId = 24;
            host.InArguments.SecurityInstanceId = 12;
                // Act            
                var results = host.TestActivity();
                // Assert                
                Assert.AreEqual(1, new List<AccessRequest>(fake.AccessRequests).Count);
                Assert.IsNotNull(host.OutArguments.AccessRequest.RequestDate, "RequestDate was not set");
May 25, 2012 at 4:17 PM

You may experiment with loading your XAMLX as an activity for unit tests.

I'm loading XAMLX files from a database as a string into a MemoryStream and then loading the stream as an Activity with ActivityXamlServices.

Let me know what you find. Remember any dependencies need to be abstracted away so that they can be faked or mocked or otherwise stubbed for the unit test.

Here's some more code to consider; here the string argument 'body' is the XAMLX file text:

            if (!String.IsNullOrEmpty(body))
                Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(body));
                Activity wf = ActivityXamlServices.Load(stream);
May 29, 2012 at 8:17 AM

Thanks for the feedback, John.  The line between Unit tests and System tests is fuzzy, in my case I want to test the entire end to end implementation of a workflow that handles complex approval flow.  So I'll be testing both activities and the entire workflow, and have mock implementations for most everything, including the database.

I can have 100 perfectly designed/tested activities, but if the WF that strings them together is broken it will be for nothing.  That said - I am going to try to break it up into more discrete activities, but ultimately I want to host in a xamlx file so I'd like to test with a xamlx file for my end to end system tests.

In your code, are you loading a xamlx file or a xaml file?  I can get it to work with xaml, not with xamlx.

May 29, 2012 at 5:27 PM
Edited May 29, 2012 at 6:17 PM
jvrobert wrote:

In your code, are you loading a xamlx file or a xaml file?  I can get it to work with xaml, not with xamlx.

XAML. Sorry for my misread.

Looks like the problem is with the C# expressions, apparently VB.NET expressions do work:

 + also: