Skip to content

Tutorial 4

PhuocLe edited this page Mar 7, 2018 · 12 revisions

Task

  • Create Unit Test project for custom workflow: Wooow.Kool.Workflow.Contact

Coding

This is your exercise.

[TestClass]
public class WooowKoolWorkflowContact_ValidateRegexTest
{
    public static XrmFakedContext Context { get; set; }
    public static XrmFakedWorkflowContext WorkflowContext { get; set; }

    [ClassInitialize()]
    public static void ClassInit(TestContext context)
    {
        Context = new XrmFakedContext();
        WorkflowContext = Context.GetDefaultWorkflowContext();
    }

    [TestMethod]
    public void WooowKoolWorkflowContact_ValidateRegex_Return_True()
    {
        //setup 
        var inputs = new Dictionary<string, object>() {
            { "StringToValidate", "334-867-5309" },
            { "MatchPattern", @"^[2-9]\d{2}-\d{3}-\d{4}$" }
        };
        //run
        var result = Context.ExecuteCodeActivity<WooowKoolWorkflowContact_ValidateRegex>(WorkflowContext, inputs);

        //result
        Assert.AreEqual(result["Valid"], "1");
    }

    [TestMethod]
    public void WooowKoolWorkflowContact_ValidateRegex_Return_False()
    {
        //setup 
        var inputs = new Dictionary<string, object>() {
            { "StringToValidate", "A334-867-5309" },
            { "MatchPattern", @"^[2-9]\d{2}-\d{3}-\d{4}$" }
        };
        //run
        var result = Context.ExecuteCodeActivity<WooowKoolWorkflowContact_ValidateRegex>(WorkflowContext, inputs);

        //result
        Assert.AreEqual(result["Valid"], "0");
    }
}

Your Solution Explorer after you finished this tutorial

Finished Tutorial 4

Clone this wiki locally