Example #1
0
        public void ConnectionStatusChangedEvent()
        {
            string input = "001 :Welcome\r\n";

            var writer = new IO.Helpers.DummyRawMessageWriter();

            using(var stringReader = new StringReader(input))
            using(var reader = new RawMessageTextReader(stringReader)) {
                using(var client = new Ondit.Client.Client(reader, writer)) {
                    ConnectionStatus? connectionStatusChanged = null;

                    client.ConnectionStatusChanged += (sender, e) => {
                        connectionStatusChanged = e.NewStatus;
                    };

                    Assert.AreEqual(ConnectionStatus.NotConnected, client.ConnectionStatus);

                    client.Connect();

                    Assert.AreEqual(ConnectionStatus.Connecting, connectionStatusChanged);
                    Assert.AreEqual(ConnectionStatus.Connecting, client.ConnectionStatus);

                    client.HandleMessage();

                    Assert.AreEqual(ConnectionStatus.Connected, connectionStatusChanged);
                    Assert.AreEqual(ConnectionStatus.Connected, client.ConnectionStatus);
                }
            }
        }
Example #2
0
        public void MessageReceive()
        {
            ICollection<RawMessage> expectedOutput = new List<RawMessage>();

            expectedOutput.Add(new RawMessage("THEGAME", "a", "b", "cd ef g"));

            string input = string.Join("\r\n", expectedOutput.Select((message) => message.ToString()).ToArray()) + "\r\n";

            var writer = new IO.Helpers.DummyRawMessageWriter();

            using(var stringReader = new StringReader(input))
            using(var reader = new RawMessageTextReader(stringReader)) {
                using(var client = new Ondit.Client.Client(reader, writer)) {
                    foreach(var expectedMessage in expectedOutput) {
                        var receivedMessage = client.HandleMessage();

                        Assert.AreEqual(expectedMessage, receivedMessage);
                    }
                }
            }
        }
Example #3
0
        public void MessageReceivedEvent()
        {
            ICollection<RawMessage> expectedOutput = new List<RawMessage>();

            expectedOutput.Add(new RawMessage("THEGAME", "a", "b", "cd ef g"));

            string input = string.Join("\r\n", expectedOutput.Select((message) => message.ToString()).ToArray()) + "\r\n";

            IEnumerator<RawMessage> messageChecker = expectedOutput.GetEnumerator();

            var writer = new IO.Helpers.DummyRawMessageWriter();

            using(var stringReader = new StringReader(input))
            using(var reader = new RawMessageTextReader(stringReader)) {
                using(var client = new Ondit.Client.Client(reader, writer)) {
                    client.RawMessageReceived += delegate(object sender, RawMessageEventArgs e) {
                        bool elementExists = messageChecker.MoveNext();

                        Assert.IsTrue(elementExists);
                        Assert.AreEqual(messageChecker.Current, e.Message);
                    };

                    foreach(var expectedMessage in expectedOutput) {
                        client.HandleMessage();
                    }
                }
            }
        }