Mock .WithSnapshot(string snapshot) using Moq-framework
See original GitHub issueLibrary 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:
- Created 4 months ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unfortunately, I do not have insight - my role was just to triage. @PramodValavala-MSFT: can you provide an update?
Let me look into this. I’m trying to figure out why the inherited class on the
BlobBaseClient.WithSnapshot
isn’t being used over theBlobClient.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 isvirtual
, as a mitigation for now.