kerryjiang / SuperWebSocket

SuperWebSocket is a .NET implementation of WebSocket server.
Apache License 2.0
505 stars 194 forks source link

JsonSubCommandBase.GetJsonMessage not virtual #8

Closed ISkomorokh closed 7 years ago

ISkomorokh commented 10 years ago

Hi Kerry Jiang!

Could you make JsonSubCommandBase.GetJsonMessage virtual? It would be easier to mock it.

Thanks.

kerryjiang commented 10 years ago

What's the purpose?

ISkomorokh commented 10 years ago

I'm writing a test which needs to check that WebSocketSession.Send(message) was called with correct data. This method is called withing JsonSubCommand<TWebSocketSession, TJsonCommandInfo>.SendJsonMessage by calling session.Send(GetJsonMessage(session, name, content)); So, I can mock session.send because it is virtual, but before calling send GetJsonMessage is called which is not virtual so I can't stub/mock it.

ISkomorokh commented 10 years ago

Also this would allow me to pass settings to serialization method to use camelCase with properties names.

            var serializedObject = JsonConvert.SerializeObject(content, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });