Reputation: 351
I am writing unit tests using xUnit and Moq. My class under test has a property
public DocumentClient documentClient {get; set;}
I am trying to mock this property using Moq and trying to mock OpenAsync method of DocumentClient. This is how I am creating the Mock object.
var documentClientObj = new Mock<DocumentClient>();
But I am getting an error saying "System.NotSupportedException : Type to mock must be an interface or an abstract or non-sealed class"
Upvotes: 1
Views: 549
Reputation: 7200
DocumentClient
Is neither an abstract class nor an interface. This means that mocking libraries cannot create proxy implementations. If you stick with the class you can't mock it.
However the Cosmos DB library has the IDocumentClient
interface in it which is what the DocumentClient
class is implementing. You should switch to that and then you will be able to mock it.
Upvotes: 1