Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing Code for Azure

I have an Azure application, and recently went gung-ho on the application settings. I realized putting pretty much every setting I needed into the ServiceConfiguration was the obvious way to go for anything you might even remotely want to change on the fly; which means web service URLs, smtp host information, etc is all in my ServiceConfiguration.

Imagine my suprise when, after I made my changes, I tried to run my 200+ unit tests, only to smack straight into this error:

Why am I getting SEHException when calling RoleEnvironment.GetConfigurationSettingValue("MYKEY")?

Obviously, I have several options here...

-I can write my own small class using RoleEnvironment.IsAvailable() to check where I should be getting my settings from, and get them from the app.config if i'm not in azure.

-I could deploy my application to the test environment, and just test the externally-facing interfaces.

But is there a "built-in" way? Are there any updates to the unit testing framework that would let me test the exact code that's running (within the environment it will be run in and with the settings that will be deployed)?

like image 842
Steve Avatar asked Dec 29 '22 09:12

Steve


2 Answers

As of June 2012 Azure release, you can use the CloudConfigurationManager - it checks the .cscfg and .csdef files if available, otherwise reads from the appSettings section of app.config or Web.config:

<configuration>
  <appSettings>
    <add key="Foo" value="Bar" />
  </appSettings>
</configuration>

Then in code:

CloudConfigurationManager.GetSetting("Foo")
like image 184
Rob Church Avatar answered Dec 30 '22 22:12

Rob Church


As far as I'm aware there is no built in way in the testing framework for testing which version of the config settings you should be using. I'm using a wrapper class like the one you describe (which I'm sure you already know is simple to write), but mainly so that we can run our websites outside of the dev fabric.

like image 22
knightpfhor Avatar answered Dec 30 '22 23:12

knightpfhor