Exemplo n.º 1
0
        public async Task SendAsyncMiddlewareIsCalledOnArbitrarySendMessageAsync(string text)
        {
            var            socket           = new LinkedFakeSocket();
            ILoggerFactory loggerFactory    = new LoggerFactory();
            var            webSocketChannel = new WebSocketChannel(socket, new [] { new Base64Middleware() }, loggerFactory);
            await webSocketChannel.SendMessageAsync(new Message
            {
                Data        = text,
                MessageType = MessageType.Text
            });

            var encodedMessage = await socket.ReadToEndAsync();

            var message = MessageSerializer.Deserialize <Message>(Encoding.UTF8.GetString(Convert.FromBase64String(encodedMessage)));

            Assert.Equal(message.Data, text);
        }
Exemplo n.º 2
0
        public async Task SendAsyncMiddlewareCalledInOrderOnArbitrarySendMessageAsync(string text)
        {
            var middlewares = new List <IMiddleware>();

            for (int i = 0; i < 10; i++)
            {
                middlewares.Add(new IncrementalMiddleware());
            }

            var            socket           = new LinkedFakeSocket();
            ILoggerFactory loggerFactory    = new LoggerFactory();
            var            webSocketChannel = new WebSocketChannel(socket, middlewares, loggerFactory);
            await webSocketChannel.SendMessageAsync(new Message
            {
                Data        = text,
                MessageType = MessageType.Text
            });

            foreach (var m in middlewares)
            {
                var middleware = (IncrementalMiddleware)m;
                Assert.Equal(middleware.Id, middleware.CalledAt);
            }
        }