Files
MTSC/MTSC.UnitTests/RoutingModules/HelloWorldMessageConverter.cs
Alexandru Macocian 619992da80 Switched server resources to Slim.ServiceManager.
Changed HttpRoutingHandler to use the general Slim.ServiceManager.
Changed WebsocketRoutingHandler to a similar approach as HttpRoutingHandler.
Implemented IRunOnStartup interface for handlers.
2021-03-12 14:05:55 +01:00

28 lines
912 B
C#

using MTSC.Common.WebSockets;
using MTSC.Common.WebSockets.RoutingModules;
using System.Text;
namespace MTSC.UnitTests.RoutingModules
{
public class HelloWorldMessageConverter : IWebsocketMessageConverter<HelloWorldMessage>
{
public HelloWorldMessage ConvertFromWebsocketMessage(WebsocketMessage websocketMessage)
{
var str = Encoding.UTF8.GetString(websocketMessage.Data);
return new HelloWorldMessage
{
HelloWorld = str == "Hello world!"
};
}
public WebsocketMessage ConvertToWebsocketMessage(HelloWorldMessage message)
{
return new WebsocketMessage
{
Data = message.HelloWorld ? Encoding.UTF8.GetBytes("Hello world!") : Encoding.UTF8.GetBytes("Not hello world!"),
Opcode = WebsocketMessage.Opcodes.Text
};
}
}
}