Exemple #1
0
        public void Constructor_Sets_Help_WhenEmpty()
        {
            var help = string.Empty;
            var gc   = new GlobalCommand("TestTest", help, Access.Administrator);

            Assert.IsTrue(gc.Help == help);
        }
Exemple #2
0
        public void Constructor_Sets_Name()
        {
            var expected = "ex";
            var gc       = new GlobalCommand(expected, "help", Access.Administrator);

            Assert.IsTrue(gc.Name == expected);
        }
Exemple #3
0
 public void MyTestInitialize()
 {
     underTest = new GlobalCommand("app", "app", Access.Administrator);
     underTest.AddToConsole();
     testWriter = new TestConsoleWriter();
     ConsoleBase.RegisterConsoleWriter(testWriter);
 }
 public void MyTestCleanup()
 {
     global.RemoveCommand(command);
     global  = null;
     command = null;
     CrestronConsole.Messages.Length = 0;
 }
 public void MyTestInitialize()
 {
     global  = new GlobalCommand("app", "App Command", Access.Administrator);
     command = new TestCommand();
     global.AddCommand(command);
     global.AddCommand(new TestCommand2());
 }
Exemple #6
0
        public void Constructor_Sets_Help_WhenShortHelp()
        {
            var help = "HelpTest";
            var gc   = new GlobalCommand("TestTest", help, Access.Administrator);

            Assert.IsTrue(gc.Help == help);
        }
Exemple #7
0
        public void RemoveFromConsole_ReturnsFalse_WhenNoCommandAdded()
        {
            var expected = false;
            var gc       = new GlobalCommand("aps", "help", Access.Administrator);
            var actual   = gc.RemoveFromConsole();

            Assert.IsTrue(actual == expected);
        }
Exemple #8
0
        public void AddToConsole_ReturnsTrue_WhenServer_AndConsoleReturnsFalse()
        {
            Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = false;
            Crestron.SimplSharp.CrestronEnvironment.DevicePlatform         = Crestron.SimplSharp.eDevicePlatform.Server;

            var gc     = new GlobalCommand("spa", "Help", Access.Administrator);
            var actual = gc.AddToConsole();

            Assert.IsTrue(actual);
        }
Exemple #9
0
        public void Constructor_Truncates_Help_When_TooLong()
        {
            var help     = "This help is longer than 79 characters long and is going to be truncated by the constructor.";
            var expected = "This help is longer than 79 characters long and is going to be truncated by ...";
            var gc       = new GlobalCommand("TestTest", help, Access.Administrator);

            Trace.WriteLine("Help: '" + gc.Help + "'");

            Assert.IsTrue(gc.Help == expected);
        }
Exemple #10
0
 public void MyTestCleanup()
 {
     underTest.RemoveFromConsole();
     underTest.Dispose();
     underTest = null;
     Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true;
     Crestron.SimplSharp.CrestronEnvironment.DevicePlatform         = Crestron.SimplSharp.eDevicePlatform.Appliance;
     ConsoleBase.UnregisterConsoleWriter(testWriter);
     testWriter = null;
 }
Exemple #11
0
        public void RemoveFromConsole_ReturnsTrue_WhenCommandAdded()
        {
            var expected = true;
            var gc       = new GlobalCommand("aps", "help", Access.Administrator);

            Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true;
            gc.AddToConsole();
            var actual = gc.RemoveFromConsole();

            Assert.IsTrue(actual == expected);
        }
Exemple #12
0
 public void MyTestCleanup()
 {
     global.RemoveCommand(command);
     global  = null;
     command = null;
     CrestronConsole.Messages.Length = 0;
     if (writer != null)
     {
         ConsoleBase.UnregisterConsoleWriter(writer);
     }
 }
Exemple #13
0
        public void Dispose_RemovesFromConsole_When_Called()
        {
            var c1 = new TestCommand();

            var gc = new GlobalCommand("temp", "help", Access.Administrator);

            gc.AddToConsole();
            gc.Dispose();

            Assert.IsFalse(gc.RemoveFromConsole());
        }
 /// <summary>
 /// Creates a global command, adding it to the <see cref="CrestronConsole"/>.
 /// </summary>
 /// <param name="command">The <see cref="GlobalCommand"/> to register.</param>
 /// <returns><see langword="true"/> if the command is newly registered, <see langword="false"/> if it isn't registered because a command with that name already was.</returns>
 public static bool RegisterCrestronConsoleCommand(GlobalCommand command)
 {
     if (consoleCommandNames.ContainsKey(command.Name))
     {
         return(false);
     }
     else
     {
         consoleCommandNames.Add(command.Name, command);
         return(true);
     }
 }
Exemple #15
0
        public void Constructor_Sets_CommandAccess_Tests()
        {
            var gc1 = new GlobalCommand("Test", "Help", Access.Operator);

            Assert.IsTrue(gc1.CommandAccess == Access.Operator);

            var gc2 = new GlobalCommand("Test", "Help", Access.Programmer);

            Assert.IsTrue(gc2.CommandAccess == Access.Programmer);

            var gc3 = new GlobalCommand("Test", "Help", Access.Administrator);

            Assert.IsTrue(gc3.CommandAccess == Access.Administrator);
        }
Exemple #16
0
        public void Dispose_RemovesAllCommands_When_Called()
        {
            var c1 = new TestCommand();

            var gc = new GlobalCommand("temp", "help", Access.Administrator);

            gc.AddToConsole();
            gc.AddCommand(c1);

            Assert.IsTrue(gc.IsCommandRegistered(c1));

            gc.Dispose();

            Assert.IsFalse(gc.IsCommandRegistered(c1));
        }
Exemple #17
0
        public void GetAllGlobalCommands_ReturnsAllGlobalCommands()
        {
            Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true;
            var gc2 = new GlobalCommand("sap", "Test", Access.Administrator);

            gc2.AddToConsole();

            var gc3 = new GlobalCommand("spsa", "Test", Access.Operator);

            gc3.AddToConsole();

            var values = GlobalCommand.GetAllGlobalCommands();

            Assert.IsTrue(values.Contains(gc2));
            Assert.IsTrue(values.Contains(gc3));
            Assert.IsTrue(values.Contains(underTest));
        }
Exemple #18
0
        public void RegisterCommand_WithExistingName_Returns_CommandInUse()
        {
            Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true;
            var expected = RegisterResult.CommandNameAlreadyExists;
            var gc       = new GlobalCommand("temp", "temp", Access.Administrator);

            gc.AddToConsole();
            var c1 = new TestCommand();
            var c2 = new TestCommand();

            c1.RegisterCommand("temp");
            var actual = c2.RegisterCommand("temp");

            System.Diagnostics.Trace.WriteLine("Register result: '" + actual + "'");
            Assert.IsTrue(expected == actual);

            c1.UnregisterCommand();
            gc = null;
        }
Exemple #19
0
 public void Constructor_Throws_ArgumentOutOfRangeException_When_NameTooLong()
 {
     var gc = new GlobalCommand("This name is longer than 23 characters.", "Help", Access.Administrator);
 }
Exemple #20
0
 public void Constructor_Throws_ArgumentOutOfRangeException_When_Name_Empty()
 {
     var gc = new GlobalCommand(string.Empty, "Help", Access.Administrator);
 }