madelson / MedallionShell

A .NET library simplifying the execution and chaining of processes
MIT License
415 stars 32 forks source link

Mocking Shell in unit tests is not possible #76

Closed alexeyshockov closed 3 years ago

alexeyshockov commented 4 years ago

Hey, thanks for a great library.

A (maybe stupid) question: how do you mock the Shell class? It's currently not possible with Moq, because there are no interface provided.

I see that in library's tests you don't use any mocks at all, but for client's code it would great to have this ability for unit tests.

Do you think it would be valuable to extract interfaces for Shell and Command classes to achieve this?

madelson commented 4 years ago

Hi @alexeyshockov thanks for your interest in the library.

It’s true that we don’t directly support mocking today and that the API isn’t terribly mock-friendly.

One concern I have with providing mocking at the shell level is that truly faking the behavior of a process with all the async things going on, respecting the various start info flags, etc would be very difficult.

When I’ve tested components that leverage this library, I prefer to mock at a higher level so that I only have to replicate the subset of the behavior that the particular usage cares about. For example, I will often wrap the shell invocation in a virtual function with a more straightforward/less-flexible API and the mock that function.

Does that resonate?