public void Serialize()
        {
            Command command = new Command();
            command.Arguments.Add("arg1");
            command.Arguments.Add("arg2");
            command.Id = "cmdTest1";
            command.CommandType = CommandType.Refresh;

            ExecutionException executionException = new ExecutionException("Could not refresh page", null, command);

            using (Stream memory = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(memory, executionException);
                memory.Position = 0; // Reset stream position
                executionException = (ExecutionException)formatter.Deserialize(memory);
            }

            Assert.IsNotNull(executionException, "ExecutionException object was not serialized properly.");
            Assert.IsNotNull(executionException.Command, "Command object was not serialized properly.");
            Assert.AreEqual(command.Arguments.Count, executionException.Command.Arguments.Count);
            Assert.AreEqual(command.Arguments[0], executionException.Command.Arguments[0]);
            Assert.AreEqual(command.Id, executionException.Command.Id);
            Assert.AreEqual(command.CommandType, executionException.Command.CommandType);
        }
Ejemplo n.º 2
0
 public void ExecuteError()
 {
     Command command = new Command();
     command.Execute(null);
 }
Ejemplo n.º 3
0
 public void ExecuteCommandDoNotKwonHow()
 {
     Command command = new Command();
     command.CommandType = CommandType.None;
     Wax.ExecutionContext context = new Wax.ExecutionContext(new TestManager());
     command.Execute(context);
 }
Ejemplo n.º 4
0
        public void Constructor()
        {
            Command command = new Command();

            Assert.AreEqual(CommandType.None, command.CommandType, "Command type not initialized correctly");
            Assert.IsNotNull(command.FindMethod, "Command find method not initialized correctly");
            Assert.AreEqual(string.Empty, command.Id, "Id not initialized correctly");
            Assert.IsNotNull(command.Arguments, "Arguments not initialized correctly");
            Assert.AreEqual(0, command.Arguments.Count, "Arguments not initialized correctly");
        }
        /// <summary>
        /// Validates if the required arguments for a given command have been specified
        /// </summary>
        /// <returns><c>true</c> if required arguments are present otherwise returns <c>false</c>.</returns>
        private static bool ValidateRequiredCommandArguments(Command command)
        {
            bool returnValue;

            switch(command.CommandType)
            {
                case CommandType.Back:
                case CommandType.BringToFront:
                case CommandType.Forward:
                case CommandType.Click:
                case CommandType.ClickNoWait:
                case CommandType.DoubleClick:
                case CommandType.AttachToIE:
                case CommandType.Close:
                case CommandType.Refresh:
                case CommandType.Flash:
                case CommandType.PressTab:
                case CommandType.Focus:
                case CommandType.ClearText:
                case CommandType.SelectText:
                case CommandType.ClearCache:
                case CommandType.ClearCookies:
                case CommandType.Code:
                    returnValue = true;
                    break;
                case CommandType.AppendText:
                case CommandType.GoTo:
                case CommandType.TypeText:
                case CommandType.Screenshot:
                case CommandType.ValidateLastFound:
                    returnValue = command.Arguments.Count == 1;
                    break;
                case CommandType.SetValue:
                case CommandType.SetCookie:
                case CommandType.GetCookie:
                case CommandType.Validate:
                case CommandType.AttachDialogHandler:
                case CommandType.GetJavaDialogMessage:
                    returnValue = command.Arguments.Count == 2;
                    break;
                case CommandType.SetValues:
                case CommandType.ValidateItems:
                    returnValue = command.Arguments.Count > 2;
                    break;
                case CommandType.Settings:
                    returnValue = command.Arguments.Count == 2;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("command", string.Format(CultureInfo.InvariantCulture, "Can not validate unknown command type: {0}", command.CommandType));
            }

            return returnValue;
        }
        /// <summary>
        /// Responsible for creating instances or derived types of <see cref="Command" />, based on
        /// the value of <paramref name="type">command type</paramref>.
        /// </summary>
        /// <param name="type">MethodType of command to create</param>
        /// <returns>Command for the given <paramref name="type">command type</paramref></returns>
        private static Command Create(CommandType type)
        {
            Command returnValue = null;
            switch(type)
            {
                case CommandType.Back:
                case CommandType.BringToFront:
                case CommandType.Forward:
                case CommandType.Flash:
                case CommandType.Click:
                case CommandType.ClickNoWait:
                case CommandType.Refresh:
                case CommandType.DoubleClick:
                case CommandType.GoTo:
                case CommandType.Close:
                case CommandType.AttachToIE:
                case CommandType.PressTab:
                case CommandType.Focus:
                case CommandType.ClearCache:
                case CommandType.ClearCookies:
                case CommandType.Screenshot:
                case CommandType.SetCookie:
                case CommandType.GetCookie:
                    returnValue = new Command();
                    break;
                case CommandType.AttachDialogHandler:
                case CommandType.GetJavaDialogMessage:
                    returnValue = new DialogHandlerCommand();
                    break;
                case CommandType.Validate:
                case CommandType.ValidateItems:
                case CommandType.ValidateLastFound:
                    returnValue = new ValidateCommand();
                    break;
                case CommandType.SetValue:
                case CommandType.SetValues:
                    returnValue = new SetValueCommand();
                    break;
                case CommandType.AppendText:
                case CommandType.TypeText:
                case CommandType.ClearText:
                case CommandType.SelectText:
                    returnValue = new TextFieldCommand();
                    break;
                case CommandType.Settings:
                    returnValue = new SettingsCommand();
                    break;
                case CommandType.Code:
                    returnValue = new CodeCommand();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("command", string.Format(CultureInfo.InvariantCulture, "Can not create a command object for unknown command type: {0}", type));
            }

            return returnValue;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExecutionException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 /// <param name="command">The command.</param>
 /// /// <param name="passou">has .</param>
 public ExecutionException(string message, Exception innerException, Command command,bool passou)
     : base(message, innerException,passou)
 {
     this.Command = command;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExecutionException"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="innerException">The inner exception.</param>
 /// <param name="command">The command.</param>
 public ExecutionException(string message, Exception innerException, Command command)
     : base(message, innerException)
 {
     this.Command = command;
 }