unit test an activity with variables

Nov 16, 2011 at 2:05 PM

Hello,

I am trying to test an activity with variable but have not been able to.  Please point me to any sample you may have on this.

My test code:

 [TestMethod()]
    public void DataProcessTest()
    {
      MyActivity activity = new MyActivity();      
      var host = WorkflowInvokerTest.Create(activity);
      
      var input = InputDictionary.Create("value1", 1);

      try
      {
        // Act
        host.TestActivity(input);       

        // Assert
        // Note: The host automatically captures the out arguments
        host.AssertOutArgument.AreEqual("MyVariable"false);
      }
      finally
      {
        // Note: The host automatically captures tracking
        host.Tracking.Trace();
      }

    }

My activity executes fine until it gets to this line of code:

PropertyDescriptor myProperty = context.DataContext.GetProperties()["MyVariable"];
myProperty.SetValue(context.DataContext, true);
I got an Object reference not set to an instance of an object.  It is saying myProperty is null.  How do I include this property as an argument to the workflow host?
THank you in advance for your help.

 

May 25, 2012 at 3:29 PM

Does "value1" need to be "MyVariable"?

Looks to me like the "MyVariable" is not an OutArgument at all.

What does ' host.OutArguments.MyVariable' look like?

Maybe:

 [TestMethod()]
    public void DataProcessTest()
    {
      MyActivity activity = new MyActivity();      
      var host = WorkflowInvokerTest.Create(activity);
      
      var input = InputDictionary.Create("value1", 1);

      try
      {
        // Act
        host.TestActivity(input);       

        // Assert
        // Note: The host automatically captures the out arguments
        host.AssertOutArgument.AreEqual("value1"false);        
      }
      finally
      {
        // Note: The host automatically captures tracking
        host.Tracking.Trace();
      }

    }