Unit Testing using Microsoft Fakes
Originally posted on Nishant Rana's Weblog:
Hi,
Just sharing a sample code to test a custom workflow activity using Microsoft Fakes.
The custom workflow activity uses LINQ.
The custom workflow activity code
1public sealed class MyCustomWorkflowActivity : CodeActivity
{
#region Public Properties
[Input("Stage Name")]
public InArgument<string> StageName { get; set; }
#endregion
#region Methods
/// <summary>
/// Executes the workflow activity.
/// </summary>
/// <param name="executionContext">
/// The execution context.
/// </param>
protected override void Execute(CodeActivityContext executionContext)
{
// Create the tracing service
var tracingService = executionContext.GetExtension<ITracingService>();
// Create the context
var context = executionContext.GetExtension<IWorkflowContext>();
var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
using (var xrmServiceContext = new XrmServiceContext(service))
{
// get the business process workflow id
var workflow = (from w in xrmServiceContext.WorkflowSet
where w.Name == "Business Process Workflow Name"
select new Workflow { WorkflowId = w.WorkflowId }).FirstOrDefault();
if (workflow != null)
{
// get the stage name from the context's input parameter
View original 319 more words

Like
Report
*This post is locked for comments