Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
prabirshrestha opened this issue Mar 2, 2012 · 10 comments
Closed

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

prabirshrestha opened this issue Mar 2, 2012 · 10 comments
Assignees

Comments

@prabirshrestha
Copy link
Member

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

#6

@joeg
Copy link

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,

joe

@prabirshrestha
Copy link
Member Author

Here is simple test using xunit and moq.

[Fact]
public void test()
{
    var fakeMsg = new Mock<CloudQueueMessage>();

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

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

    var fakeQueueClient = new Mock<CloudQueueClient>();
    fakeQueueClient
        .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
Copy link

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.

joe

@prabirshrestha
Copy link
Member Author

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

@joeg
Copy link

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.

@TimLovellSmith
Copy link
Member

+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.

@TimLovellSmith
Copy link
Member

(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-zz Dec 9, 2013
@PureKrome
Copy link

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.

@PureKrome
Copy link

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

stankovski pushed a commit that referenced this issue Sep 9, 2014
Updated the generated code to reflect the split files.
@stankovski
Copy link
Member

Please recreate in https://github.com/Azure/azure-storage-net/.

stankovski pushed a commit that referenced this issue Oct 4, 2014
Minor change to replace LiveId with MicrosoftId
chuanboz pushed a commit to chuanboz/HDInsight that referenced this issue Feb 20, 2015
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
Adding resourcename and resourcegroup in app.config
hovsepm pushed a commit that referenced this issue May 20, 2016
jethibau pushed a commit to jethibau/azure-sdk-for-net that referenced this issue Aug 2, 2018
* Adding zone support

* Adding zone tests

* Fixing test name

* Adding test recordings

* Removing catch all exception from tests, adding comments for the tests we skip

* Zone samples

* Test recordings for zone samples

* Reflecting test name update in recording
AlexGhiondea pushed a commit to AlexGhiondea/azure-sdk-for-net that referenced this issue Feb 12, 2019
AlexGhiondea pushed a commit to AlexGhiondea/azure-sdk-for-net that referenced this issue Feb 12, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants