Reputation: 3669
I use Moq. I want to stub a property getter in mock object:
var db = new Lazy<DatabaseContext>(DatabaseContextFactory.Create);
var mock = new Mock<IDocumentOperationContext>();
// stub "Database" property getter
mock.SetupGet(_ => _.Database).Stub(_ => db.Value);
But it throws an exception:
System.InvalidOperationExceptionThe object 'IDocumentOperationContext _ => _.Database' is not a mocked object.
I don't want to implement IDocumentOperationContext
or to stub with already existing DatabaseContext
object.
How to achieve the goal? Is it possible in another Mocking library?
Upvotes: 1
Views: 134