public void InvocationMessageParseTest(string protocolName, string invocationId, string target, object[] arguments)
        {
            var                     message  = new AspNetCore.SignalR.Protocol.InvocationMessage(invocationId, target, arguments);
            IHubProtocol            protocol = protocolName == "json" ? (IHubProtocol) new JsonHubProtocol() : new MessagePackHubProtocol();
            var                     bytes    = new ReadOnlySequence <byte>(protocol.GetMessageBytes(message));
            ReadOnlySequence <byte> payload;

            if (protocolName == "json")
            {
                TextMessageParser.TryParseMessage(ref bytes, out payload);
            }
            else
            {
                BinaryMessageParser.TryParseMessage(ref bytes, out payload);
            }
            var serverlessProtocol = protocolName == "json" ? (IServerlessProtocol) new JsonServerlessProtocol() : new MessagePackServerlessProtocol();

            Assert.True(serverlessProtocol.TryParseMessage(ref payload, out var parsedMessage));
            var invocationMessage = (InvocationMessage)parsedMessage;

            Assert.Equal(1, invocationMessage.Type);
            Assert.Equal(invocationId, invocationMessage.InvocationId);
            Assert.Equal(target, invocationMessage.Target);
            var expected = JsonConvert.SerializeObject(arguments);
            var actual   = JsonConvert.SerializeObject(invocationMessage.Arguments);

            Assert.Equal(expected, actual);
        }
Example #2
0
        public void SingleBinaryMessage()
        {
            var data = new ReadOnlySequence <byte>(_binaryInput);

            if (!BinaryMessageParser.TryParseMessage(ref data, out _))
            {
                throw new InvalidOperationException("Failed to parse");
            }
        }
        public void SingleBinaryMessage()
        {
            ReadOnlySpan <byte> buffer = _binaryInput;

            if (!BinaryMessageParser.TryParseMessage(ref buffer, out _))
            {
                throw new InvalidOperationException("Failed to parse");
            }
        }
Example #4
0
        private static bool TryGetPayload(IHubProtocol protocol, InvocationMessage invocationMessage, out ReadOnlySequence <byte> payload)
        {
            var buffer = new ReadOnlySequence <byte>(protocol.GetMessageBytes(invocationMessage));

            if (protocol is JsonHubProtocol)
            {
                return(TextMessageParser.TryParseMessage(ref buffer, out payload));
            }
            else if (protocol is MessagePackHubProtocol)
            {
                return(BinaryMessageParser.TryParseMessage(ref buffer, out payload));
            }

            throw new ArgumentException($"{protocol.GetType()} is not supported");
        }
        public async Task SignalRInvocationMethodExecutorTest(string protocolName)
        {
            var resolver       = new SignalRRequestResolver(false);
            var methodExecutor = new SignalRInvocationMethodExecutor(resolver, new ExecutionContext {
                Executor = _triggeredFunctionExecutor
            });
            var hub          = Guid.NewGuid().ToString();
            var category     = Guid.NewGuid().ToString();
            var @event       = Guid.NewGuid().ToString();
            var connectionId = Guid.NewGuid().ToString();
            var arguments    = new object[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() };

            var message     = new Microsoft.AspNetCore.SignalR.Protocol.InvocationMessage(Guid.NewGuid().ToString(), @event, arguments);
            var protocol    = protocolName == "json" ? (IHubProtocol) new JsonHubProtocol() : new MessagePackHubProtocol();
            var contentType = protocolName == "json" ? Constants.JsonContentType : Constants.MessagePackContentType;
            var bytes       = new ReadOnlySequence <byte>(protocol.GetMessageBytes(message));
            ReadOnlySequence <byte> payload;

            if (protocolName == "json")
            {
                TextMessageParser.TryParseMessage(ref bytes, out payload);
            }
            else
            {
                BinaryMessageParser.TryParseMessage(ref bytes, out payload);
            }

            var request = TestHelpers.CreateHttpRequestMessage(hub, category, @event, connectionId, contentType: contentType, content: payload.ToArray());
            await methodExecutor.ExecuteAsync(request);

            var result      = await _triggeredFunctionDataTcs.Task;
            var triggerData = (SignalRTriggerEvent)result.TriggerValue;

            Assert.NotNull(triggerData.TaskCompletionSource);
            Assert.Equal(hub, triggerData.Context.Hub);
            Assert.Equal(category, triggerData.Context.Category);
            Assert.Equal(@event, triggerData.Context.Event);
            Assert.Equal(connectionId, triggerData.Context.ConnectionId);
            Assert.Equal(hub, triggerData.Context.Hub);
            Assert.Equal(arguments, triggerData.Context.Arguments);
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.Title = "JAWE";

            var something = new ParameterValidator(typeof(TestMessage));

            Console.WriteLine(something);

            byte[] data         = { 0x1, 0x1 };
            var    binaryParser = new BinaryMessageParser();
            var    result       = binaryParser.Parse(data);

            Console.WriteLine(result);


            //var processor = new WrMessageProcessor();
            //var wrParser = new WrStrMessageParser(processor);
            //var result = wrParser.Parse("0 1010");
            //Console.WriteLine(result);


            Console.ReadLine();
        }