Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        public List <Token> GetTokens(string configFile)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(configFile);
            var commandsConfigurationSource = new CommandsConfigurationXmlSource(xmlDoc);

            return(commandsConfigurationSource.Tokens);
        }
Example #6
0
        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());
        }
Example #8
0
        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();
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
        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;
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
        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);
        }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        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);
        }