public void GiveAParameterWithSpaceAndSingleQuotes()
        {
            var command      = @"move 'C:\Temp\a.txt' to 'c:\Temp\b.txt'";
            var testTask     = new TestMultipleTask();
            var computedTask = new ComputedTask(testTask);
            var parameters   = computedTask.GetParameters(command).ToList();

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(@"C:\Temp\a.txt", parameters[0]);
            Assert.AreEqual(@"c:\Temp\b.txt", parameters[1]);
        }
        public void GivenASimpleTaskCanExtractParameters()
        {
            var command      = @"move C:\Temp\a.txt to c:\Temp\b.txt";
            var testTask     = new TestMultipleTask();
            var computedTask = new ComputedTask(testTask);
            var parameters   = computedTask.GetParameters(command).ToList();

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(@"C:\Temp\a.txt", parameters[0]);
            Assert.AreEqual(@"c:\Temp\b.txt", parameters[1]);
        }
        public void GivenAISimpleTaskCanGenerateAComputedTaskMultipleParams()
        {
            var testTask     = new TestMultipleTask();
            var computedTask = new ComputedTask(testTask);

            Assert.IsNotNull(computedTask);
            Assert.IsNotNull(computedTask.Data);
            Assert.AreEqual(2, computedTask.Data.Positions.Count);
            Assert.AreEqual(@"(move)([ ])("".*?""|\S+)([ ])(to)([ ])("".*?""|\S+)", computedTask.Data.Regex.ToString());
            Assert.AreEqual(TaskType.Parameterized, computedTask.Type);
        }
Esempio n. 4
0
        public static IEnumerable <string> GetParameters(this ComputedTask computedTask, string command)
        {
            var acceptedEnclosers = new char[] { '\'', '\"' };
            var matches           = computedTask.Data.Regex.Match(command);

            foreach (var position in computedTask.Data.Positions)
            {
                yield return(matches.Groups[(position + 1)]
                             .Value
                             .TrimStart(acceptedEnclosers)
                             .TrimEnd(acceptedEnclosers));
            }
        }
Esempio n. 5
0
        public ComputedTask RegisterTask(ISimpleTask simpleTask)
        {
            if (_isInitialized)
            {
                throw new NotSupportedException("You cannot register tasks after initializing taskable.");
            }

            TaskValidator.ValidateTask(simpleTask);

            var computedTask = new ComputedTask(simpleTask);

            if (_rawTasks.Any(t => t.Name == computedTask.Name))
            {
                throw new DuplicateTaskDefinitionException(computedTask.Name);
            }

            _rawTasks.Add(computedTask);

            return(computedTask);
        }