public void ThrowCommandNotFoundExceptionWhenNoCommandsRegistered()
        {
            var          ce = new RouterCommand();
            const string UNREGISTERED_COMMAND_ID = "unregistered";

            Assert.Throws <CommandNotFoundException>(() => ce.Execute(UNREGISTERED_COMMAND_ID));
        }
        public void ThrowsnWhenNoArgumentsSupplied(string[] args)
        {
            var router = new RouterCommand();

            var e = Assert.Throws <InvalidCommandArrayException>(() => router.Execute(args));

            Assert.Equal("The given command array was invalid and could not be executed.", e.Message);
        }
        public void ThrowCommandNotFoundExceptionWithMessage(string commandId)
        {
            var ce = new RouterCommand();

            var exception = Assert.Throws <CommandNotFoundException>(() => ce.Execute(commandId));

            Assert.Equal($"Command with ID {commandId} was not found.", exception.Message);
        }
Esempio n. 4
0
        public void RejectNonAlphanumericCommandIds(string commandId)
        {
            var command = new FakeCommand();
            var router  = new RouterCommand();

            var e = Assert.Throws <ArgumentException>(() => router.Register(commandId, command));

            Assert.Equal("Command ID must be alphanumeric.", e.Message);
        }
        public void PassAllParametersExceptCommandIdToCommandExecute(params string[] args)
        {
            var ce = new RouterCommand();
            var ac = new ArgsCommand();

            ce.Register("test", ac);

            ce.Execute(args);

            Assert.True(ac.Args.SequenceEqual(args.Skip(1)));
        }
        public void IgnoresLeadingAndTrailingWhitespaceInCommandIds(string commandId, string commandIdToExecute)
        {
            var ce      = new RouterCommand();
            var command = new SignalCommand();

            ce.Register(commandId, command);

            ce.Execute(commandIdToExecute);

            Assert.True(command.HasBeenRun);
        }
 public void CallDeviceConfig(int serialNo)
 {
     NMSReportCommand nmsReportCommand = ApplicationCache.Instance().CurNMSDataWrapper.Find(serialNo);
     if (nmsReportCommand == null)
     {
         MessageBox.Show("선택하신 디바이스가 존재하지 않습니다");
         return;
     }
     RouterCommand routerCommand = new RouterCommand(nmsReportCommand);
     routerCommand.ShowDialog();
 }
        public void ReturnResultOfExecutedCommand(object objToReturn)
        {
            string        returnCommandId = "return";
            ReturnCommand returnCommand   = new ReturnCommand(objToReturn);
            RouterCommand routerCommand   = new RouterCommand();

            routerCommand.Register(returnCommandId, returnCommand);

            var result = routerCommand.Execute(returnCommandId);

            Assert.Equal(objToReturn, result);
        }
        public void ThrowsWhenCommandThrowsInvalidCommandArrayException()
        {
            var eToThrow = new InvalidCommandArrayException("The given command array was invalid and could no be executed.");
            var thrower  = new ThrowerCommand(eToThrow);
            var router   = new RouterCommand();

            router.Register("throw", thrower);

            var result = Assert.Throws <InvalidCommandArrayException>(() => router.Execute("throw"));

            Assert.Equal("A registered command was given an invalid command array.", result.Message);
            Assert.Equal(eToThrow, result.InnerException);
        }
        public void ExecuteSpecifiedRegisteredCommand(string commandId)
        {
            var ce              = new RouterCommand();
            var commandToRun    = new SignalCommand();
            var commandNotToRun = new SignalCommand();

            ce.Register(commandId, commandToRun);
            ce.Register("anotherCommand", commandNotToRun);

            ce.Execute(commandId);

            Assert.True(commandToRun.HasBeenRun);
            Assert.True(commandNotToRun.HasBeenRun == false);
        }
Esempio n. 11
0
        public static IExecutable MakeApp(string rootPath = ".")
        {
            var main        = new RouterCommand();
            var fs          = new FileSystem();
            var provider    = new FileSystemLevelsProvider(fs, rootPath);
            var initializer = new MasterFolderLevelInitializer(
                new UserJsonLevelInitializationDeterminer(fs),
                new CopyDir(fs),
                provider,
                fs.Path);

            main.Register("levels", new GetLevelsCommand(provider));
            main.Register("open", new OpenLevelCommand(
                              initializer,
                              provider));
            main.Register("instructions", new GetInstructionsPathCommand(provider));
            main.Register("verify", new VerifyCommand(
                              provider,
                              new JarFileVerifier(new JarFileProcessFactory())
                              ));
            main.Register("reset", new ResetLevelCommand(initializer));

            return(main);
        }