JetBrains / YouTrackSharp

.NET Standard 2.0 Library to access YouTrack API.
https://www.jetbrains.com/youtrack
Apache License 2.0
134 stars 105 forks source link

No interfaces of classes in solution - needed for mocking #78

Closed ghost closed 6 years ago

ghost commented 6 years ago

What we want to do...

is to make unit tests base on YouTrackSharp classes like IssuesService and so I don't want to call server too often. Instead I would rather use interface of the class to mock it in any mocking package so no changes are applied during tests on company's YouTrack.

The problem is...

that there are no interfaces what is pretty dissapointing and there are few ways around to solve this but they are not prefered as they use tricks instead of clear logic.

Solutions...

that we identified (yet to test) are:

  1. Create test project on YouTrack, and add role with access only to this project so it doesn't mess any other projects by accident | | | Problem: connecting to server
  2. Include the code in our repository and create interface ourselves | | | Problem: tracking upstream changes
  3. Create own library | | | Problem: not reliable solution
  4. Mocking HttpClient | | | Problem: too low level, tests dependent on API changes

Action...

that I took was creating those interfaces and commiting to develop branch.

Any help or advise would be apprieciated, Krzysztof Nowicki

maartenba commented 6 years ago

May I propose solution # 5?

  1. Extract interfaces, create a pull request

That would be very welcomed, and we're definitely open to merging it in :-)

ghost commented 6 years ago

79

To not mess things up too much we just added interfaces that we needed for our mocking purposes. Hope to see it running soon enough ;-) Thanks for the answer.

/kn

maartenba commented 6 years ago

Thanks! Making a few additions. Would it matter if e.g. IIssue was not merged? Or would you need those simple objects as interfaces as well?

ghost commented 6 years ago

@maartenba we won't mind it. We will manage without IIssue. All we need are interfaces from services classes I added. IIssue was "just in case" addition and we won't really have to mock it. Sorry for the inconvenience!

maartenba commented 6 years ago

No worries. Will merge it into develop and release an alpha build on NuGet later on which you can test with. Thanks for your contribution and suggestion!

maartenba commented 6 years ago

(and because introducing these interfaces means version should go to 4.0, I will also target .NET Standard 2.0)

ghost commented 6 years ago

Glad to have this issue solved! Thank you 👍

maartenba commented 6 years ago

There you go :) https://github.com/JetBrains/YouTrackSharp/releases/tag/4.0.0-develop-201808210153 (pushed to NuGet, should be visible there soon, too)