public void CloneTest() { QuoteBotConfig config1 = new QuoteBotConfig(); QuoteBotConfig config2 = config1.Clone(); // Equivalent, but not same instance. Assert.AreEqual(config1, config2); Assert.AreNotSame(config1, config2); }
public void DefaultConfigTest() { QuoteBotConfig defaultConfig = new QuoteBotConfig(); QuoteBotConfig loadedConfig = XmlLoader.LoadConfig( Path.Combine(quoteBotPluginDir, "Config", "SampleQuoteBotConfig.xml") ); Assert.AreEqual(defaultConfig, loadedConfig); }
public void TestSetup() { this.quoteConfig = new QuoteBotConfig(); // Pretend someone is VERY generious with their regexes (.* instead of \S+ for user, // has no mimimum size, no number checks for IDs). this.quoteConfig.AddCommand = @"!quote\s+add\s+\<(?<user>.*)\>\s+(?<quote>.*)"; this.quoteConfig.DeleteCommand = @"!quote\s+delete\s+(?<id>.*)"; this.quoteConfig.GetCommand = @"!quote\s+(get)?\s*(?<id>.*)"; this.uut = new QuoteBotParser(this.quoteConfig); }
public void XmlLoadTest() { QuoteBotConfig expectedConfig = new QuoteBotConfig(); expectedConfig.AddCommand = @"^@quote\s+add\s+\<(?<user>\S+)\>\s+(?<quote>.+)"; expectedConfig.DeleteCommand = @"^@quote\s+delete\s+(?<id>\d+)"; expectedConfig.RandomCommand = @"^@quote\s+random"; expectedConfig.GetCommand = @"^@quote\s+(get)?\s*(?<id>\d+)"; QuoteBotConfig loadedConfig = XmlLoader.LoadConfig( Path.Combine(quoteBotTestDir, "TestFiles", "GoodConfig.xml") ); Assert.AreEqual(expectedConfig, loadedConfig); }
public void ValidationTest() { QuoteBotConfig config = new QuoteBotConfig(); // Default config should not throw. Assert.DoesNotThrow(() => config.Validate()); // Start removing things. config.AddCommand = null; Assert.Throws <ValidationException>(() => config.Validate()); config.AddCommand = string.Empty; Assert.Throws <ValidationException>(() => config.Validate()); config.AddCommand = " "; Assert.Throws <ValidationException>(() => config.Validate()); config = new QuoteBotConfig(); config.DeleteCommand = null; Assert.Throws <ValidationException>(() => config.Validate()); config.DeleteCommand = string.Empty; Assert.Throws <ValidationException>(() => config.Validate()); config.DeleteCommand = " "; Assert.Throws <ValidationException>(() => config.Validate()); config = new QuoteBotConfig(); config.RandomCommand = null; Assert.Throws <ValidationException>(() => config.Validate()); config.RandomCommand = string.Empty; Assert.Throws <ValidationException>(() => config.Validate()); config.RandomCommand = " "; Assert.Throws <ValidationException>(() => config.Validate()); config = new QuoteBotConfig(); config.GetCommand = null; Assert.Throws <ValidationException>(() => config.Validate()); config.GetCommand = string.Empty; Assert.Throws <ValidationException>(() => config.Validate()); config.GetCommand = " "; Assert.Throws <ValidationException>(() => config.Validate()); config = new QuoteBotConfig(); }
public void EqualsTest() { QuoteBotConfig config1 = new QuoteBotConfig(); QuoteBotConfig config2 = new QuoteBotConfig(); Assert.AreEqual(config1, config2); Assert.AreEqual(config2, config1); Assert.AreEqual(config1.GetHashCode(), config2.GetHashCode()); Assert.IsFalse(config1.Equals(2)); Assert.IsFalse(config1.Equals(null)); // Start changing things: config1.AddCommand += "1"; Assert.AreNotEqual(config1, config2); Assert.AreNotEqual(config2, config1); Assert.AreNotEqual(config1.GetHashCode(), config2.GetHashCode()); config1 = new QuoteBotConfig(); config1.DeleteCommand += "1"; Assert.AreNotEqual(config1, config2); Assert.AreNotEqual(config2, config1); Assert.AreNotEqual(config1.GetHashCode(), config2.GetHashCode()); config1 = new QuoteBotConfig(); config1.RandomCommand += "1"; Assert.AreNotEqual(config1, config2); Assert.AreNotEqual(config2, config1); Assert.AreNotEqual(config1.GetHashCode(), config2.GetHashCode()); config1 = new QuoteBotConfig(); config1.GetCommand += "1"; Assert.AreNotEqual(config1, config2); Assert.AreNotEqual(config2, config1); Assert.AreNotEqual(config1.GetHashCode(), config2.GetHashCode()); config1 = new QuoteBotConfig(); }