danikf/tik4net

Mocking commands

AsafMag opened this issue · 1 comments

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?

Hi,
reasons for this approach:

  • Extensibility (everybody is able to create his own connection extension - e.q. extension in EthernetMonitorclass.
  • 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 with CQS. This facade itself is controller (from my perspective) and should not be unit-tested.
  • Mock whole ITikConnection and ITikCommand (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