示例#1
0
        public void itShouldExpandCtorArgsWithMultipleConfiguredTokens()
        {
            var mockCommandConsumingToken = "CommandCenter.Tests, CommandCenter.Tests.MockCommands.MockCommandConsumingToken";
            var cmdConfiguration          = new CommandConfiguration {
                TypeActivationName = mockCommandConsumingToken
            };

            cmdConfiguration.ConstructorArgs.Add("ctorArg1", @"[BACKUPDIR]\FakeFile.[EXT]");
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var tokens = new List <Token>();

            tokens.Add(new Token {
                Key   = "[BACKUPDIR]",
                Value = @"C:\SomeFakeDirectory"
            });
            tokens.Add(new Token {
                Key   = "[EXT]",
                Value = "jpg"
            });

            var cmdBuilder    = new CommandsBuilder(cmdConfigurations, tokens);
            var builtCommands = cmdBuilder.BuildCommands();

            var builtCommand = builtCommands.First() as MockCommandConsumingToken;

            Assert.IsNotNull(builtCommand);
            Assert.AreEqual(builtCommand.TokenizedArg, @"C:\SomeFakeDirectory\FakeFile.jpg");
        }
示例#2
0
        public List <BaseCommand> GetUndoableCommmands(List <CommandConfiguration> commandsConfiguration)
        {
            var commandsBuilder = new CommandsBuilder(commandsConfiguration);
            var commands        = commandsBuilder.BuildCommands();

            return(commands.Where(c => !c.IsUndoable).ToList());
        }
示例#3
0
        public bool RunPreflight(List <CommandConfiguration> commandsConfiguration)
        {
            var commandsBuilder = new CommandsBuilder(commandsConfiguration);
            var commands        = commandsBuilder.BuildCommands();

            _commandsRunner = new CommandsRunner(commands);
            _commandsRunner.OnReportSent += CommandsRunner_OnReportSent;
            DidCommandsSucceed            = _commandsRunner.RunPreflight();
            LastRunElapsedTime            = _commandsRunner.LastRunElapsedTime;
            return(DidCommandsSucceed);
        }
示例#4
0
        public void itShouldRaiseExceptionWhenConstructorArgsAreWrong()
        {
            var cmdConfiguration = new CommandConfiguration {
                TypeActivationName = "CommandCenter.Tests, CommandCenter.Tests.MockCommands.MockCommandWithNonDefaultConstructor"
            };
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var cmdBuilder = new CommandsBuilder(cmdConfigurations);

            cmdBuilder.BuildCommands();
        }
示例#5
0
        public void itShouldRaiseExceptionWhenTypeLoadingFails()
        {
            var nonExistingTypeName = "CommandCenter.Tests, NoSuchType";
            var cmdConfiguration    = new CommandConfiguration {
                TypeActivationName = nonExistingTypeName
            };
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var cmdBuilder = new CommandsBuilder(cmdConfigurations);

            cmdBuilder.BuildCommands();
        }
示例#6
0
        public void itShouldRaiseExceptionWhenTypeNameConfigurationFormatIsIncorrect()
        {
            var incorrectTypeActivationNameFormat = "CommandCenter.Infrastructure.Tests.MockCommands.MockSucceedingCommand";
            var cmdConfiguration = new CommandConfiguration {
                TypeActivationName = incorrectTypeActivationNameFormat
            };
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var cmdBuilder = new CommandsBuilder(cmdConfigurations);

            cmdBuilder.BuildCommands();
        }
示例#7
0
        public void itShouldRaiseExceptionWhenAssemblyLoadingFails()
        {
            var nonExistingAssemblyName = "NoSuchAssembly, CommandCenter.Infrastructure.Tests.MockCommands.MockSucceedingCommand";
            var cmdConfiguration        = new CommandConfiguration {
                TypeActivationName = nonExistingAssemblyName
            };
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var cmdBuilder = new CommandsBuilder(cmdConfigurations);

            cmdBuilder.BuildCommands();
        }
示例#8
0
        public void itShouldCreateCorrectlyConfiguredCommands()
        {
            var cmdConfiguration = new CommandConfiguration {
                TypeActivationName = "CommandCenter.Tests, CommandCenter.Tests.MockCommands.MockSucceedingCommand"
            };
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var cmdBuilder = new CommandsBuilder(cmdConfigurations);

            var result = cmdBuilder.BuildCommands();

            Assert.IsNotNull(result.First());
        }
        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());
        }
示例#10
0
        public void itShouldCreateCommandsWithNonDefaultConstructor()
        {
            var cmdConfiguration = new CommandConfiguration {
                TypeActivationName = "CommandCenter.Tests, CommandCenter.Tests.MockCommands.MockCommandWithNonDefaultConstructor"
            };

            cmdConfiguration.ConstructorArgs.Add("arg1", "dummy constructorArg value 1");

            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var cmdBuilder = new CommandsBuilder(cmdConfigurations);

            var result = cmdBuilder.BuildCommands();

            Assert.IsNotNull(result.First());
        }
示例#11
0
        public void BuildCommandTest_AVERAGE_PRICE_TYPE_COMMAND_2_75returned()
        {
            //arrange
            PurchaseBuilder purchaseBuilder = new PurchaseBuilder();
            string          command         = "average price type 1";
            string          expected        = "2,75";
            string          actual          = String.Empty;

            //act
            List <Purchase> purchaseArrayAveragePriceTypeTest = new List <Purchase> {
                purchase1, purchase2, purchase3, purchase4
            };
            CommandsBuilder commandBuilder = new CommandsBuilder();

            actual = commandBuilder.BuildCommands(command, purchaseArrayAveragePriceTypeTest);

            //assert
            Assert.AreEqual(expected, actual);
        }
示例#12
0
        public void BuildCommandTest_All_QUANTITY_COMMAND_6returned()
        {
            //arrange
            PurchaseBuilder purchaseBuilder = new PurchaseBuilder();
            string          command         = "count all";
            string          expected        = "6";
            string          actual          = String.Empty;

            //act
            List <Purchase> purchaseArrayAllQuantityTest = new List <Purchase> {
                purchase1, purchase2, purchase3
            };
            CommandsBuilder commandBuilder = new CommandsBuilder();

            actual = commandBuilder.BuildCommands(command, purchaseArrayAllQuantityTest);

            //assert
            Assert.AreEqual(expected, actual);
        }
示例#13
0
        public void BuildCommandTest_COUNT_TYPES_COMMAND_3returned()
        {
            //arrange
            PurchaseBuilder purchaseBuilder = new PurchaseBuilder();
            string          command         = "count types";
            string          expected        = "3";
            string          actual          = String.Empty;

            //act
            List <Purchase> purchaseArrayQuantityTypesTest = new List <Purchase> {
                purchase1, purchase2, purchase3
            };
            CommandsBuilder commandBuilder = new CommandsBuilder();

            actual = commandBuilder.BuildCommands(command, purchaseArrayQuantityTypesTest);

            //assert
            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void itShouldExpandTypeNamesWithTokens()
        {
            var cmdConfiguration = new CommandConfiguration {
                TypeActivationName = "[COMMAND1]"
            };

            cmdConfiguration.ConstructorArgs.Add("ctorArg1", @"anything  goes");
            var cmdConfigurations = new List <CommandConfiguration>();

            cmdConfigurations.Add(cmdConfiguration);
            var tokens = new List <Token>();

            tokens.Add(new Token {
                Key   = "[COMMAND1]",
                Value = "CommandCenter.Tests, CommandCenter.Tests.MockCommands.MockCommandConsumingToken"
            });

            var cmdBuilder    = new CommandsBuilder(cmdConfigurations, tokens);
            var builtCommands = cmdBuilder.BuildCommands();

            var builtCommand = builtCommands.First() as MockCommandConsumingToken;

            Assert.IsNotNull(builtCommand);
        }