Integration testing azure storage – Fluent syntax

Hi,

I recently set about writing a solution that’s heavily reliant on Azure Blob storage. I found my debugging cycle wasn’t nice, I’d spin up the code then spend ages in Azure Storage Explorer to work out what had happened. I also new I’d want some integration tests for the future.

So I did some research set about writing a quick set of helpers to allow me to write clean, quick and simple tests that worked in VS Test explorer.

The result is FluentAzureBlobTesting, this allows me to write lovely declarative statements like this:

           blobClient
                .AssertContainerExists(expectedContainerName)
                .AssertBlobExists(expectedBlobName)
                .AssertBlobDataIs(expectedBlobData)
                .AssertBlobContainsMetaData(expectedMetaDataKey, expectedMetaDataValue)
It also handles the starting, stopping and clearing of the storage emulator so all you have to do is click “Run All” and it handles the rest. *Dependency on Azure 2.3 SDK
        private static CloudStorageAccount account;
        private static CloudBlobClient blobClient;

        [ClassInitialize]
        public static void StartAndCleanStorage(TestContext cont)
        {
            account = CloudStorageAccount.DevelopmentStorageAccount;
            blobClient = account.CreateCloudBlobClient();
            blobClient.StartEmulator();
        }

        [ClassCleanup]
        public static void ShutdownStorage()
        {
            blobClient.StopEmulator();
        }

        [TestInitialize]
        public void CleanAndRestartStorage()
        {
            blobClient.ClearBlobItemsFromEmulator();
        }
Should the test fail the extensions report back the reason for failures and log trace output on success.
FailedTest PassingTestWithTrace
Now my debugging cycle is nice a quick and I’m writing a good set of unit tests as I go.
The source is available on github here, hopefully useful to you!
Thanks to Rory for the starting point here: http://www.neovolve.com/post/2012/01/12/Integration-testing-with-Azure-development-storage.aspx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: