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); } } }
private void Connection(string host, int port) { client = new Client(host, port); client.SynchronizingObject = this; client.RawMessageSent += MessageSent; client.RawMessageReceived += MessageReceived; client.ConversationMessageReceived += ConversationMessageReceived; client.Connect(); client.WaitForConnected(); if(client.ConnectionStatus != ConnectionStatus.Connected) { conversation.Text += string.Format(@"Could not connect to {0} on port {1}." + Environment.NewLine, host, port); return; } clientThread = new Thread(() => { while(client != null) { client.HandleMessageBlock(); } }); clientThread.Start(); }
private void connect_Click(object sender, EventArgs e) { if(client != null) { client.Dispose(); client = null; } if(clientThread != null) { clientThread.Abort(); clientThread = null; } string host = server.Text; int portNumber = int.Parse(port.Text); Connection(host, portNumber); }
void Run() { using(client = new Client("irc.slagg.org", 6667)) { Console.WriteLine("Connecting..."); client.Connect(); client.WaitForConnected(); Console.WriteLine("Connected!"); LoadPlugins(); client.JoinChannel("#test"); while(client.ConnectionStatus == ConnectionStatus.Connected) { client.HandleMessageBlock(); } } }
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); } } } }
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(); } } } }
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); } } }
public void MessageSend() { ICollection<RawMessage> inputMessages = new List<RawMessage>(); inputMessages.Add(new RawMessage("THEGAME", "a", "b", "cd ef g")); string expectedOutput = string.Join("\r\n", inputMessages.Select((message) => message.ToString()).ToArray()) + "\r\n"; var reader = new IO.Helpers.DummyRawMessageReader(); using(var stringWriter = new StringWriter()) using(var writer = new RawMessageTextWriter(stringWriter)) { using(var client = new Ondit.Client.Client(reader, writer)) { foreach(var message in inputMessages) { client.SendMessage(message); } Assert.AreEqual(expectedOutput, stringWriter.ToString()); } } }