Пример #1
0
        public void Run()
        {
            while (true)
            {
                string   input = Console.ReadLine();
                ICommand Command;
                switch (input.ToUpper())
                {
                case "CLEAR":
                    Command = new ClearCommand();
                    Command.Execute();
                    break;

                case "VERSION":
                    Command = new VersionCommand();
                    Command.Execute();
                    break;

                default:
                    Command = new NullCommand();
                    Command.Execute();
                    break;
                }
            }
        }
        private void DataResource_Changed(object sender, EventArgs e)
        {
            // Ensure that the bound object is updated when DataResource changes.
            DataResource       dataResource = (DataResource)sender;
            DependencyProperty depProp      = mTargetProperty as DependencyProperty;

            if (depProp != null)
            {
                DependencyObject depObj = (DependencyObject)mTargetObject;
                object           value  = Convert(dataResource.BindingTarget, depProp.PropertyType);
                depObj.SetValue(depProp, value);
            }
            else
            {
                PropertyInfo propInfo = mTargetProperty as PropertyInfo;
                if (propInfo != null)
                {
                    object value = Convert(dataResource.BindingTarget, propInfo.PropertyType);

                    // extra support for commands here. Some classes don't allow a null
                    // command for example InputBinding. In this case we use a dummy
                    // command (NullCommand) instead of setting a null value.

                    if (value == null && propInfo.PropertyType.IsAssignableFrom(typeof(ICommand)))
                    {
                        value = new NullCommand();
                    }

                    propInfo.SetValue(mTargetObject, value, new object[0]);
                }
            }
        }
        public void ReturnAnErrorResponseWhenExecuted()
        {
            var nullCommand     = new NullCommand();
            var commandResponse = nullCommand.Execute();

            Assert.That(commandResponse.Status, Is.EqualTo(CommandResponseStatus.Error));
        }
Пример #4
0
        public async void NullCommandTestAll()
        {
            NullCommand n     = NullCommand.Instance;
            var         token = new CancellationToken();

            await n.ExecuteAsync(token);

            await n.UndoAsync(token);

            Assert.Equal("[Null]", n.Show());
        }
Пример #5
0
        public void ShouldDoNothingWhenExecuted()
        {
            //GIVEN
            var command = new NullCommand();

            //WHEN
            var core = Substitute.For <ISharedCore>();

            command.ExecuteOn(core);

            //THEN
            core.ReceivedNothing();
        }
Пример #6
0
        public void Test_Command_Writes_Ok_Message()
        {
            var nullMessage = new NullMessage();
            nullMessage.MessageId = 43;

            var command = new NullCommand();

            MemoryStream stream = new MemoryStream();

            command.Execute(nullMessage, stream);

            var sentMessage = new OkMessage();

            sentMessage.Decode(stream.GetBuffer());

            Assert.Equal(nullMessage.MessageId, sentMessage.MessageId);
        }
Пример #7
0
        public ICommand MakeCommand(string commandName)
        {
            ICommand commandToReturn;

            Type t = GetTypeToCreate(commandName);

            if (t == null)
            {
                commandToReturn = new NullCommand();
            }
            else
            {
                commandToReturn = Activator.CreateInstance(t) as ICommand;
            }

            return(commandToReturn);
        }
Пример #8
0
        public void ShouldReturnOnlyStartingPosition()
        {
            var       startingPosition = new Position(2, -3);
            const int steps            = 3;
            const int positionLimit    = 10;

            var command = new NullCommand(steps);

            var(lastPosition, positions) = command.Execute(startingPosition, positionLimit);

            var expectedLastPosition = new Position(2, -3);
            var expectedPositions    = new List <Position>
            {
                new Position(2, -3)
            };

            lastPosition.Should().Be(expectedLastPosition);
            positions.Should().BeEquivalentTo(expectedPositions);
        }
Пример #9
0
        /// <summary>
        /// Parse the input for command and arguments string
        /// </summary>
        /// <param name="input"></param>
        /// <param name="command"></param>
        /// <param name="commandArgs"></param>
        public void TryParse(string input, out Command command, out string commandArgs)
        {
            command     = new NullCommand();
            commandArgs = string.Empty;

            if (!string.IsNullOrEmpty(input) && !string.IsNullOrWhiteSpace(input))
            {
                string[] commandText = input.Split(commandDelimiter, StringSplitOptions.RemoveEmptyEntries);
                if (commandText.Length > 0)
                {
                    string commandKey = commandText[commandIndex].ToLower();
                    string args       = commandText.Length > 1 ? commandText[commandIndex + 1] : string.Empty;

                    if (registeredCommands.ContainsKey(commandKey))
                    {
                        command     = registeredCommands[commandKey];
                        commandArgs = args;
                    }
                }
            }
        }
Пример #10
0
        static int Execute(ConsoleCommand cmd)
        {
            ICommand command = new NullCommand();

            switch (cmd.Name)
            {
            case null:
                return(0);

            case "exit":
                command = new ExitCommand();
                break;

            case "find":
                command = new FindCommand(cmd);
                break;

            case "route":
                command = new RouteCommand(cmd);
                break;

            case "multiroute":
                command = new MultiRouteCommand(cmd);
                break;

            case "stats":
                command = new StatsCommand();
                break;

            default:
                Console.WriteLine("Unrecognised command.");
                return(0);
            }

            return(command.Execute());
        }
		private void DataResource_Changed(object sender, EventArgs e)
		{
			// Ensure that the bound object is updated when DataResource changes.
			DataResource dataResource = (DataResource)sender;
			DependencyProperty depProp = mTargetProperty as DependencyProperty;
			
			if (depProp != null)
			{
				DependencyObject depObj = (DependencyObject)mTargetObject;
				object value = Convert(dataResource.BindingTarget, depProp.PropertyType);
				depObj.SetValue(depProp, value);
			}
			else
			{
				PropertyInfo propInfo = mTargetProperty as PropertyInfo;
				if (propInfo != null)
				{
					object value = Convert(dataResource.BindingTarget, propInfo.PropertyType);

                    // extra support for commands here. Some classes don't allow a null
                    // command for example InputBinding. In this case we use a dummy
                    // command (NullCommand) instead of setting a null value.
                    
                    if (value == null && propInfo.PropertyType.IsAssignableFrom( typeof( ICommand ) ) )
                    {
                        value = new NullCommand();
                    }

                    propInfo.SetValue(mTargetObject, value, new object[0]);
				}
			}
		}
 static NullCommand()
 {
     Instance = new NullCommand();
 }
Пример #13
0
        public void FinishesImmediately()
        {
            var command = new NullCommand();

            Assert.Equal("null", command.RunAsync(CancellationToken.None).Result);
        }
Пример #14
0
        public void HasName()
        {
            var nullCommand = new NullCommand();

            Assert.Equal("null", nullCommand.Name);
        }
Пример #15
0
 public NopCommandTests()
 {
     nullCommand = new NullCommand();
 }