Example #1
0
        private void button1_Click(object sender, EventArgs e)//edit to data struct
        {
            if (nodeSelected == null)
            {
                return;
            }
            var macro = new MacroCommand();

            if (nodeSelected is ScalarNode)
            {
                ScalarNode tempScalar = (ScalarNode)nodeSelected;
                TreeNode   node       = searchTreeEdit(root, tempScalar.id);

                var key   = dataGridView1.Rows[0].Cells[0].EditedFormattedValue.ToString();
                var value = dataGridView1.Rows[0].Cells[1].EditedFormattedValue.ToString();
                vl = new ValueCommand(mapNode, node, tempScalar, key, this, value);
                macro.Add(vl);
                Manager.Execute(macro);
            }
            else
            {
                vl = new ValueCommand(this, dataGridView1, nodeSelected);
                macro.Add(vl);
                Manager.Execute(macro);

                RefreshAll();

                expandAllNodes(nodeSelected);
            }
        }
Example #2
0
        public void Process(Instruction instruction)
        {
            Command command;

            switch (instruction.InstructionType)
            {
                case InstructionType.NamespaceDeclaration:
                    command = new NamespaceDeclarationCommand(instruction.NamespaceDeclaration, StateCommuter);
                    break;
                case InstructionType.StartObject:
                    command = new StartObjectCommand(StateCommuter, TypeSource, instruction.XamlType, rootInstance);
                    break;
                case InstructionType.StartMember:
                    command = new StartMemberCommand(StateCommuter, GetActualMemberFromMemberSpecifiedInInstruction(instruction.Member));
                    break;
                case InstructionType.Value:
                    command = new ValueCommand(StateCommuter, this.TypeSource, TopDownValueContext, (string)instruction.Value);
                    break;
                case InstructionType.EndObject:
                    command = new EndObjectCommand(StateCommuter, stateCommuter => Result = stateCommuter.Current.Instance);
                    break;
                case InstructionType.EndMember:
                    command = new EndMemberCommand(TypeSource, StateCommuter);
                    break;
                case InstructionType.GetObject:
                    command = new GetObjectCommand(StateCommuter);
                    break;
                default:
                    throw new ParseException($"The XamlInstructionType {instruction.InstructionType} has an unexpected value");
            }

            command.Execute();
        }
        public async Task CallsOutgoingPipeline_WhenSendingCommand()
        {
            var command = new ValueCommand(11);

            await this.testee.SendAsync(command).ConfigureAwait(false);

            A.CallTo(() => outgoingPipeline.InvokeAsync(command)).MustHaveHappened();
        }
Example #4
0
        private static Envelope CreateTestee()
        {
            var sender    = new EndpointAddress("sender");
            var recipient = new EndpointAddress("recipient");
            var body      = new ValueCommand(11);

            return(Envelope.Create(sender, recipient, body));
        }
        public async Task DoesNotInvokeAsyncHandler_WhenItWasNotAddedBefore()
        {
            var handler = new ValueCommandHandler();
            var command = new ValueCommand(11);

            await this.testee.InvokeAsync(handler, command).ConfigureAwait(false);

            handler.Value.Should().Be(0);
        }
Example #6
0
        public async Task ShouldInvokeGivenFinalActionForCommand()
        {
            var message = new ValueCommand(11);
            var incommingMessageContext = CreateIncommingMessageContext(message);

            await this.testee.InvokeAsync(incommingMessageContext, null).ConfigureAwait(false);

            A.CallTo(() => this.finalActionForCommand.Invoke(message)).MustHaveHappened();
        }
Example #7
0
        public async Task LogsReceptionOfMessage()
        {
            var message = new ValueCommand(11);
            var incommingMessageContext = CreateIncommingMessageContext(message);

            await this.testee.InvokeAsync(incommingMessageContext, null).ConfigureAwait(false);

            "Received Command of type SimpleDomain.TestDoubles.ValueCommand from sender".Should().HaveBeenLogged().WithInfoLevel();
        }
        public async Task CanInvokeAsyncMethod()
        {
            var handler = new ValueCommandHandler();
            var command = new ValueCommand(11);

            await this.testee.InvokeAsync(handler, command).ConfigureAwait(false);

            handler.Value.Should().Be(11);
        }
        public void CanRegisterHandlerType()
        {
            var assemblies = new[] { typeof(ValueCommandHandler).Assembly };
            var command    = new ValueCommand(11);

            this.testee.SubscribeMessageHandlers(assemblies);

            this.testee.Subscriptions.GetCommandSubscription(command).Should().NotBeNull();
        }
Example #10
0
        public async Task DoesNotCallNext()
        {
            var message = new ValueCommand(11);
            var incommingMessageContext = CreateIncommingMessageContext(message);
            var next = A.Fake <Func <Task> >();

            await this.testee.InvokeAsync(incommingMessageContext, next).ConfigureAwait(false);

            A.CallTo(() => next.Invoke()).MustNotHaveHappened();
        }
        public void ThrowsException_WhenNoCommandHandlerSubscriptionCanBeFound()
        {
            var valueCommand = new ValueCommand(Value);

            A.CallTo(() => this.handlerRegistry.GetCommandHandler(valueCommand)).Returns(null);

            Action action = () => this.testee.GetCommandSubscription(valueCommand);

            action.ShouldThrow <NoSubscriptionException>();
        }
        public async Task ShouldCallEnvelopeStepsAndMessageSteps()
        {
            var message  = new ValueCommand(11);
            var envelope = Envelope.Create(new EndpointAddress("sender"), new EndpointAddress("recipient"), message);

            await this.testee.InvokeAsync(envelope).ConfigureAwait(false);

            this.envelopeStep.HasBeenCalled.Should().BeTrue();
            this.messageStep.HasBeenCalled.Should().BeTrue();
        }
        public async Task CanInvokeAsyncHandlerWithMessage_WhenTheirTypeRelationshipWasAddedBefore()
        {
            this.testee.Add(typeof(ValueCommandHandler), typeof(ValueCommand));

            var handler = new ValueCommandHandler();
            var command = new ValueCommand(11);

            await this.testee.InvokeAsync(handler, command).ConfigureAwait(false);

            handler.Value.Should().Be(11);
        }
Example #14
0
        public void CanAddNewHeader()
        {
            var headers = new Dictionary <string, object>();
            var body    = new ValueCommand(11);

            var testee = new Envelope(headers, body);

            testee.AddHeader("New Header", 42);

            testee.Headers.Should().ContainKey("New Header").And.ContainValue(42);
        }
        public void CanSetMessage()
        {
            var message  = new ValueCommand(11);
            var envelope = Envelope.Create(new EndpointAddress("sender"), new EndpointAddress("recipient"), message);
            var pipelineConfiguration = A.Fake <IHavePipelineConfiguration>();
            var testee = new IncommingEnvelopeContext(envelope, pipelineConfiguration);

            testee.SetMessage();

            testee.Message.Should().Be(message);
        }
Example #16
0
        public void CanCreateInstanceWithConstructor()
        {
            var headers = new Dictionary <string, object> {
                { "Foo", "Foo" }, { "Bar", 42 }
            };
            var body = new ValueCommand(11);

            var testee = new Envelope(headers, body);

            testee.Headers.Should().BeSameAs(headers);
            testee.Body.Should().BeSameAs(body);
        }
Example #17
0
        public void AddsNewHeader_WhenReplacingNonExistingHeader()
        {
            var headers = new Dictionary <string, object> {
                { "Existing Header", 42 }
            };
            var body = new ValueCommand(11);

            var testee = new Envelope(headers, body);

            testee.ReplaceHeader("NonExisting Header", 666);

            testee.Headers.Should().HaveCount(2).And.ContainKey("NonExisting Header").And.ContainValue(666);
        }
Example #18
0
        public void DoesNothing_WhenAddingAnExistingHeader()
        {
            var headers = new Dictionary <string, object> {
                { "Existing Header", 42 }
            };
            var body = new ValueCommand(11);

            var testee = new Envelope(headers, body);

            testee.AddHeader("Existing Header", 666);

            testee.Headers.Should().HaveCount(1).And.ContainKey("Existing Header").And.ContainValue(42);
        }
Example #19
0
        public void CanCreateInstanceWithFactoryMethod()
        {
            var sender    = new EndpointAddress("sender");
            var recipient = new EndpointAddress("recipient");
            var body      = new ValueCommand(11);

            var testee = Envelope.Create(sender, recipient, body);

            testee.Headers.Should().ContainKey(HeaderKeys.Sender);
            testee.Headers.Should().ContainKey(HeaderKeys.Recipient);
            testee.Headers.Should().ContainKey(HeaderKeys.TimeSent);
            testee.Headers.Should().ContainKey(HeaderKeys.MessageId);
            testee.Headers.Should().ContainKey(HeaderKeys.CorrelationId);
            testee.Body.Should().BeSameAs(body);
        }
        public async Task CanGetCommandSubscription_WhenItHasBeenSubscribedWithAssemblyScanningBefore()
        {
            Action <Type> register = t => { };

            var command = new ValueCommand(Value);
            var handler = new ValueCommandHandler();

            A.CallTo(() => this.handlerRegistry.GetCommandHandler(command)).Returns(handler);

            this.testee.ScanAssemblyForMessageHandlers(Assembly.GetExecutingAssembly(), register);

            var subscription = this.testee.GetCommandSubscription(command);
            await subscription.HandleAsync(command).ConfigureAwait(false);

            handler.Value.Should().Be(Value);
        }
        public async Task CanGetCommandSubscription_WhenItHasBeenSubscribedAsAsyncActionBefore()
        {
            var expectedValue = 0;
            var command       = new ValueCommand(Value);

            var handler = new Func <ValueCommand, Task>(c =>
            {
                expectedValue = c.Value;
                return(Task.CompletedTask);
            });

            this.testee.AddCommandHandler(handler);

            var subscription = this.testee.GetCommandSubscription(command);
            await subscription.HandleAsync(command).ConfigureAwait(false);

            expectedValue.Should().Be(Value);
        }
        public async Task ShouldHandleCommand()
        {
            const int Value = 42;

            var expectedValue = 0;
            var valueCommand  = new ValueCommand(Value);

            var handler = new Func <ValueCommand, Task>(cmd =>
            {
                expectedValue = cmd.Value;
                return(Task.CompletedTask);
            });

            var testee = new CommandSubscription <ValueCommand>(handler);

            await testee.HandleAsync(valueCommand).ConfigureAwait(false);

            expectedValue.Should().Be(Value);
        }
Example #23
0
        public void Process(XamlInstruction instruction)
        {
            Command command;

            switch (instruction.InstructionType)
            {
            case XamlInstructionType.NamespaceDeclaration:
                command = new NamespaceDeclarationCommand(this, instruction.NamespaceDeclaration);
                break;

            case XamlInstructionType.StartObject:
                command = new StartObjectCommand(this, instruction.XamlType, rootInstance);
                break;

            case XamlInstructionType.StartMember:
                command = new StartMemberCommand(this, GetMember(instruction.Member));
                break;

            case XamlInstructionType.Value:
                command = new ValueCommand(this, topDownValueContext, (string)instruction.Value);
                break;

            case XamlInstructionType.EndObject:
                command = new EndObjectCommand(this);
                break;

            case XamlInstructionType.EndMember:
                command = new EndMemberCommand(this, topDownValueContext);
                break;

            case XamlInstructionType.GetObject:
                command = new GetObjectCommand(this);
                break;

            default:
                throw new XamlParseException($"The XamlInstructionType {instruction.InstructionType} has an unexpected value");
            }

            command.Execute();
        }
Example #24
0
        public void Process(Instruction instruction)
        {
            Command command;

            switch (instruction.InstructionType)
            {
            case InstructionType.NamespaceDeclaration:
                command = new NamespaceDeclarationCommand(instruction.NamespaceDeclaration, StateCommuter);
                break;

            case InstructionType.StartObject:
                command = new StartObjectCommand(StateCommuter, TypeSource, instruction.XamlType, rootInstance);
                break;

            case InstructionType.StartMember:
                command = new StartMemberCommand(StateCommuter, GetActualMemberFromMemberSpecifiedInInstruction(instruction.Member));
                break;

            case InstructionType.Value:
                command = new ValueCommand(StateCommuter, valueContext, (string)instruction.Value);
                break;

            case InstructionType.EndObject:
                command = new EndObjectCommand(StateCommuter, stateCommuter => Result = stateCommuter.Current.Instance, LifecycleListener);
                break;

            case InstructionType.EndMember:
                command = new EndMemberCommand(TypeSource, StateCommuter, valueContext);
                break;

            case InstructionType.GetObject:
                command = new GetObjectCommand(StateCommuter);
                break;

            default:
                throw new ParseException($"The XamlInstructionType {instruction.InstructionType} has an unexpected value");
            }

            command.Execute();
        }
Example #25
0
        public string ProcessCommand(string content)
        {
            var requestData = JsonConvert.DeserializeObject <Command>(content);
            var command     = requestData.Name;
            var parameters  = requestData.Parameters;

            string elementId = null;

            if (parameters == null)
            {
                throw new NullReferenceException("Parameters can not be NULL");
            }

            JToken elementIdObject;

            if (parameters.TryGetValue("ID", out elementIdObject))
            {
                elementId = elementIdObject.ToString();
            }

            CommandBase commandToExecute;

            if (command.Equals("ping"))
            {
                // Service command
                return("<pong>");
            }

            // TODO: Refactor similar to CommandExecutors in Driver
            if (command.Equals(DriverCommand.GetAlertText))
            {
                commandToExecute = new AlertTextCommand();
            }
            else if (command.Equals(DriverCommand.AcceptAlert))
            {
                commandToExecute = new AlertCommand {
                    Action = AlertCommand.With.Accept
                };
            }
            else if (command.Equals(DriverCommand.DismissAlert))
            {
                commandToExecute = new AlertCommand {
                    Action = AlertCommand.With.Dismiss
                };
            }
            else if (command.Equals(DriverCommand.FindElement) || command.Equals(DriverCommand.FindChildElement))
            {
                commandToExecute = new ElementCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.FindElements) || command.Equals(DriverCommand.FindChildElements))
            {
                commandToExecute = new ElementsCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.ClickElement))
            {
                commandToExecute = new ClickCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.SendKeysToElement))
            {
                var values = ((JArray)parameters["value"]).ToObject <List <string> >();
                var value  = string.Empty;
                if (values.Any())
                {
                    value = values.Aggregate((aggregated, next) => aggregated + next);
                }

                commandToExecute = new ValueCommand {
                    ElementId = elementId, KeyString = value
                };
            }
            else if (command.Equals(DriverCommand.GetElementText))
            {
                commandToExecute = new TextCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.IsElementDisplayed))
            {
                commandToExecute = new DisplayedCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.GetElementLocation))
            {
                commandToExecute = new LocationCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.GetElementLocationOnceScrolledIntoView))
            {
                commandToExecute = new LocationInViewCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.GetElementSize))
            {
                commandToExecute = new GetElementSizeCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.GetElementRect))
            {
                commandToExecute = new GetElementRectCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.GetPageSource))
            {
                commandToExecute = new PageSourceCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.GetOrientation))
            {
                commandToExecute = new OrientationCommand();
            }
            else if (command.Equals(DriverCommand.GetElementAttribute))
            {
                commandToExecute = new GetElementAttributeCommand {
                    ElementId = elementId
                };
            }
            else if (command.Equals(DriverCommand.ExecuteScript))
            {
                commandToExecute = new ExecuteCommand();
            }
            else if (command.Equals(ExtendedDriverCommand.InvokeAppBarItemCommand))
            {
                commandToExecute = new InvokeAppBarItemCommand();
            }
            else if (command.Equals(ExtendedDriverCommand.InvokeMethodCommand))
            {
                commandToExecute = new InvokeMethodCommand();
            }
            else
            {
                throw new NotImplementedException("Not implemented: " + command);
            }

            // TODO: Replace passing Automator to command with passing some kind of configuration
            commandToExecute.Automator  = this;
            commandToExecute.Parameters = parameters;

            var response = commandToExecute.Do();

            return(response);
        }
Example #26
0
        public void Process(XamlInstruction instruction)
        {
            Command command;

            switch (instruction.InstructionType)
            {
                case XamlInstructionType.NamespaceDeclaration:
                    command = new NamespaceDeclarationCommand(this, instruction.NamespaceDeclaration);
                    break;
                case XamlInstructionType.StartObject:
                    command = new StartObjectCommand(this, instruction.XamlType, rootInstance);
                    break;
                case XamlInstructionType.StartMember:
                    command = new StartMemberCommand(this, GetMember(instruction.Member));
                    break;
                case XamlInstructionType.Value:
                    command = new ValueCommand(this, topDownValueContext, (string)instruction.Value);
                    break;
                case XamlInstructionType.EndObject:
                    command = new EndObjectCommand(this);
                    break;
                case XamlInstructionType.EndMember:
                    command = new EndMemberCommand(this, topDownValueContext);
                    break;
                case XamlInstructionType.GetObject:
                    command = new GetObjectCommand(this);
                    break;
                default:
                    throw new XamlParseException($"The XamlInstructionType {instruction.InstructionType} has an unexpected value");
            }

            command.Execute();
        }
        public void Process(XamlNode node)
        {
            Command command;

            switch (node.NodeType)
            {
                case XamlNodeType.NamespaceDeclaration:
                    command = new NamespaceDeclarationCommand(this, node.NamespaceDeclaration);
                    break;
                case XamlNodeType.StartObject:
                    command = new StartObjectCommand(this, node.XamlType, rootInstance);
                    break;
                case XamlNodeType.StartMember:
                    command = new StartMemberCommand(this, GetMember(node.Member));
                    break;
                case XamlNodeType.Value:
                    command = new ValueCommand(this, (string)node.Value);
                    break;
                case XamlNodeType.EndObject:
                    command = new EndObjectCommand(this);
                    break;
                case XamlNodeType.EndMember:
                    command = new EndMemberCommand(this, topDownMemberValueContext);
                    break;
                case XamlNodeType.GetObject:
                    command = new GetObjectCommand(this);
                    break;
                default:
                    throw new InvalidOperationException();
            }

            command.Execute();
        }
Example #28
0
 public IActionResult Post([FromBody] ValueCommand value)
 {
     Program.systemNode.SendCommandAsync(value);
     return(Ok(value));
 }