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?
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?
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();
}
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
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.
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...
© 2022 - 2024 — McMap. All rights reserved.