Exemplo n.º 1
0
        public void OnState_Failed_FailCallbackCalled()
        {
            // Arrange
            AcknowledgementProcessor        target    = new AcknowledgementProcessor();
            List <Tuple <bool, ErrorInfo> > callbacks = new List <Tuple <bool, ErrorInfo> >();
            ErrorInfo error = new ErrorInfo("reason", 123);

            // Act
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 0)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 1)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 2)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.OnStateChanged(new States.ConnectionFailedState(null, error));

            // Assert
            Assert.Equal(3, callbacks.Count);
            Assert.True(callbacks.TrueForAll(c => !c.Item1));                               // Nack
            Assert.True(callbacks.TrueForAll(c => object.ReferenceEquals(c.Item2, error))); // Error
        }
Exemplo n.º 2
0
        public void WhenSendingMessage_AckCallbackCalled_ForMultipleMessages()
        {
            // Arrange
            AcknowledgementProcessor        target    = new AcknowledgementProcessor(new Connection(new AblyRealtime(ValidKey)));
            List <Tuple <bool, ErrorInfo> > callbacks = new List <Tuple <bool, ErrorInfo> >();

            // Act
            target.QueueIfNecessary(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 0)
                                                                                                                        {
                                                                                                                            callbacks.Add(Tuple.Create(ack, err));
                                                                                                                        }
                                    });
            target.QueueIfNecessary(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 1)
                                                                                                                        {
                                                                                                                            callbacks.Add(Tuple.Create(ack, err));
                                                                                                                        }
                                    });
            target.QueueIfNecessary(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 2)
                                                                                                                        {
                                                                                                                            callbacks.Add(Tuple.Create(ack, err));
                                                                                                                        }
                                    });
            target.OnMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Ack)
            {
                MsgSerial = 0, Count = 3
            });

            // Assert
            Assert.Equal(3, callbacks.Count);
            Assert.True(callbacks.TrueForAll(c => c.Item1));         // Ack
            Assert.True(callbacks.TrueForAll(c => c.Item2 == null)); // No error
        }
Exemplo n.º 3
0
        public void OnState_Connected_MsgSerialReset()
        {
            // Arrange
            Mock <IConnectionContext> context = new Mock <IConnectionContext>();

            context.SetupGet(c => c.Connection).Returns(new Realtime.Connection(new Mock <IConnectionManager>().Object));

            AcknowledgementProcessor target         = new AcknowledgementProcessor();
            ProtocolMessage          targetMessage1 = new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test");
            ProtocolMessage          targetMessage2 = new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test");
            ProtocolMessage          targetMessage3 = new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test");
            ProtocolMessage          targetMessage4 = new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test");

            // Act
            target.SendMessage(targetMessage1, null);
            target.SendMessage(targetMessage2, null);
            target.OnStateChanged(new States.ConnectionConnectedState(context.Object, new ConnectionInfo("", 0, "")));
            target.SendMessage(targetMessage3, null);
            target.SendMessage(targetMessage4, null);

            // Assert
            Assert.Equal(0, targetMessage1.MsgSerial);
            Assert.Equal(1, targetMessage2.MsgSerial);
            Assert.Equal(0, targetMessage3.MsgSerial);
            Assert.Equal(1, targetMessage4.MsgSerial);
        }
Exemplo n.º 4
0
        public void WhenSendingMessage_NackCallbackCalled_ForMultipleMessages_WithError()
        {
            // Arrange
            AcknowledgementProcessor        target    = new AcknowledgementProcessor();
            List <Tuple <bool, ErrorInfo> > callbacks = new List <Tuple <bool, ErrorInfo> >();
            ErrorInfo error = new ErrorInfo("reason", 123);

            // Act
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 0)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 1)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 2)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.OnMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Nack)
            {
                MsgSerial = 0, Count = 3, Error = error
            });

            // Assert
            Assert.Equal(3, callbacks.Count);
            Assert.True(callbacks.TrueForAll(c => !c.Item1));                               // Nack
            Assert.True(callbacks.TrueForAll(c => object.ReferenceEquals(c.Item2, error))); // Error
        }
Exemplo n.º 5
0
        public void WhenReceiveMessage_HandleAction(ProtocolMessage.MessageAction action)
        {
            // Arrange
            AcknowledgementProcessor target = new AcknowledgementProcessor();

            // Act
            bool result = target.OnMessageReceived(new ProtocolMessage(action));

            // Assert
            Assert.True(result);
        }
Exemplo n.º 6
0
        public void WhenSendingMessage_MsgSerialNotIncremented(ProtocolMessage.MessageAction messageAction)
        {
            // Arrange
            AcknowledgementProcessor target         = new AcknowledgementProcessor();
            ProtocolMessage          targetMessage1 = new ProtocolMessage(messageAction, "Test");
            ProtocolMessage          targetMessage2 = new ProtocolMessage(messageAction, "Test");
            ProtocolMessage          targetMessage3 = new ProtocolMessage(messageAction, "Test");

            // Act
            target.SendMessage(targetMessage1, null);
            target.SendMessage(targetMessage2, null);
            target.SendMessage(targetMessage3, null);

            // Assert
            Assert.Equal(0, targetMessage1.MsgSerial);
            Assert.Equal(0, targetMessage2.MsgSerial);
            Assert.Equal(0, targetMessage3.MsgSerial);
        }
Exemplo n.º 7
0
        public void WhenSendingMessage_NackCallbackCalled()
        {
            // Arrange
            AcknowledgementProcessor        target    = new AcknowledgementProcessor();
            List <Tuple <bool, ErrorInfo> > callbacks = new List <Tuple <bool, ErrorInfo> >();
            long msgSerial = 0;

            // Act
            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 0)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.OnMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Nack)
            {
                MsgSerial = msgSerial++, Count = 1
            });

            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 1)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.OnMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Nack)
            {
                MsgSerial = msgSerial++, Count = 1
            });

            target.SendMessage(new ProtocolMessage(ProtocolMessage.MessageAction.Message, "Test"), (ack, err) => { if (callbacks.Count == 2)
                                                                                                                   {
                                                                                                                       callbacks.Add(Tuple.Create(ack, err));
                                                                                                                   }
                               });
            target.OnMessageReceived(new ProtocolMessage(ProtocolMessage.MessageAction.Nack)
            {
                MsgSerial = msgSerial++, Count = 1
            });

            // Assert
            Assert.Equal(3, callbacks.Count);
            Assert.True(callbacks.TrueForAll(c => !c.Item1));        // Nack
            Assert.True(callbacks.TrueForAll(c => c.Item2 != null)); // Error
        }
Exemplo n.º 8
0
 public AckProtocolTests(ITestOutputHelper output) : base(output)
 {
     _connection = new Connection(new AblyRealtime(ValidKey));
     _connection.Initialise();
     _ackProcessor = new AcknowledgementProcessor(_connection);
 }