I have some unit tests where I want to mock the Azure BlobItem
class (Azure.Storage.Blobs.Models).
Here is my test class I'm using. I want the Values
getter to return a list with a mock BlobItem. That is working.
public class TestPage : Page<BlobItem>
{
public override IReadOnlyList<BlobItem> Values
{
get
{
return new List<BlobItem>() { new Mock<BlobItem>().Object };
}
}
public override string ContinuationToken => throw new NotImplementedException();
public override Response GetRawResponse()
{
throw new NotImplementedException();
}
}
However when I do this, the Name
property on my mock BlobItem is always null.
I can try to set it up so that Name
would return a mocked value like so:
var mock = new Mock<BlobItem>();
mock.SetupGet(x => x.Name).Returns("mock");
But then I get an error:
Non-overridable members may not be used in setup/verification expressions.
I understand why this error is happening. But I do not know what the solution is.
I want a mocked BlobItem to return a non-null Name
value. How can I achieve this?