예제 #1
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();
                    }
                }
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
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);
                    }
                }
            }
        }
예제 #4
0
        public void MessageSentEvent()
        {
            ICollection<RawMessage> messages = new List<RawMessage>();

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

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

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

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

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

                foreach(var message in messages) {
                    client.SendMessage(message);
                }
            }
        }