Random Musings

May 30, 2009

TDD on Dynamics CRM Workflow

Filed under: Dynamics CRM — haditeo @ 8:23 pm
Tags: , ,

In the Dynamics CRM 4 custom workflow activity, we can create an instance of CRMService by instantiating a IWorkflowContext object

IWorkflowContext context = ((IContextService)executionContext.GetService(typeof(IContextService))).Context;
ICrmService crmService = context.CreateCrmService();

How to unit test a Dynamics CRM 4 workflow ? since the CrmService object needs to be created with an interface type of ICrmService

Notice here carefully that we need to implement several methods, but in my scenario, i need to use the execute method.

    class MyCrmService :ICrmService

        private CrmService crmService;

        public MyCrmService()
            NetworkCredential nc = new NetworkCredential();
            nc.Domain = "Domain";
            nc.UserName = "administrator";
            nc.Password = "pwd";

            // Set up the CRM Service.
            CrmAuthenticationToken token = new CrmAuthenticationToken();
            token.AuthenticationType = 0;
            token.OrganizationName = "xyz";

            CrmService service = new CrmService();
            service.Url = "http://localhost/mscrmservices/2007/crmservice.asmx";
            service.CrmAuthenticationTokenValue = token;
            service.Credentials = nc;
            this.crmService = service;        

        #region ICrmService Members

        public Guid Create(BusinessEntity entity)
            throw new Exception("The method or operation is not implemented.");

        public void Delete(string entityName, Guid id)
            throw new Exception("The method or operation is not implemented.");

        public object Execute(object request)
            return crmService.Execute((Request)request);

        public string Fetch(string fetchXml)
            throw new Exception("The method or operation is not implemented.");

        public BusinessEntity Retrieve(string entityName, Guid id, ColumnSetBase columnSet)
            throw new Exception("The method or operation is not implemented.");

        public BusinessEntityCollection RetrieveMultiple(QueryBase query)
            throw new Exception("The method or operation is not implemented.");

        public void Update(BusinessEntity entity)
            throw new Exception("The method or operation is not implemented.");


        #region IDisposable Members

        public void Dispose()
            throw new Exception("The method or operation is not implemented.");

    public class Class1
        private MyCrmService crmSvc;
        private MyMetadataService metadataSvc;
        private SendEmailActivity activity;

        public void Init()
            this.crmSvc = new MyCrmService();

            this.metadataSvc = new MyMetadataService();

            this.activity = new SendEmailActivity();


The advantages of using the Interface, during the runtime, we can switch a method which requires ICrmService with the actual CrmService itself


May 29, 2009

TDD on DeliverIncomingEmailRequest

Filed under: Dynamics CRM — haditeo @ 7:06 pm
Tags: , ,

There is a scenario where developers would like to convert emails to the related entity let’s say incident.

To process the incoming emails, a plugin needs to be developed that listen to the DeliverIncomingEmail message. Imagine that developers need to setup a vpc which has a valid routable email address and internet connection etc.

Actually in the SDK, we can simulate this by triggering DeliverIncomingEmailRequest CRM service

Developers can use the below code

            DeliverIncomingEmailRequest req = new DeliverIncomingEmailRequest();
            req.From = "from@email.com";
            req.To = "ryan@sample.com";
            req.Subject = "subject" + DateTime.Now.ToLongDateString() + " - " + DateTime.Now.ToLongTimeString();
            req.MessageId = "messageId" + Guid.NewGuid().ToString();
            req.Body = "body" + Guid.NewGuid().ToString();
            req.Cc = "cc@email.com";
            req.Bcc = "bcc@email.com";
            req.ReceivedOn = new CrmDateTime("10/10/2000");
            req.SubmittedBy = "abc";
            req.Importance = "1";

            req.Attachments = new BusinessEntityCollection();
            req.Attachments.EntityName =
            DeliverIncomingEmailResponse res = (DeliverIncomingEmailResponse)crmService.Execute(req);

Pay attention that one of the recipient must be a valid CRM user with his/her valid email address. In this example, ryan@sample.com is a valid crm user.

This code can be run by using NUnit to make the testing easier.

May 3, 2009

How to use ASP.NET Ajax RadComboBox with WatiN

Filed under: telerik,watin — haditeo @ 5:24 pm
Tags: ,

I am curious in how to select a valid value from the Telerik ASP.NET Ajax RadComboBox with WatiN.

First of all i googled around its forum and found this forum post. I didn’t look carefully as it was only applied to ASP.NET RadComboBox and ASP.NET Ajax RadComboBox

No wonder, after i blindly used it without modifying it, the DOM element cannot be found. Here my IE Developer Toolbar with IE 8 came to rescue

Take a look at the (a) tag inside this screenshot. In the ASP.NET RadComboBox, it was still using (image) tag


Take a look at the (li) tag for the items in the combo box. Previously it was using (div) tag


Here is the code snippet:

  // currently my RadComboBox client-id name is ddlTopic. 
  // please substitute your proper combobox name appended by "_Arrow" 
  Link radComboBoxDropDownImage = ie.Link(Find.ById("ddlTopic_Arrow")); 
  // my RadComboBox client-id name is ddlTopic 
  // please substitute with your proper combobox name appended by "_DropDown" 
  Div divTopic = ie.Div(Find.ById("ddlTopic_DropDown")); 
  ElementCollection elColl = divTopic.ElementsWithTag("li"); 
  // here i would like to select the 4th option inside the combo-box 
  // the dropdownlist option index is started with 0  

May 2, 2009

WatiN and Ajax Request

Filed under: watin — haditeo @ 6:32 pm

Currently i have came across almost the same issue But this time, i am using Telerik RadAjax. Currently waiting for their update.

WatiN tips : ie.Refresh

Filed under: watin — haditeo @ 6:29 pm

Just came across Ayende’s blog

Developers can use the Refresh() method to clear the browser’s cache, so that the browser always pick-up our latest changes


Getting Started With WatiN

Filed under: watin — haditeo @ 6:15 pm
Tags: ,

Today i went to library and searched for books on TDD. Came across this particular book Pragmatic Unit Testing in C# with NUnit

Actually i need to find a good way to automate my UI testing since my current tasks now mostly deal with Javascript, Telerik 3rd ASP.NET Ajax and finally Dynamics CRM SDK

For the starter, i have googled across this
Getting started with WatiN and remember to create an app.config file and configure the STA Thread

Currently i am learning in applying TDD. For the UI test now, i am using NUnit to automate the testing.

I have setup the ie object by using this code snippet :

IE ie = new IE("http://localhost/webform1.aspx");

It was quite easy to use WatiN.
1) To configure a textbox field, i am using this code snippet :


2) I am using an image button to open the RadWindow. This is the code snippet :


3) How to get hold of the Modal Dialog that has been opened by RadWindow ? I used IE Developer Tool and find out that an IFrame is invoked. This is the code snippet :

Frame radWindowFrame = ie.Frame(Find.ByName("RadWindowObject"));

4) Currently i have encountered an issue. I have performed an Ajax request by clicking a client side button to retrieve tabular data and populate back to the client using grid. WatiN executes my line of code synchronously so i need to check at the client side whether asynchronous postback has been successfully performed so that i can proceed with my WatiN code.

Create a free website or blog at WordPress.com.