Expose InArguments/OutArguments property on Test Hosts to simplify passing arguments to the activity under test

This feature is now released in Microsoft.Activities.UnitTesting v1.8.5

WorkflowInvokerTest Example

[TestMethod]
public void TestMethod1()
{
    // Arrange
    var activity = new Sum();

    var host = WorkflowInvokerTest.Create(activity);

    // InArguments is a dynamic object of type Microsoft.Activities.WorkflowArguments
    host.InArguments.Num1 = 1;
    host.InArguments.Num2 = 2;

     // Act
    host.TestActivity();

    // Assert
    Assert.AreEqual(3, host.OutArguments.Result);
}

WorkflowApplicationTest Example

[TestMethod]
public void SumAddsTwoNumbersWorkflowApplication()
{
    // Arrange
    var activity = new Sum();

    dynamic arguments = new WorkflowArguments();
    arguments.Num1 = 1;
    arguments.Num2 = 2;

    // With WorkflowApplication you have to specify the arguments when created
    // Cannot support InArguments Property
    var host = WorkflowApplicationTest.Create(activity, arguments);

    // Act
    host.TestActivity();

    // Assert
    Assert.AreEqual(3, host.OutArguments.Result);
}

New Unit Tests for WorkflowInvokerTest

WorkflowInvokerTest.InArguments Property

InArgumentsShouldPassValues Verifies that you can pass a value using InArguments to an activity]
InArgumentsWithDictionaryWillThrow Verifies that if you use both an input dictionary an InArguments you get an argument exception

WorkflowInvokerTest.OutArguments Property

OutArgumentsShouldNotBeNull Verifies that the OutArguments property is not null when there are no arguments
OutArgumentsShouldThrowWhenDoesNotExist Verifies that accessing a dynamic OutArguments that does not exist will throw an exception
OutArgumentsShouldReturnValues Verifies that OutArguments return values when they exist
OutArgumentsShouldThrowWhenNotSetYet Verifies that accessing the OutArguments property before the workflow has run will throw

New Unit Tests for WorkflowApplicationTest

Note: There is no InArguments property for WorkflowApplicationTest because arguments must be specified when constructed.

WorkflowApplicationTest .OutArguments Property

OutArgumentsShouldNotBeNull Verifies that the OutArguments property is not null when there are no arguments
OutArgumentsShouldThrowWhenDoesNotExist Verifies that accessing a dynamic OutArguments that does not exist will throw an exception
OutArgumentsShouldReturnValues Verifies that OutArguments return values when they exist
OutArgumentsShouldThrowWhenNotSetYet Verifies that accessing the OutArguments property before the workflow has run will throw

Last edited Jul 21, 2011 at 2:17 PM by ronjacobs, version 8

Comments

No comments yet.