Mocking commands
AsafMag opened this issue · 1 comments
AsafMag commented
I would really like to mock ITikConnection.Save
and many other functions but they are implemented as extension methods. Is that really necessary? What are the reasons for implementing most of the library as extension methods?
danikf commented
Hi,
reasons for this approach:
- Extensibility (everybody is able to create his own connection extension - e.q. extension in
EthernetMonitor
class. - I believe that interaction with mikrotik (or database) should be tested by integration tests, not unitests. (https://stackoverflow.com/questions/6766478/unit-testing-dbcontext/6768712#6768712)
- I believe that unit-testing
controlers
is not goog idea (no real logic inside) and loading/saving code is very similar.
How to test your code (just brainstorming):
- Use some kind of mikrotik facade abstraction (like DAO/Service layer) and mock this facade (e.q.
LoadAllEthBasedInterfaces()
,LoadAllActiveUsers()
,DisableMikrotikUserByName(name)
). It also helps withCQS
. This facade itself iscontroller
(from my perspective) and should not be unit-tested. - Mock whole
ITikConnection
andITikCommand
(pretend mikrotik communication) - could be very hard work
BTW: I have plan to create some kind of mikrotikwrapper class (wraps connection) with easy to use API (like mikrotik.Users.Create(name, ...);
and I will face the same problem there - so - may be, I will recognize I am wrong :-)
D