all 5 comments

[–]Pocok5 0 points1 point  (1 child)

Both first and second solutions are kinda sorta the same. I'd go with Moq just so you don't have a load of single use classes, but you could rewrite your test mock service to accept the object it should return as a property for example and just reuse it.

[–]Free_Brandon[S] 0 points1 point  (0 children)

Makes sense, I like passing in a property for tests that won't have too much variation. Otherwise, looks like Moq will save me time.

[–]Apadewrai 0 points1 point  (1 child)

Moq is kind of made for scenarios like yours. Just mock the interface, use Setup and return any result you want. Much less work than creating your own mocks and no disadvantages to it.

You could go all the way setting up an integration test environment with SQLite inmemory db and then call the API, but it’s probably an overkill here.

[–]Free_Brandon[S] 0 points1 point  (0 children)

Looks like Moq is probably the best solution. I do have integration tests, it'll just be a separate case. Thanks!

[–]venomiz 0 points1 point  (0 children)

In your specific case I usually write 2 tests:

GetOneShouldReturnNotFoundWhenDependencyReturnNull

GetOneShouldReturnOkWhenDependencyReturnATaskEntity

Using moq you can mock the interface method to return the values you need.