Exemplo n.º 1
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);
        }
Exemplo n.º 2
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>();
        }
Exemplo n.º 3
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();
        }