public void SplitsFragmentsWithoutSpacings()
 {
     var configurationString = "CommandName= FilesOnly ; Directory= C:\\Test\\ ";
     var commandConfiguration = new DynamicCommandConfiguration(configurationString);
     Assert.That(commandConfiguration.Configuration.ContainsKey("commandname"), "Missing Key: filesonly");
     Assert.That(commandConfiguration.Configuration.ContainsKey("directory"), "Missing Key: directory");
     Assert.AreEqual("filesonly", commandConfiguration.Configuration["commandname"], "Wrong Command Name");
     Assert.AreEqual("c:\\test\\", commandConfiguration.Configuration["directory"], "Wrong Command Name");
 }
 public void SplitsFragmentsWithApostrophsAndThreeItems()
 {
     var configurationString = "CommandName='FileExtension'; Directory='C:\\Test\\'; FileExtension='txt'";
     var commandConfiguration = new DynamicCommandConfiguration(configurationString);
     Assert.That(commandConfiguration.Configuration.ContainsKey("commandname"), "Missing Key: fileextension");
     Assert.That(commandConfiguration.Configuration.ContainsKey("directory"), "Missing Key: directory");
     Assert.That(commandConfiguration.Configuration.ContainsKey("fileextension"), "Missing Key: fileextension");
     Assert.AreEqual("fileextension", commandConfiguration.Configuration["commandname"], "Wrong Command Name");
     Assert.AreEqual("c:\\test\\", commandConfiguration.Configuration["directory"], "Wrong Command Name");
     Assert.AreEqual("txt", commandConfiguration.Configuration["fileextension"], "Wrong FileExtension");
 }
        public BulkCommandInfo ParseCommandStrings(IEnumerable <string> commandStrings)
        {
            var aggregates = commandStrings
                             .Aggregate(new
            {
                InvocationInfos = new Dictionary <string, IList <CommandInvocationInfo> >(),
                AdditionalInfos = new List <string>()
            },
                                        (previous, x) =>
            {
                var commandConfiguration = new DynamicCommandConfiguration(x);
                var configuration        = commandConfiguration.Configuration;
                if (configuration.ContainsKey("directory") && configuration.ContainsKey("commandname"))
                {
                    var cachedCommandDirectory = configuration["directory"];
                    var cachedCommandName      = configuration["commandname"];

                    if (!previous.InvocationInfos.ContainsKey(cachedCommandDirectory))
                    {
                        previous.InvocationInfos.Add(cachedCommandDirectory, new List <CommandInvocationInfo>());
                    }

                    configuration.Remove("commandname");
                    configuration.Remove("directory");
                    previous.InvocationInfos[cachedCommandDirectory].Add(new CommandInvocationInfo
                    {
                        CommandName   = cachedCommandName,
                        Configuration = configuration
                    });
                }
                else if (!configuration.ContainsKey("directory"))
                {
                    previous.AdditionalInfos.Add("One Command skipped due to missing 'Directory' property");
                }
                else if (!configuration.ContainsKey("commandname"))
                {
                    previous.AdditionalInfos.Add("One Command skipped due to missing 'Command' property");
                }
                return(previous);
            });

            return(new BulkCommandInfo()
            {
                InvocationInfos = aggregates.InvocationInfos,
                AdditionalInfo = aggregates.AdditionalInfos
            });
        }
        public BulkCommandInfo ParseCommandStrings(IEnumerable<string> commandStrings)
        {
            var aggregates = commandStrings
                .Aggregate(new
                            {
                                InvocationInfos = new Dictionary<string, IList<CommandInvocationInfo>>(),
                                AdditionalInfos = new List<string>()
                            },
                           (previous, x) =>
                               {
                                   var commandConfiguration = new DynamicCommandConfiguration(x);
                                   var configuration = commandConfiguration.Configuration;
                                   if (configuration.ContainsKey("directory") && configuration.ContainsKey("commandname"))
                                   {
                                       var cachedCommandDirectory = configuration["directory"];
                                       var cachedCommandName = configuration["commandname"];

                                       if(!previous.InvocationInfos.ContainsKey(cachedCommandDirectory))
                                           previous.InvocationInfos.Add(cachedCommandDirectory,new List<CommandInvocationInfo>());

                                       configuration.Remove("commandname");
                                       configuration.Remove("directory");
                                       previous.InvocationInfos[cachedCommandDirectory].Add(new CommandInvocationInfo
                                                                                                 {
                                                                                                    CommandName = cachedCommandName,
                                                                                                    Configuration = configuration
                                                                                                 });
                                   }
                                   else if (!configuration.ContainsKey("directory"))
                                   {
                                       previous.AdditionalInfos.Add("One Command skipped due to missing 'Directory' property");
                                   }
                                   else if (!configuration.ContainsKey("commandname"))
                                   {
                                       previous.AdditionalInfos.Add("One Command skipped due to missing 'Command' property");
                                   }
                                   return previous;
                               });

            return new BulkCommandInfo()
                       {
                           InvocationInfos = aggregates.InvocationInfos,
                           AdditionalInfo = aggregates.AdditionalInfos
                       };
        }
 public void ReturnsEmptyDictionaryForEmptyString()
 {
     var configurationString = "";
     var commandConfiguration = new DynamicCommandConfiguration(configurationString);
     Assert.IsNotNull(commandConfiguration.Configuration, "Dictonary expected, but is null");
 }