Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:21:11+00:00 2026-06-01T04:21:11+00:00

I need to assert the value of a variable in a workflow service. I’ve

  • 0

I need to assert the value of a variable in a workflow service.

I’ve already downloaded and am using the Microsoft.Activities.UnitTesting framework from CodePlex to test the workflow service endpoint, return values, and flow logic – but I need to verify the value of a variable after calling into an endpoint and getting a response – is that possible?

If it’s not is there some other type of workaround that might work that doesn’t involve changing the workflow itself to produce an output parameter? Because when in production I certainly wouldn’t need one.

Thanks!

UPDATE 2.A

Currently using the stubs method instead of the WCF method for testing the service.

[TestMethod]
[DeploymentItem(@"TestService\Service1.xamlx")]
public void TestValueOfInteger1AfterStart()
{
    // inject the mocks into the service
    var xamlInjector = new XamlInjector("Service1.xamlx");
    xamlInjector.ReplaceAll(typeof(Receive), typeof(ReceiveStub));
    xamlInjector.ReplaceAll(typeof(SendReply), typeof(SendReplyStub));

    // setup the messages
    var stubExtension = new MessagingStubExtension();

    // enqueue a message for the receive activity using parameters content
    stubExtension.EnqueueReceive(XName.Get("{http://tempuri.org/}IService"), "Start", null);

    // setup the host
    var host = WorkflowInvokerTest.Create(xamlInjector.GetWorkflowService().Body);
    host.Extensions.Add(stubExtension);

    try
    {
        host.TestActivity();
        ...

UPDATE 2.B

So, after some more effort I found that instead of using the WCF endpoint for unit test I could recover a context through reflection if I used the stubs. Above is an exerpt of the stubs unit testing code and below is the reflection code I’m using to get a refreshed ActivityContext. However, now I’m getting the following error when trying to get the value of the variable.

The interesting part is that you can clearly see the activity the context is tied to is the activity in which it is defined – the poor framework is just a little confused.

Exception when trying to grab the variable value.

...
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;

// recover the WorkflowInstance
var proxy = stubExtension.GetType().GetProperty("InstanceProxy",
                                                bindingFlags).GetValue(stubExtension,
                                                                       bindingFlags,
                                                                       null,
                                                                       null,
                                                                       null) as WorkflowInstanceProxy;

// recover the WorkflowInstance
var fieldInfo = proxy.GetType().GetField("instance", bindingFlags);
var workflowInstance = fieldInfo.GetValue(proxy) as WorkflowApplication;

// recover the ActivityExecutor
fieldInfo = workflowInstance.GetType().BaseType.GetField("executor", bindingFlags);
dynamic activityExecutor = fieldInfo.GetValue(workflowInstance);

// recover the rootInstance
fieldInfo = activityExecutor.GetType().GetField("rootInstance", bindingFlags);
var rootInstance = fieldInfo.GetValue(activityExecutor) as ActivityInstance;

// recover the cachedResolutionContext
fieldInfo = activityExecutor.GetType().GetField("cachedResolutionContext", bindingFlags);
var cachedResolutionContext = fieldInfo.GetValue(activityExecutor) as ActivityContext;

MethodInfo methodInfo = cachedResolutionContext.GetType().GetMethod("Reinitialize", bindingFlags);
methodInfo.Invoke(cachedResolutionContext, bindingFlags, null, new object[]
                                                                   {
                                                                       rootInstance,
                                                                       activityExecutor
                                                                   }, null);

var val = (int)((Sequence)rootInstance.Activity).Variables.First(x => x.Name == "integer1").Get(cachedResolutionContext);
Assert.AreEqual(val, 1, "The integer value of integer1 is not correct.");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:21:12+00:00Added an answer on June 1, 2026 at 4:21 am

    You could use AppFabric tracking and monitor the variable.

    However, the question raises the further question that if you are already testing flow logic and outputs, why do you need to test the internal state of the wf instance?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some unit tests and I need to be able to Assert whether
Suppose we have 3 variables and we need to ASSERT that they can either
I need to mask out some leading bits of an value. If the value
I'm using CUnit for my project unit testing. I need to test whether I
Is there a way to assert that a variable (or more specifically, a fact)
I have homework that I need to make a custom string class using C
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.
Need to an expression that returns only things with an I followed by either
Need to locate the following pattern: The letter I followed by a space then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.