public void GetVersionCommand_WhenCreated_TheIdentifierIsCorrect()
        {
            //Act
            Command command = new GetVersionCommand();

            //Assert
            Assert.AreEqual('V', command.Identifier);
        }
        public string GetVersion()
        {
            IGetVersionCommand command = new GetVersionCommand(new OptionObject());

            if (command == null)
            {
                logger.Error("A valid GetVersion command was not retrieved.");
                return("");
            }
            return(command.Execute());
        }
        public void ParseCommand_That_Does_Not_Exist_Should_Return_False()
        {
            var userOutput = Substitute.For <IUserOutput>();
            var command    = new GetVersionCommand(_commandContext, Substitute.For <ILogger>());
            var commands   = new List <ICommand> {
                command
            };
            var catalystCli = new CatalystCli(userOutput, commands);

            catalystCli.ParseCommand("test").Should().BeFalse();
        }
        public void Execute_String_ReturnsString()
        {
            // Arrange
            string             expected = "";
            IGetVersionCommand command  = new GetVersionCommand(typeof(string));

            // Act
            var actual = command.Execute();

            // Assert
            Assert.AreEqual(expected.GetType(), actual.GetType());
        }
        public void GetVersionRequest_Can_Be_Sent()
        {
            //Arrange
            var commandContext = TestCommandHelpers.GenerateCliRequestCommandContext();
            var connectedNode  = commandContext.GetConnectedNode(null);
            var command        = new GetVersionCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateRequest(commandContext, command, "-n", "node1");

            //Assert
            var requestSent = TestCommandHelpers.GetRequest <VersionRequest>(connectedNode);

            requestSent.Should().BeOfType(typeof(VersionRequest));
        }
        public void GetVersionResponse_WhenConstructed_BuildNumberIsParsedCorrectly()
        {
            //Arrange
            GetVersionCommand command = new GetVersionCommand();

            byte[] data = ResponseHelper.AppendChecksum(new byte[] { 0x56, 0x01, 0x02, 0x03 });
            byte[] test = ResponseHelper.AppendChecksum(new byte[] { 0x56, 0x78, 0x9A, 0xBC });

            //Act
            GetVersionResponse response = new GetVersionResponse(command, data);

            //Assert
            Assert.AreEqual(0x01, response.Major, "The Major version number is not correct.");
            Assert.AreEqual(0x02, response.Minor, "The Minor version number is not correct.");
            Assert.AreEqual(0x03, response.Revision, "The Revision version number is not correct.");
        }
Beispiel #7
0
        public void GetVersionResponse_Can_Get_Output()
        {
            //Arrange
            var versionResponse = new VersionResponse {
                Version = "1.2.3.4"
            };
            var commandContext    = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getVersionCommand = new GetVersionCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, versionResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(versionResponse.ToJsonString());
        }
Beispiel #8
0
        public override bool Execute()
        {
            bool isOk = false;

            try
            {
                var pingCmd = new PingCommand(_appState, _commsPort);
                pingCmd.Execute();
                isOk = pingCmd.IsSuccessful;
                if (isOk)
                {
                    var versionCmd = new GetVersionCommand(_appState, _commsPort);
                    versionCmd.Execute();
                    isOk     = versionCmd.IsSuccessful;
                    _version = isOk ? versionCmd.Version : "";
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                OnCompeted();
                if (!isOk)
                {
                    if (MessageBox.Show(_mainForm,
                                        string.Format("Connection failed on port {0}.  \nWould you like to change the settings?", Settings.Default.COMPort),
                                        Application.ProductName,
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information,
                                        MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        //show options
                        var cmd = new OpenOptionsStripCommand(_appState, _commsPort, _commsPortFactory);
                        cmd.Execute();
                    }
                }
            }
            return(isOk);
        }
Beispiel #9
0
        protected void OnConnectActionActivated(object sender, EventArgs e)
        {
            var isOk = false;

            try {
                // TODO: This code is duplicated with WinForms.StripCommands.ConnectStripCommand
                var pingCmd = new PingCommand(appState, commsPort);
                pingCmd.Execute();
                isOk = pingCmd.IsSuccessful;
                if (isOk)
                {
                    var versionCmd = new GetVersionCommand(appState, commsPort);
                    versionCmd.Execute();
                    isOk = versionCmd.IsSuccessful;
                    //version = isOk ? versionCmd.Version : "";
                }
            } catch (Exception ex) {
                var dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error,
                                               ButtonsType.Ok, "Failed to connect:\n%s", ex.Message);
                dialog.Run();
            }
        }