Has anyone successfully mocked the Socket class in .NET?

后端 未结 5 1066
深忆病人
深忆病人 2021-01-02 08:38

I\'m trying to mock out the System.net.Sockets.Socket class in C# - I tried using NUnit mocks but it can\'t mock concrete classes. I also tried using Rhino Mocks but it see

5条回答
  •  情书的邮戳
    2021-01-02 08:42

    The reason you get a SocketException when you call the Send method is because Send is not an overridable method. For RhinoMocks to be able to mock the behavior of a property or method, it has to either be defined in an interface (which we then create our mock off) or is overridable.

    Your only solution to this is to create a mockable wrapper class (as suggested by thinkzig).

提交回复
热议问题