question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mock .WithSnapshot(string snapshot) using Moq-framework

See original GitHub issue

Library name and version

Azure.Storage.Blobs 12.14.1

Query/Question

Hi,

Is there a possibility to mock (using Moq framework) the .WithSnapshot() method on the BlobClient? Currently the .WithSnapshot() method is not defined as virtual so Moq cannot create an “override” for this specific method. Calls like DeleteAsync() or UploadAsync() can be mocked without any problem.

In my testing code:

_blobClientMock = new Mock<BlobClient>(MockBehavior.Strict);
_blobClientSnapshotMock = new Mock<BlobClient>(MockBehavior.Strict);
_blobClientMock.Setup(x => x.WithSnapshot(mockedBlobItemSnapShot1.Name)).Returns(_blobClientSnapshotMock.Object);

Error when I debug / run the test:

System.NotSupportedException : Unsupported expression: x => x.WithSnapshot(mockedBlobItemSnapShot1.Name)
Non-overridable members (here: BlobClient.WithSnapshot) may not be used in setup / verification expressions.

I know we can do it the “hard” way by wrapping things etc. but I was wondering if we could avoid this and if there are any other solutions to do this.

Thanks in advance,

Tom

Environment

Azure Functions Runtime 4 and .NET6.0 Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview Version 17.7.0 Preview 1.0

Issue Analytics

  • State:open
  • Created 4 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jsquirecommented, Jun 1, 2023

@jsquire Any news on this subject? 😄

Unfortunately, I do not have insight - my role was just to triage. @PramodValavala-MSFT: can you provide an update?

0reactions
amnguyecommented, Jun 9, 2023

Let me look into this. I’m trying to figure out why the inherited class on the BlobBaseClient.WithSnapshot isn’t being used over the BlobClient.WithSnapshot since they are both essentially the same thing, but the API looks a little different.

Sorry for the inconvenience. If possible I think you can still use the BlobBaseClient.WithSnapshot instead since that one is virtual, as a mitigation for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Iqoqo/mockshot: Automatic mock generation from snapshot ...
Introduction to writing tests with Mockshot on Medium ... Use the snapshot's output as blueprints for generating a mock. ... className: string |...
Read more >
How to mock dynamic values in snapshot tests?
I have to snapshot tests: I create snapshot from router page with custom routers(guards for logged in users) and every time i run...
Read more >
Snapshot Testing
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
De-mystifying Jest Snapshot Test Mocks | by Albert Brand
So, let's say you have a nice React Native setup with the Jest testing library. You want to snapshot-test all your components of...
Read more >
json-snapshot.github.io | Snapshot Testing for Java
Snapshots help figuring out whether the output of the modules covered by tests is changed, without doing tons of asserts! When is it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found