public void itShouldLoadTokens() { var tokenKey1 = "TOKEN1"; var tokenValue1 = "TOKEN1VALUE"; var tokenKey2 = "TOKEN2"; var tokenValue2 = "TOKEN2VALUE"; var xmlConfig = $@" <commands> <tokens> <token key='{tokenKey1}' value='{tokenValue1}' /> <token key='{tokenKey2}' value='{tokenValue2}' /> </tokens> </commands> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var tokens = xmlConfigSource.Tokens; Assert.AreEqual(2, xmlConfigSource.Tokens.Count); var token = tokens.First(); Assert.IsNotNull(token); Assert.AreEqual(token.Key, tokenKey1); Assert.AreEqual(token.Value, tokenValue1); token = tokens.Last(); Assert.IsNotNull(token); Assert.AreEqual(token.Key, tokenKey2); Assert.AreEqual(token.Value, tokenValue2); }
public void itShouldNotLoadCommentedOutCommandConfigurations() { var xmlConfig = @" <commandCenter> <commands> <command> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> </command> <!-- <command> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> </command> --> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); Assert.AreEqual(1, cmdConfigs.Count); }
public void itShouldNotRaiseExceptionWhenCtorArgsHasNonctorArgsElements() { var xmlConfig = @" <commandCenter> <commands> <command> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> <ctorArgs> <ctorArg value='someValue'/> <!-- <ctorArg value='commentedOutForTesting'/> --> <anotherNonCtorArgElement /> </ctorArgs> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); Assert.AreEqual(1, cmdConfigs.Count); }
public void itShouldNotThrowExceptionIfThereAreNoTokens() { var xmlConfig = @" <commands> </commands> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var tokens = xmlConfigSource.Tokens; Assert.AreEqual(0, tokens.Count); xmlConfig = @" <commands> <tokens> </tokens> </commands> "; xmlDoc.LoadXml(xmlConfig); xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); tokens = xmlConfigSource.Tokens; Assert.AreEqual(0, tokens.Count); }
public List <Token> GetTokens(string configFile) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configFile); var commandsConfigurationSource = new CommandsConfigurationXmlSource(xmlDoc); return(commandsConfigurationSource.Tokens); }
public List <CommandConfiguration> GetCommands(string configFile) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configFile); var commandsConfigurationSource = new CommandsConfigurationXmlSource(xmlDoc); var commandConfigs = commandsConfigurationSource.GetCommandConfigurations().Where(c => c.Enabled).ToList(); var cmdBuilder = new CommandsBuilder(commandConfigs, commandsConfigurationSource.Tokens); return(cmdBuilder.GetTokenizedConfiguration()); }
public bool Run() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(_commandsConfigFile); var commandsConfigurationSource = new CommandsConfigurationXmlSource(xmlDoc); var commandsConfiguration = commandsConfigurationSource.GetCommandConfigurations(); var commandsBuilder = new CommandsBuilder(commandsConfiguration); var commands = commandsBuilder.BuildCommands(); var commandsRunner = new CommandsRunner(commands); commandsRunner.OnReportSent += CommandsRunner_OnReportSent; return(commandsRunner.Run()); }
public void itShouldThrowExceptionIfEnabledAttributeValueIsNeitherTrueNorFalseNorEmpty() { var xmlConfig = $@" <commandCenter> <commands> <command enabled='werjwjekqrl'> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); }
public void itShouldThrowExceptionIfValueOfAttributeValueIsBlank() { var xmlConfig = @" <commands> <tokens> <token key='KEY1' value=' ' /> </tokens> </commands> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var tokens = xmlConfigSource.Tokens; Assert.AreEqual(0, tokens.Count); }
public void itShouldThrowExceptionIfAttributeKeyIsMissing() { var xmlConfig = @" <commands> <tokens> <token value='TOKEN1VALUE' /> </tokens> </commands> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var tokens = xmlConfigSource.Tokens; Assert.AreEqual(0, tokens.Count); }
public void itShouldRaiseExceptionWhenCommandNodeNotFound() { var xmlConfig = @" <commandCenter> <commands> <commandNodeNot> </commandNodeNot> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); Assert.AreEqual(0, cmdConfigs.Count); }
public void itShouldThrowExceptionOnDuplicateTokenKeys() { var tokenKey1 = "TOKEN1"; var tokenValue1 = "TOKEN1VALUE"; var tokenKey2 = "TOKEN1"; var tokenValue2 = "TOKEN2VALUE"; var xmlConfig = $@" <commands> <tokens> <token key='{tokenKey1}' value='{tokenValue1}' /> <token key='{tokenKey2}' value='{tokenValue2}' /> </tokens> </commands> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var tokens = xmlConfigSource.Tokens; }
public void itShouldAssignEmptyStringIfShortDesriptionDoesNotExist() { var xmlConfig = $@" <commandCenter> <commands> <command> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); var cmdConfig = cmdConfigs.FirstOrDefault(); Assert.IsNotNull(cmdConfig); Assert.AreEqual(cmdConfig.ShortDescription, string.Empty); }
public void itShouldSetEnabledToTrueIfEnabledAttributeValueIsEmpty() { var xmlConfig = $@" <commandCenter> <commands> <command enabled=''> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); var cmdConfig = cmdConfigs.FirstOrDefault(); Assert.IsNotNull(cmdConfig); Assert.IsTrue(cmdConfig.Enabled); }
public void itShouldRaiseExceptionWhenTypeNameNotFound() { var xmlConfig = @" <commandCenter> <commands> <command> <ctorArgs> <ctorArg name='dummyName' value='dummyValue' /> </ctorArgs> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); Assert.AreEqual(0, cmdConfigs.Count); }
public void itShouldLoadCommandConfigurationsWithParameterElements() { var xmlConfig = @" <commandCenter> <commands> <command> <typeName>CommandCenter.Tests, CommandCenter.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> <ctorArgs> <ctorArg name='dummyName' value='dummyValue' /> </ctorArgs> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); Assert.AreEqual(1, cmdConfigs.Count); }
public void itShouldRaiseNotExceptionWhenCtorNameAttributeIsOmitted() { var xmlConfig = @" <commandCenter> <commands> <command> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> <ctorArgs> <ctorArg value='someValue'/> </ctorArgs> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); Assert.AreEqual(1, cmdConfigs.Count); }
public void itShouldGetShortDesriptionWhenItExists() { var shortDescText = "This is a test short description"; var xmlConfig = $@" <commandCenter> <commands> <command> <typeName>CommandCenter.Infrastructure.Tests, CommandCenter.Infrastructure.Tests.MockCommands.MockCommandWithNonDefaultConstructor</typeName> <shortDescription>{shortDescText}</shortDescription> </command> </commands> </commandCenter> "; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlConfig); var xmlConfigSource = new CommandsConfigurationXmlSource(xmlDoc); var cmdConfigs = xmlConfigSource.GetCommandConfigurations(); var cmdConfig = cmdConfigs.FirstOrDefault(); Assert.IsNotNull(cmdConfig); Assert.AreEqual(cmdConfig.ShortDescription, shortDescText); }