I am using xUnit and Moq for writing test cases. I am using the code below to create a Mock but am getting the highlighted issue.
CloudBlockBlob source = null;
AccessCondition sourceAccessCondition = null;
AccessCondition destAccessCondition = null;
BlobRequestOptions options = null;
OperationContext operationContext = null;
CloudBlobContainer container = new CloudBlobContainer(uri);
Task task = null;
DeleteSnapshotOption deleteSnapshotOption = new DeleteSnapshotOption();
var mockCloudBlobClient = new Mock<Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient>();
mockCloudBlobClient.Setup(repo => repo.GetContainerReference("sample")).Returns(container);
var mockCloudBlobContainer = new Mock<Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer>(uri);
mockCloudBlobContainer.Setup(repo => repo.GetBlockBlobReference("sample")).Returns(new CloudBlockBlob(uri));
var mockBlobServiceProvider = new Mock<BlobServiceProvider>();
mockBlobServiceProvider.Setup(repo => repo.GetBlockBlobContainer("sample")).Returns(new CloudBloblContainer(new Uri("http://mytest")));
The line mockBlobServiceProvider.Setup(repo => repo.GetBlockBlobContainer("sample")).Returns(new CloudBloblContainer(new Uri("http://mytest")));
is giving me this error:
System.NotSupportedException: 'Unsupported expression: repo => repo.GetBlockBlobContainer("sample")
Non-overridable members (here: BlobServiceProvider.GetBlockBlobContainer) may not be used in setup / verification expressions.'
Class BlobServiceProvider
:
Public Class BlobServiceProvider
{
public CloudBlobContainer GetBlockBlobContainer(string containerName)
{
CloudBlobContainer Container = blobClient.GetContainerReference(containerName);
Container.CreateIfNotExistsAsync();
return Container;
}
}
How can I resolve this issue?