GetStream / stream-net

NET Client - Build Activity Feeds & Streams with GetStream.io

Home Page:https://getstream.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unit testing with StreamClient

reddy6ue opened this issue · comments

StreamClient is currently a bottleneck in unit testing. Can you consider making the public methods of the following classes virtual, or Extract interfaces for all public methods?

  • StreamClient
  • StreamFeed
  • BatchOperations

@Link512 any ideas on this?

Are you trying to test the integration with StreamClient or do you just want to ignore HttpCalls? If you want to ignore API calls we could add support to inject your own HttpClient into the library, and use a noop one for unit tests. In any case we are considering making the library easy to mock, but for now it is not a priority for development. Feel free to share any code from your side via PR if you already have something to make this work.

The quick and dirty idea is to make all public methods virtual in StreamClient, StreamFeed and BatchOperations. Then any StreamClient user can mock it themselves.

The other option is to extract three interfaces IStreamClient, IStreamFeed and IBatchOperations. Let me know which you prefer and I'll send a pull request.

      Are you trying to test the integration with StreamClient or do you just want to ignore HttpCalls? If you want to ignore API calls we could add support to inject your own HttpClient into the library, and use a noop one for unit tests. In any case we are considering making the library easy to mock, but for now it is not a priority for development. Feel free to share any code from your side via PR if you already have something to make this work.

I'm good with integration tests. They are fairly easy to write with the client as is. It's only unit tests that I need help with.

The quick and dirty idea is to make all public methods virtual in StreamClient, StreamFeed and BatchOperations. Then any StreamClient user can mock it themselves.

The other option is to extract three interfaces IStreamClient, IStreamFeed and IBatchOperations. Let me know which you prefer and I'll send a pull request.

I believe extracting interfaces is the cleaner way of doing this, so we should aim for that.

@Link512 @tbarbugli I created a pull request. Please review.

@reddy6ue i've merged the PR and published the changes to version 2.5.0 of the package

@Link512 Thanks. This works for me.