Writing unit test cases that target Azure Dev Fabric

We are currently building an application that writes to Azure blob-storage as part of its business process.  As I was writing test cases for it, my Blob-storage operations were failing because that code is now running under the context of the test case instead of my web role.  So I needed a way to make sure that:

  1. DevFabric is running when my test cases start
  2. The DataConnectionString string is setup to hit DevFabric (I don’t really want to hit the “real” cloud for these test cases)

So I added a method marked with the “AssemblyInitialize” attribute in my Unit test project.  In that method, I check to see if DevFabric has started, if it is not started, i kick it off and wait for it to run.  Once that is going, I need to get the Data Connection String from my test project’s app.config file.  And now, when the code to access Blob storage gets called, it will have all the information it needs in order to successfully complete the operation. 

I have a lot of test cases that hit Azure, so that’s why I used AssemblyInitialize…this code could’ve been placed inside one test case or in a “ClassInitialize” method.

        public static void AzureInitialize(TestContext testContext)
            if( System.Diagnostics.Process.GetProcessesByName("DSService").Length == 0)
                System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo();
                start.Arguments = "/devstore:start";
                start.FileName = @"C:\Program Files\Windows Azure SDK\v1.2\bin\csrun.exe";
                var proc = new System.Diagnostics.Process();
                proc.StartInfo = start;
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => configSetter(ConfigurationManager.AppSettings[configName]));
            var azureAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

This is what I added in app.config:

    "DataConnectionString" value="UseDevelopmentStorage=true" />

About esteban

Esteban is the Founder and Chief Technologist at Nebbia Technology, an ALM consulting and Azure-powered technology company. He is a software developer with a passion for ALM, TFS, Azure, and software development best practices. Esteban is a Microsoft Visual Studio ALM MVP and ALM Ranger, Pluralsight author, and the president of ONETUG (Orlando .NET User Group).

7 thoughts on “Join me at VSLive in Orlando!

  1. Emre

    Is there any way to remove old folders from azure? When I delete a folder from my local and deploy project, it is not removing from Azure.

  2. Microsoft DevOps Blog

    […] Join me at VSLive in Orlando! – Esteban GarciaThis November, I will be back at Live! 360 in Orlando.  The conference runs from November 12th through November 17th at the Royal Pacific Resort. […]

  3. Professional PC Services

    I like your post! I read your blog often and I shared this
    post on my Facebook and my friends loved it. Keep up the awesome work.

  4. Pedenti Prasad

    import-digital-certificate-in-etoken-no key corrponding to this certificate was no found

  5. Pedenti Prasad

    Import Digital Certificate In eToken User certificate No Key Corresponding to This certificate Was Found.

    1. Pedenti Prasad

      Import Digital Certificate In eToken User certificate No Key Corresponding to This certificate Was Found.

  6. Andrew German

    From my point of view, dynamic scaling should be checked in advance to make sure everything is fine. The cloud infrastructure support provider should be used to compare between apples. If the test environment is different from the working one, data integrity raises serious questions.
    Here’s an indicative solution https://axisbits.com/blog/Cloud-Performance-Testing-of-Your-Software

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *