public void CreateCommandXElement_NullActionResultExecutor_ThrowsArgumentNullException()
        {
            var elementCommand = new ElementCommand("command", "#selector", "<div>Some HTML!</div>");

            Action action = () => elementCommand.CreateCommandXElement(null);

            action.ShouldThrow <ArgumentNullException>();
        }
        public void Equals_OtherElementCommandIsSameObject_ReturnsTrue()
        {
            var elementCommand = new ElementCommand("command", "#selector", "<div>Some HTML!</div>");

            var result = elementCommand.Equals(elementCommand);

            result.Should().BeTrue();
        }
        public void Equals_OtherElementCommandIsNull_ReturnsFalse()
        {
            var            elementCommand = new ElementCommand("command", "#selector", "<div>Some HTML!</div>");
            ElementCommand other          = null;

            var result = elementCommand.Equals(other);

            result.Should().BeFalse();
        }
        public void Equals_OtherObjectIsNotAnElementCommand_ReturnsFalse()
        {
            var other          = new object();
            var elementCommand = new ElementCommand("command", "#selector", "<div>Some HTML!</div>");

            var result = elementCommand.Equals(other);

            result.Should().BeFalse();
        }
Example #5
0
        public void Equals_OtherNonElementCommandIsNull_ReturnsFalse()
        {
            var            nonElementCommand = new NonElementCommand("command", "#selector");
            ElementCommand other             = null;

            var result = nonElementCommand.Equals(other);

            result.Should().BeFalse();
        }
        TaconiteResult IPluginCommandWithContentOrArgumentSyntax.WithContent(string html)
        {
            if (html == null)
            throw new ArgumentNullException("html");

              var command = new ElementCommand(_plugin, _selector, html);
              Result.AddCommand(command);

              return Result;
        }
        TaconiteResult IPluginCommandWithContentOrArgumentSyntax.WithContent(PartialViewResult partial)
        {
            if (partial == null)
            throw new ArgumentNullException("partial");

              var command = new ElementCommand(_plugin, _selector, partial);
              Result.AddCommand(command);

              return Result;
        }
        public TaconiteResult WithContent(PartialViewResult partialViewResult)
        {
            if (partialViewResult == null)
            throw new ArgumentNullException("partialViewResult");

              var command = new ElementCommand("replaceContent", _selector, partialViewResult);
              Result.AddCommand(command);

              return Result;
        }
        public TaconiteResult WithContent(string html)
        {
            if (String.IsNullOrEmpty(html))
            throw new ArgumentNullException("html");

              var command = new ElementCommand("replaceContent", _selector, html);
              Result.AddCommand(command);

              return Result;
        }
        public void Equals_OneHtmlAndOnePartialViewResult_ReturnsFalse()
        {
            var command         = "command";
            var selector        = "#selector";
            var elementCommand0 = new ElementCommand(command, selector, "<div>Some HTML!</div>");
            var elementCommand1 = new ElementCommand(command, selector, new PartialViewResult());

            var result = elementCommand0.Equals(elementCommand1);

            result.Should().BeFalse();
        }
        public void Equals_PartialViewResult_PartialViewResultsDifferent_ReturnsFalse()
        {
            var command         = "command";
            var selector        = "#selector";
            var elementCommand0 = new ElementCommand(command, selector, new PartialViewResult());
            var elementCommand1 = new ElementCommand(command, selector, new PartialViewResult());

            var result = elementCommand0.Equals(elementCommand1);

            result.Should().BeFalse();
        }
        public void Equals_Html_OtherElementCommandPropertiesDifferent_ReturnsFalse(
            string command0, string selector0, string html0,
            string command1, string selector1, string html1)
        {
            var elementCommand0 = new ElementCommand(command0, selector0, html0);
            var elementCommand1 = new ElementCommand(command1, selector1, html1);

            var result = elementCommand0.Equals(elementCommand1);

            result.Should().BeFalse();
        }
        public void GetHashCode_OneHtmlAndOnePartialViewResult_ReturnsFalse()
        {
            var command         = "command";
            var selector        = "#selector";
            var elementCommand0 = new ElementCommand(command, selector, "<div>Some HTML!</div>");
            var elementCommand1 = new ElementCommand(command, selector, new PartialViewResult());

            var result0 = elementCommand0.GetHashCode();
            var result1 = elementCommand1.GetHashCode();

            result0.Should().NotBe(result1);
        }
        public void GetHashCode_Html_ElementCommandsHaveDifferentProperties_ReturnsDifferentHashCode(
            string command0, string selector0, string html0,
            string command1, string selector1, string html1)
        {
            var elementCommand0 = new ElementCommand(command0, selector0, html0);
            var elementCommand1 = new ElementCommand(command1, selector1, html1);

            var result0 = elementCommand0.GetHashCode();
            var result1 = elementCommand1.GetHashCode();

            result0.Should().NotBe(result1);
        }
        public void Equals_PartialViewResult_OtherElementCommandPropertiesSame_ReturnsTrue()
        {
            var command           = "command";
            var selector          = "#selector";
            var partialViewResult = new PartialViewResult();
            var elementCommand0   = new ElementCommand(command, selector, partialViewResult);
            var elementCommand1   = new ElementCommand(command, selector, partialViewResult);

            var result = elementCommand0.Equals(elementCommand1);

            result.Should().BeTrue();
        }
        public void GetHashCode_PartialViewResult_PartialViewResultsDifferent_ReturnsDifferentHashCode()
        {
            var command         = "command";
            var selector        = "#selector";
            var elementCommand0 = new ElementCommand(command, selector, new PartialViewResult());
            var elementCommand1 = new ElementCommand(command, selector, new PartialViewResult());

            var result0 = elementCommand0.GetHashCode();
            var result1 = elementCommand1.GetHashCode();

            result0.Should().NotBe(result1);
        }
Example #17
0
        public TaconiteResult WithContent(PartialViewResult partialViewResult)
        {
            if (partialViewResult == null)
            {
                throw new ArgumentNullException("partialViewResult");
            }

            var command = new ElementCommand("replaceContent", _selector, partialViewResult);

            Result.AddCommand(command);

            return(Result);
        }
Example #18
0
        public TaconiteResult WithContent(string html)
        {
            if (String.IsNullOrEmpty(html))
            {
                throw new ArgumentNullException("html");
            }

            var command = new ElementCommand("replaceContent", _selector, html);

            Result.AddCommand(command);

            return(Result);
        }
        TaconiteResult IPluginCommandWithContentOrArgumentSyntax.WithContent(PartialViewResult partial)
        {
            if (partial == null)
            {
                throw new ArgumentNullException("partial");
            }

            var command = new ElementCommand(_plugin, _selector, partial);

            Result.AddCommand(command);

            return(Result);
        }
        TaconiteResult IPluginCommandWithContentOrArgumentSyntax.WithContent(string html)
        {
            if (html == null)
            {
                throw new ArgumentNullException("html");
            }

            var command = new ElementCommand(_plugin, _selector, html);

            Result.AddCommand(command);

            return(Result);
        }
        /// <summary>
        /// Specifies the jQuery selector for the target element(s).
        /// </summary>
        /// <param name="selector">The jQuery selector for the target element(s).</param>
        TaconiteResult IAppendCommandToTargetSyntax.To(string selector)
        {
            if (String.IsNullOrEmpty(selector))
            throw new ArgumentNullException("selector");

              ElementCommand command;
              if (_html != null)
            command = new ElementCommand("append", selector, _html);
              else
            command = new ElementCommand("append", selector, _partialViewResult);

              Result.AddCommand(command);

              return Result;
        }
        TaconiteResult IInsertCommandBeforeOrAfterTargetSyntax.Before(string selector)
        {
            if (String.IsNullOrEmpty(selector))
            throw new ArgumentNullException("selector");

              ElementCommand command;
              if (_html != null)
            command = new ElementCommand("before", selector, _html);
              else
            command = new ElementCommand("before", selector, _partialViewResult);

              Result.AddCommand(command);

              return Result;
        }
        public TaconiteResult WithPartialView(string viewName, object model)
        {
            var partialViewResult = new PartialViewResult
            {
                ViewName             = viewName,
                ViewData             = new ViewDataDictionary(model),
                TempData             = new TempDataDictionary(),
                ViewEngineCollection = ViewEngines.Engines
            };

            var command = new ElementCommand(_plugin, _selector, partialViewResult);

            Result.AddCommand(command);

            return(Result);
        }
        public void CreateCommandXElement_RawHtml_ReturnsCorrectXElement()
        {
            var command              = "command";
            var selector             = "#selector";
            var html                 = "<div>Some HTML!</div>";
            var elementCommand       = new ElementCommand(command, selector, html);
            var controllerContext    = Substitute.For <ControllerContext>();
            var actionResultExecutor = Substitute.For <ActionResultExecutor>(controllerContext);

            var result = elementCommand.CreateCommandXElement(actionResultExecutor);

            result.Name.Should().Be((XName)command);
            result.Should().HaveAttribute("select", selector);
            result.FirstNode.NodeType.Should().Be(XmlNodeType.CDATA);
            result.Value.Should().Be(html);
        }
Example #25
0
        /// <summary>
        /// Specifies the jQuery selector for the target element(s).
        /// </summary>
        /// <param name="selector">The jQuery selector for the target element(s).</param>
        TaconiteResult IPrependCommandToTargetSyntax.To(string selector)
        {
            if (String.IsNullOrEmpty(selector))
            {
                throw new ArgumentNullException("selector");
            }

            ElementCommand command;

            if (_html != null)
            {
                command = new ElementCommand("prepend", selector, _html);
            }
            else
            {
                command = new ElementCommand("prepend", selector, _partialViewResult);
            }

            Result.AddCommand(command);

            return(Result);
        }
Example #26
0
        TaconiteResult IInsertCommandBeforeOrAfterTargetSyntax.After(string selector)
        {
            if (String.IsNullOrEmpty(selector))
            {
                throw new ArgumentNullException("selector");
            }

            ElementCommand command;

            if (_html != null)
            {
                command = new ElementCommand("after", selector, _html);
            }
            else
            {
                command = new ElementCommand("after", selector, _partialViewResult);
            }

            Result.AddCommand(command);

            return(Result);
        }
Example #27
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);
        }
        public TaconiteResult WithPartialView(string viewName, object model)
        {
            var partialViewResult = new PartialViewResult
            {
              ViewName = viewName,
              ViewData = new ViewDataDictionary(model),
              TempData = new TempDataDictionary(),
              ViewEngineCollection = ViewEngines.Engines
            };

              var command = new ElementCommand(_plugin, _selector, partialViewResult);
              Result.AddCommand(command);

              return Result;
        }
Example #29
0
        public void InsertCommandNote(String noteText, ElementCommand command, Element target)
        {
            Element commandNote = CreateNewElement(ElementType.Note, noteText);
            commandNote.Command = command;
            commandNote.Status = ElementStatus.Special;
            commandNote.TailImageSource = String.Format("pack://application:,,,/{0};component/{1}", "Planz", "Images/command.png");
            commandNote.HasAssociation = true;
            commandNote.CanOpen = false;
            commandNote.CanExplore = false;
            commandNote.CanRename = false;
            commandNote.CanDelete = false;

            bool hasSameCommand = false;
            foreach (Element ele in target.Elements)
            {
                if (ele.IsCommandNote && ele.Command == command)
                {
                    hasSameCommand = true;
                    break;
                }
            }
            if (!hasSameCommand)
            {
                InsertElement(commandNote, target, 0);
            }
        }