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:
- DevFabric is running when my test cases start
- 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" />