Giter Club home page Giter Club logo

Comments (4)

vtortola avatar vtortola commented on August 16, 2024

How would you unit test the TcpListener class? :)

This is a component that you should use to fulfil your contracts without exposing it, and without leaking its implementation details to other parts of your application.

This component is already unit tested, and in your tests, you should mock whatever implementation uses it.

from websocketlistener.

ramlongcat avatar ramlongcat commented on August 16, 2024

I don't want to unit test your library which as you said is already unit tested.
My idea was more like having the WebSocketListener implement a IWebSocketListener interface I could mock in my unit tests. Right now the WebSocketListener is sealed and has no virtual methods so it's hard for me to simulate a case where for example the ReadStringAsync method returns a specific string I'm looking for...

from websocketlistener.

vtortola avatar vtortola commented on August 16, 2024

Just think about WebSocketListener like you would do about TcpListener. The right way of using it, is to have a wrapper class that implements one of your interfaces. That interface can be mocked and they you can test what happens when you receive a specific string. If in the future, you want to move to System.Net.WebSockets, you would just create a new implementation of your custom interface, and replace the one that wraps WebSocketListener; then you would have no dependency on my interfaces.

Cheers.

from websocketlistener.

ramlongcat avatar ramlongcat commented on August 16, 2024

yeah that's what i've done, it's just more painful.
TcpListener inability to be mocked is an issue, not a feature though :)
I'll mark this issue as solved.

from websocketlistener.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.