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

Mocking Blobclient.DownloadContentAsync() #1411

Open
sarwary opened this issue Aug 30, 2023 · 3 comments
Open

Mocking Blobclient.DownloadContentAsync() #1411

sarwary opened this issue Aug 30, 2023 · 3 comments

Comments

@sarwary
Copy link

sarwary commented Aug 30, 2023

Hello, am I mocking the method below correctly coz, when called its not returning the result:

var blobContent = new BinaryData("this is test data");
var downloadResult = BlobsModelFactory.BlobDownloadResult(content: blobContent);
var response = Response.FromValue(downloadResult, blobContainerClientResponseMock.Object);

mockBlobClientTrue.Setup(client => client.DownloadContentAsync(default)).ReturnsAsync(response);

the reslut object of the task returned form this method is null.

@alexdtm9
Copy link

alexdtm9 commented Sep 12, 2023

I am using it like this in my code and it works:

var response = await blobClient.DownloadContentAsync();
if (!response.HasValue || response.GetRawResponse().IsError) (....)

This is how I mocked:

 var mockResponse = new Mock<Response>();
 var mockValue = BlobsModelFactory.BlobDownloadResult(new BinaryData("some data"), default);
_blobClient.Setup(x => x.DownloadContentAsync(default)).ReturnsAsync(Response.FromValue(mockValue, mockResponse.Object));

If I pass 'default' or 'It.IsAny()' inside my mocking the result is always null.

@anktsrkr
Copy link

@anktsrkr
Copy link

In this blog post i have exactly defined how to do - https://anktsrkr.github.io/post/getting-started-with-testing-for-azure-blob-storage-mocking-blob-storage-sdk/

Now it is updated to FakeItEasy. However if you follow the repo and see the old commits you will still be able to find which is using MOQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants