DEV Community

Discussion on: Kentico Xperience 13 Beta 3 - New Data Access APIs

Collapse
 
hades200082 profile image
Lee Conlin

Very interesting read. Can ObjectQuery GetEnumerableTypedResultAsync and GetEnumerableTypedResult be mocked with moq?

Collapse
 
seangwright profile image
Sean G. Wright

Lee,

The methods on ObjectQueryBase<T> are virtual, so assuming you somehow mock that, you should be able to override the methods.

The new Get() methods on IInfoProvider<T> are also virtual, so by mocking those and having them return a mocked ObjectQuery<T> (which inherits ObjectQueryBase<T>) you should be able to fake out the whole data access layer.

That said, I don't often see this kind of code being mocked because the internals of the querying code are very specific to getting data out of the database, and this seems like a much better opportunity for integration tests.

By putting code that interacts with DocumentQuery<T> and ObjectQuery<T> behind abstractions you can unit test your business logic, and integration test your data access implementation.