Exemple #1
0
        public async Task send_and_receive()
        {
            var timeout = new CancellationTokenSource();

            timeout.CancelAfter(60.Seconds());

            JsonSerialization.RegisterType("socket-pong", typeof(SocketPong));

            using (var client = new ClientWebSocket())
            {
                await client.ConnectAsync("ws://127.0.0.1:3010".ToUri(), timeout.Token);

                var outgoing = new SocketPing {
                    Name = "Kareem Hunt"
                }.ToCleanJson();
                await client.SendMessageAsync(outgoing);

                var buffer = new ArraySegment <byte>(new byte[1000]);

                var result = await client.ReceiveAsync(buffer, timeout.Token);

                var json = buffer.ReadString(result);
                JsonSerialization.DeserializeMessage(json)
                .ShouldBeOfType <SocketPong>()
                .Name.ShouldBe("Kareem Hunt");
            }
        }
        public void can_pick_up_the_type_of_a_client_message_from_the_json_bodyy()
        {
            var message = new RunSpec {
                id = "embeds"
            };
            var json = JsonSerialization.ToCleanJson(message);

            var deserialized = JsonSerialization.DeserializeMessage(json)
                               .ShouldBeOfType <RunSpec>();

            deserialized.id.ShouldBe("embeds");
            deserialized.ShouldNotBeTheSameAs(message);
        }