Esempio n. 1
0
        public void ShouldReadRequestsCorrectly()
        {
            var converter = new MessageConverter();

            var requestByteString =
                "42696E400000002F000000010000000D417574686F72697A6174696F6E0000001642617369632064326C72615470775A57527059513D3D000000250000001273797374656D2E6C6973744D6574686F6473000000010000000300000003426C61";

            var requestStream = BinaryUtils.CreateByteStream(requestByteString);
            var requestReader = new HmBinaryMessageReader(requestStream);
            var messageBuilder = new MessageBuilder();

            converter.Convert(requestReader, messageBuilder);
            var request = messageBuilder.Result.ShouldBeOfType<Request>();
            request.Headers.Count.ShouldBe(1);
            var authHeader = string.Concat("Basic ", Convert.ToBase64String(Encoding.UTF8.GetBytes("wiki:pedia")));
            request.Headers.ShouldContainKeyAndValue("Authorization", authHeader);
            request.Method.ShouldBe("system.listMethods");
            request.Parameters.Count.ShouldBe(1);
            request.Parameters.First().ShouldBe("Bla");
        }
Esempio n. 2
0
        public void WorksWithRequestResponseProtocol()
        {
            var request = new Request
            {
                Method = "test",
                Parameters = { "param1", new List<object> { "nested param" } }
            };

            var reader = new MessageReader(request);

            var converter = new MessageConverter();
            var messageBuilder = new MessageBuilder();
            converter.Convert(reader, messageBuilder);

            var request2 = messageBuilder.Result.ShouldBeOfType<Request>();
            request2.Method.ShouldBe("test");
            request2.Parameters.Count.ShouldBe(2);
            request2.Parameters.First().ShouldBe("param1");

            var param2 = request2.Parameters.Skip(1).First().ShouldBeAssignableTo<ICollection<object>>();
            param2.First().ShouldBe("nested param");
        }