Ejemplo n.º 1
0
        public void Can_reconnect()
        {
            var reconnected = false;
            var client = new DdpClient(_socket, _helper);
            client.DdpReconnect += () => reconnected = true;

            var firstMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(new
            {
                session = AutoFixture.Create<string>(),
                msg = "connected"
            }));

            var secondMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(new
            {
                session = AutoFixture.Create<string>(),
                msg = "connected"
            }));

            // Act
            _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), firstMessage);
            _socket.Closed += Raise.Event<EventHandler>();
            _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), secondMessage);

            // Assert
            _socket.Received().Open();
            reconnected.Should().BeTrue();
        }
Ejemplo n.º 2
0
        private void SocketOnMessage(object sender, PortableMessageReceivedEventArgs messageEventArgs)
        {
            var json = messageEventArgs.Message;
            var data = JObject.Parse(json);

            _logger.LogDebug($"RECIEVED: {JsonConvert.SerializeObject(data, Formatting.Indented)}");

            var isRocketMessage = data?["msg"] != null;

            if (isRocketMessage)
            {
                var type = data["msg"].ToObject <string>();
                InternalHandle(type, data);
                OnDataReceived(type, data);
            }
        }
Ejemplo n.º 3
0
        public void Connecting_should_set_session()
        {
            var client = new DdpClient(_socket, _helper);

            var sessionId = AutoFixture.Create<string>();
            var message = new
            {
                session = sessionId,
                msg = "connected"
            };
            var jsonMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(message));

            // Act
            _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), jsonMessage);

            // Assert
            client.SessionId.Should().Be(sessionId);
        }
Ejemplo n.º 4
0
        public void Can_unsubscribe()
        {
            var client = new DdpClient(_socket, _helper);

            var subId = AutoFixture.Create<string>();
            var message = new
            {
                id = subId,
                msg = "nosub"
            };
            var jsonMessage = new PortableMessageReceivedEventArgs(JsonConvert.SerializeObject(message));

            // Act
            var task = client.UnsubscribeAsync(subId, TimeoutToken);
            _socket.MessageReceived += Raise.Event<EventHandler<PortableMessageReceivedEventArgs>>(new object(), jsonMessage);

            Action action = async () => await task;

            // Assert
            action.ShouldNotThrow<OperationCanceledException>();
        }