public override void Setup()
        {
            base.Setup();

            var commands = new[]
            {
                new CommandDescriptor("IdentityRunnable", String.Empty, Enumerable.Empty <ArgumentDescriptor>(), new[] { "IdentityRunnable" }),
                new CommandDescriptor("IncrementRunnable", String.Empty, new[]
                {
                    new ArgumentDescriptor
                    {
                        ArgumentType = typeof(Double),
                        ArgumentName = "value",
                        DefaultValue = 0,
                        IsOptional   = false,
                        Position     = 0
                    }
                }, new[] { "IncrementRunnable", "increment", "inc" })
            };

            var runnableFactory = new DefaultRunnableFactory(new[] { typeof(IdentityRunnable), typeof(IncrementRunnable) });

            var repository           = new MemoryDescriptorRepository(commandDescriptors: commands);
            var commandCallResolver  = new DefaultCommandCallResolver(repository, runnableFactory);
            var selectorManager      = new DefaultSelectorFactory();
            var nodeSelectorResolver = new DefaultSelectorResolver(selectorManager, repository);
            var runnableManager      = new DefaultRunnableManager();
            var executor             = new StandardExecutor(runnableManager);

            // initialize compiler and control flow factory
            ControlFlowFactory = new DefaultControlFlowFactory(commandCallResolver, nodeSelectorResolver, executor);
            Compiler           = new CodeQueryCompiler();
        }
        public void Parse_ShouldParseHandle_WhenSelectorsAreDefined(String command)
        {
            // Given
            var underTest = new CodeQueryCompiler();

            // When
            var result = underTest.Parse(command);

            // Then
            Assert.That(result, Is.Not.Null);
        }
        public void Parse_ShouldParseCommand_WhenSimpleCommandCallIsPassed()
        {
            // Given
            var underTest = new CodeQueryCompiler();

            // When
            var result = underTest.Parse("@test-command");

            // Then
            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.TypeOf <CommandCallControlFlowElement>());
        }
        public void Parse_ShouldReturnSequenceControlFlow_WhenMultipleCommandsArePassed()
        {
            // Given
            var underTest = new CodeQueryCompiler();

            // When
            var result = underTest.Parse("@test-command; @test-command-2") as SequenceControlFlowElement;

            // Then
            Assert.That(result, Is.Not.Null);
            var expectedChildren = result.Children
                                   .Cast <CommandCallControlFlowElement>()
                                   .Select(call => call.CommandCallElement.MethodName);

            Assert.That(expectedChildren, Is.EquivalentTo(new[] { "test-command", "test-command-2" }));
        }
        public void Parse_ShouldParseCommand_WhenSimpleCommandCallWithOneStringParameterIsPassed()
        {
            // Given
            var underTest = new CodeQueryCompiler();

            // When
            var result = underTest.Parse("@test-command \"hello world!\"") as CommandCallControlFlowElement;

            // Then
            Assert.That(result, Is.Not.Null);

            var actualParameters = result.CommandCallElement.ActualParameters.ToArray();

            Assert.That(actualParameters.Length, Is.EqualTo(1));
            Assert.That(actualParameters.Select(parameter => new {
                Position = parameter.Position,
                Value    = parameter.Value.Value as String
            }), Is.EquivalentTo(new[] { new { Position = Option.Some(0), Value = "hello world!" } }));
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Bootstrapper"/> class.
        /// </summary>
        public Bootstrapper(IRunnableFactory runnableFactory, IDescriptorRepository descriptorRepository, Func <Bootstrapper, ICommandDescriptorManager> commandDescriptorManager = null,
                            Func <Bootstrapper, ICommandCallResolver> commandResolver = null, Func <Bootstrapper, ISelectorFactory> selectorFactory = null,
                            Func <Bootstrapper, ISelectorResolver> selectorResolver   = null, Func <Bootstrapper, IRunnableManager> runnableManager = null, Func <Bootstrapper, IExecutor> executor = null,
                            Func <Bootstrapper, IControlFlowFactory <ControlFlowBase> > controlFlowFactory = null)
        {
            Assume.NotNull(runnableFactory, nameof(runnableFactory));
            Assume.NotNull(descriptorRepository, nameof(descriptorRepository));

            RunnableFactory          = runnableFactory;
            DescriptorRepository     = descriptorRepository;
            CommandDescriptorManager = commandDescriptorManager.SafeInvoke(this) ?? new DefaultCommandDescriptorManager();
            CommandCallResolver      = commandResolver.SafeInvoke(this) ?? new DefaultCommandCallResolver(descriptorRepository, RunnableFactory);
            SelectorFactory          = selectorFactory.SafeInvoke(this) ?? new DefaultSelectorFactory();
            SelectorResolver         = selectorResolver.SafeInvoke(this) ?? new DefaultSelectorResolver(SelectorFactory, DescriptorRepository);
            RunnableManager          = runnableManager.SafeInvoke(this) ?? new DefaultRunnableManager();
            Executor = executor.SafeInvoke(this) ?? new StandardExecutor(RunnableManager);

            ControlFlowFactory = controlFlowFactory.SafeInvoke(this) ?? new DefaultControlFlowFactory(CommandCallResolver, SelectorResolver, Executor);
            Compiler           = new CodeQueryCompiler();
        }
Example #7
0
        public override void Setup()
        {
            base.Setup();

            var runnableFactory = new DefaultRunnableFactory(new[] { typeof(ToUpperCaseRunnable), typeof(GetTextRunnable), typeof(ToStringRunnable) });

            var commands    = getCommandDescriptors();
            var selectors   = getSelectorDescriptors();
            var combinators = getCombinatorDescriptors();

            var descriptorRepository = new MemoryDescriptorRepository(selectors, combinators, commandDescriptors: commands);

            var commandCallResolver  = new DefaultCommandCallResolver(descriptorRepository, runnableFactory);
            var selectorManager      = new DefaultSelectorFactory();
            var nodeSelectorResolver = new DefaultSelectorResolver(selectorManager, descriptorRepository);
            var runnableManager      = new DefaultRunnableManager();
            var executor             = new StandardExecutor(runnableManager);

            // initialize compiler and control flow factory
            ControlFlowFactory = new DefaultControlFlowFactory(commandCallResolver, nodeSelectorResolver, executor);
            Compiler           = new CodeQueryCompiler();
        }