Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking commands #54

Open
AsafMag opened this issue Nov 15, 2018 · 1 comment
Open

Mocking commands #54

AsafMag opened this issue Nov 15, 2018 · 1 comment

Comments

@AsafMag
Copy link

AsafMag commented Nov 15, 2018

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
Copy link
Owner

danikf commented Nov 17, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants