Mocking Azure Storage Transactions
Asked Answered
C

4

6

I am looking for mocking the azure storage transactions using Moles Mocking framework.

Any thoughts/documentation/samples on how to mock the azure storage transactions using Moles or may be any other mocking framework?

Crifasi answered 20/1, 2013 at 18:38 Comment(2)
P.S. I have already been through Guidance on Efficiently Testing Azure SolutionsCrifasi
I would recomend abstracting all the calls to azure storage in wrappers and mocking them. The majority of problems that you will get from storage will be connection related or throttles.Baryta
R
0

While this don't answer directly the question, as an alternative solution, I use the emulator shipped out of the box, which I believe could be considered as a mock of the azure storage.

Here is the piece of code I've added in my unit test base class to start the storage emulator:

    [TestInitialize]
    public void setup()
    {
         Process.Start(@"C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun", "/devstore").WaitForExit();

    }
Rexford answered 21/1, 2013 at 5:44 Comment(1)
Thanks Uzul! However, I am looking forward to mock the entities/transactions and avoid usage of storage emulator.Crifasi
C
0

The latest release of the .NET client virtualizes all service call APIs and also unseals relevant classes - meaning it should be simple to mock out the storage client library. Testing was performed with moq I believe. See: https://github.com/Azure/azure-storage-net/blob/master/BreakingChanges.txt

Criminology answered 13/5, 2016 at 19:17 Comment(0)
E
0

All you need to do is create an interface for whatever azure class you want to mock and take that interface as a dependency instead of the concrete azure class, for product code pass the concrete class from storage sdk, for your unit tests just use any unit testing framework (ie. Moq) or just your mock implementation of the interface and you are done.

Empoverish answered 11/6, 2016 at 22:37 Comment(0)
S
0

Prerequisite: Download Microsoft Azure Sdk for .Net (Contains The Storage Emulator) https://azure.microsoft.com/en-us/downloads/

You can run your code against the Azure storage emulator. The storage emulator is a local environment that emulates an Azure Storage account in the cloud. The emulator is a free option for testing and debugging your code while your application is under development. The emulator uses a well-known account and key. For more details, see Use the Azure Storage Emulator for Development and Testing

Connect to the Storage Emulator Account by setting up the bellow connection in to web.config

<appSettings>
  <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
</appSettings>

This is a screenshot of My Development Storage Emulator, This is a mock of Blobs tables etc...

enter image description here

Senn answered 14/8, 2016 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.