Has anyone successfully mocked the Socket class in .NET?

后端 未结 5 1055
深忆病人
深忆病人 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 09:06

    You'd better to create an interface and mock it in your test, and implement a wrapper class in your code, that forward all method calls to .NET socket as thinkzig said. Look at this link, it's same issue: How do you mock out the file system in C# for unit testing?

提交回复
热议问题