[storage] unit tests/mocks to storage client libraries #6

prabirshrestha opened this Issue Mar 2, 2012 · 10 comments


None yet
7 participants

prabirshrestha commented Mar 2, 2012

Create interface/virtual methods so we can easily write unit tests.


joeg commented Mar 5, 2012

We have yet to provide public unit tests as they are currently part of a larger internal testing framework. That being said our tests rely on the public api surface of both the convenience and protocol layers. Your tests should be able to do the same. If there is a specific scenario you are targetting that is not possible via the public api surface, please let us know,



prabirshrestha commented Mar 5, 2012

Here is simple test using xunit and moq.

public void test()
    var fakeMsg = new Mock<CloudQueueMessage>();

        .Setup(m => m.Id).Returns("1");
        .Setup(m => m.AsString).Returns("test msg");

    var fakeQueue = new Mock<CloudQueue>();
        .Setup(q => q.GetMessage()).Returns(fakeMsg.Object);

    var fakeQueueClient = new Mock<CloudQueueClient>();
        .Setup(q => q.GetQueueReference("q1")).Returns(fakeQueue.Object);

    var queueClient = fakeQueueClient.Object;
    var msg = queueClient.GetQueueReference("q1").GetMessage();
    Assert.Equal("test msg", msg.AsString);

And here is the error I get when I run the test. (This is limitation in most mocking frameworks.)

Test 'ClassLibrary1.Class1.test' failed: System.NotSupportedException : Invalid setup on a non-virtual (overridable in VB) member: m => m.Id
    at Moq.Mock.ThrowIfCantOverride(Expression setup, MethodInfo method)
    at Moq.Mock.<>c__DisplayClass1f`2.<SetupGet>b__1e()
    at Moq.PexProtector.Invoke[T](Func`1 function)
    at Moq.Mock.SetupGet[T,TProperty](Mock mock, Expression`1 expression, Func`1 condition)
    at Moq.Mock.<>c__DisplayClass1c`2.<Setup>b__1b()
    at Moq.PexProtector.Invoke[T](Func`1 function)
    at Moq.Mock.Setup[T,TResult](Mock mock, Expression`1 expression, Func`1 condition)
    at Moq.Mock`1.Setup[TResult](Expression`1 expression)
    Class1.cs(15,0): at ClassLibrary1.Class1.test()

By the way how are guys writing tests and which framework are you using.

joeg commented Mar 8, 2012

While we dont support mocking in the sense you described above many of our tests are targetted at the storage emulator that ships with the sdk which allows testing without hitting the public cloud.

One of the primary reasons the unit tests are not available online is due to the coupling with internal systems. As we continue the effort to provide more open source around the Azure sdks we will be updating these tests.



prabirshrestha commented Mar 8, 2012

It would be great to have unit tests even without hitting the storage emulator.

joeg commented Mar 15, 2012

Absolutely. Again we are in the process of decoupling our tests to be consumable by the public in a simple way. We will update the main branch as soon as this is available.

@ghost ghost assigned jeffreyjirwin Apr 9, 2012

+1 on this, bring us IBlobClient and IBlobContainer. Our existing unit tests already want to mock out methods on CloudBlobClient and CloudBlobContainer, and they are resorting to some fairly stupid workarounds in order to do so, like creating wrapper classes.

(By the way I don't think anyone is asking you to make your unit tests public. They're just asking for you to modify the API to make it easy for us to unit test our consumer code.)

@ghost ghost assigned bradygaster Dec 9, 2013

Yep! +1 to this please. Would really really REALLY love to make it easy to unit test this stuff....

var cloudQueue = A.Fake<ICloudQueue>();

^ That's not so hard to do, for us .. eh MS?

*I'm using FakeItEasy for my unit tests.

Also, should this issue be moved to the Storage repo?

stankovski pushed a commit that referenced this issue Sep 9, 2014

Merge pull request #6 from AuxMon/LatestGeneratedCode
Updated the generated code to reflect the split files.

@stankovski stankovski closed this Oct 2, 2014

@PureKrome PureKrome referenced this issue in Azure/azure-storage-net Oct 3, 2014


Enable unit testing for client libraries #80

stankovski pushed a commit that referenced this issue Oct 4, 2014

Merge pull request #6 from findmeetu/master
Minor change to replace LiveId with MicrosoftId

chuanboz pushed a commit to chuanboz/HDInsight that referenced this issue Feb 20, 2015

Merge pull request #6 from hdinsight/updatepoller
increasing polling interval to 30 seconds

yugangw-msft pushed a commit that referenced this issue May 29, 2015

yugangw-msft pushed a commit that referenced this issue Jul 9, 2015

Merge pull request #6 from MabOneSdk/swatim
Adding resourcename and resourcegroup in app.config

hovsepm pushed a commit that referenced this issue May 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment