public void TestMessageFactoryCommand() { IMessageFactory messageFactory = new MessageFactory(); IMessage message; // Command without prefix message = messageFactory.CreateMessage("DEADBEEF", "QUIT"); Assert.AreEqual("QUIT", message.Command); // Command with prefix message = messageFactory.CreateMessage("DEADBEEF", ":nick!user@host QUIT"); Assert.AreEqual("QUIT", message.Command); // Command with parameters message = messageFactory.CreateMessage("DEADBEEF", "QUIT :reason"); Assert.AreEqual("QUIT", message.Command); // Command with prefix and parameters message = messageFactory.CreateMessage("DEADBEEF", ":nick!user@host QUIT :reason"); Assert.AreEqual("QUIT", message.Command); // Command with invalid prefix message = messageFactory.CreateMessage("DEADBEEF", ":nick!user QUIT"); Assert.AreEqual("QUIT", message.Command); }
public void TestMessageFactoryPrefix() { IMessageFactory messageFactory = new MessageFactory(); IMessage message; // Nick-only prefix message = messageFactory.CreateMessage("DEADBEEF", ":nick QUIT"); Assert.AreEqual("nick", message.Prefix.Nick); Assert.AreEqual(string.Empty, message.Prefix.UserName); Assert.AreEqual(string.Empty, message.Prefix.HostName); Assert.IsTrue(message.Prefix.Exists); // Nick and user prefix, invalid as prefix cannot just have a nick and user message = messageFactory.CreateMessage("DEADBEEF", ":nick!~user QUIT"); Assert.AreEqual(string.Empty, message.Prefix.Nick); Assert.AreEqual(string.Empty, message.Prefix.UserName); Assert.AreEqual(string.Empty, message.Prefix.HostName); Assert.IsFalse(message.Prefix.Exists); // Nick and user prefix, invalid as prefix cannot just have a nick and user message = messageFactory.CreateMessage("DEADBEEF", ":[email protected] QUIT"); Assert.AreEqual("nick", message.Prefix.Nick); Assert.AreEqual("~user", message.Prefix.UserName); Assert.AreEqual("website.com", message.Prefix.HostName); Assert.IsTrue(message.Prefix.Exists); // Nick and user prefix, invalid as prefix cannot just have a nick and user message = messageFactory.CreateMessage("DEADBEEF", ":[email protected] QUIT"); Assert.AreEqual("nick", message.Prefix.Nick); Assert.AreEqual("~user", message.Prefix.UserName); Assert.AreEqual("127.0.0.1", message.Prefix.HostName); Assert.IsTrue(message.Prefix.Exists); }
public void TestMessageFactoryParameters() { IMessageFactory messageFactory = new MessageFactory(); IMessage message; // Message with no parameters message = messageFactory.CreateMessage("DEADBEEF", "QUIT"); Assert.AreEqual(0, message.Parameters.Count()); // Message with one non-trailing parameter message = messageFactory.CreateMessage("DEADBEEF", "JOIN #channel1,#channel2"); Assert.AreEqual(1, message.Parameters.Count()); Assert.AreEqual("#channel1,#channel2", message.Parameters.ElementAt(0)); // Message with two non-trailing parameters message = messageFactory.CreateMessage("DEADBEEF", "JOIN #channel1,#channel2 key1,key2"); Assert.AreEqual(2, message.Parameters.Count()); Assert.AreEqual("#channel1,#channel2", message.Parameters.ElementAt(0)); Assert.AreEqual("key1,key2", message.Parameters.ElementAt(1)); // Message with trailing parameter message = messageFactory.CreateMessage("DEADBEEF", "QUIT :reason with spaces"); Assert.AreEqual(1, message.Parameters.Count()); Assert.AreEqual("reason with spaces", message.Parameters.ElementAt(0)); // Message with three parameters and trailing parameter message = messageFactory.CreateMessage("DEADBEEF", "USER username usermode * :real name"); Assert.AreEqual(4, message.Parameters.Count()); Assert.AreEqual("username", message.Parameters.ElementAt(0)); Assert.AreEqual("usermode", message.Parameters.ElementAt(1)); Assert.AreEqual("*", message.Parameters.ElementAt(2)); Assert.AreEqual("real name", message.Parameters.ElementAt(3)); }
public void TestMessageFactoryEmptyMessage() { IMessageFactory messageFactory = new MessageFactory(); messageFactory.CreateMessage("DEADBEEF", ""); }
public void TestMessageFactoryServer() { IMessageFactory messageFactory = new MessageFactory(); IMessage message; message = messageFactory.CreateMessage("DEADBEEF", "QUIT"); Assert.AreEqual("DEADBEEF", message.Server); message = messageFactory.CreateMessage("FEEBDAED", "QUIT"); Assert.AreEqual("FEEBDAED", message.Server); }