コード例 #1
0
        public void Disconnect_Should_Disconnect_From_Node()
        {
            var commandContext = TestCommandHelpers.GenerateCliCommandContext();

            var nodeRpcClient = TestCommandHelpers.MockNodeRpcClient();

            TestCommandHelpers.MockActiveConnection(commandContext, nodeRpcClient);
            TestCommandHelpers.MockNodeRpcClientFactory(commandContext, nodeRpcClient);
            var rpcNodeConfig        = TestCommandHelpers.MockRpcNodeConfig(commandContext);
            var socketClientRegistry = TestCommandHelpers.AddClientSocketRegistry(commandContext, _testScheduler);

            var clientHashCode =
                socketClientRegistry.GenerateClientHashCode(
                    EndpointBuilder.BuildNewEndPoint(rpcNodeConfig.HostAddress, rpcNodeConfig.Port));

            socketClientRegistry.AddClientToRegistry(clientHashCode, nodeRpcClient);

            var commands = new List <ICommand> {
                new DisconnectCommand(commandContext, Substitute.For <ILogger>())
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var isCommandParsed = console.ParseCommand("disconnect", "-n", "node1");

            isCommandParsed.Should().BeTrue();

            socketClientRegistry.Registry.Count.Should().Be(0);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public static void GenerateRequest(ICommandContext commandContext,
                                           ICommand command,
                                           params string[] commandArgs)
        {
            var commands = new List <ICommand> {
                command
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            commandArgs = commandArgs.ToList().Prepend(command.CommandName).ToArray();
            console.ParseCommand(commandArgs);
        }
コード例 #4
0
ファイル: ConnectTests.cs プロジェクト: jakubbober/Catalyst
        public void Cannot_Connect_With_Invalid_Config()
        {
            var commandContext = TestCommandHelpers.GenerateCliCommandContext();

            commandContext.GetNodeConfig(Arg.Any <string>()).Returns((IRpcClientConfig)null);

            var commands = new List <ICommand> {
                new ConnectCommand(commandContext, _logger)
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var exception = Assert.Throws <ArgumentNullException>(() => console.ParseCommand("connect", "-n", "node1"));
        }
コード例 #5
0
        public void ParseCommand_That_Does_Exist_Should_Return_True()
        {
            var userOutput = Substitute.For <IUserOutput>();
            var command    = Substitute.For <ICommand>();

            command.CommandName.Returns("test");
            command.Parse(Arg.Any <string[]>()).Returns(true);

            var commands = new List <ICommand> {
                command
            };
            var catalystCli = new CatalystCli(userOutput, commands);

            catalystCli.ParseCommand("test").Should().BeTrue();
        }
コード例 #6
0
        public void Cannot_Connect_With_Invalid_SocketChannel()
        {
            var commandContext = TestCommandHelpers.GenerateCliCommandContext();

            TestCommandHelpers.MockRpcNodeConfig(commandContext);

            var commands = new List <ICommand> {
                new ConnectCommand(commandContext, _logger)
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var isCommandParsed = console.ParseCommand("connect", "-n", "test");

            isCommandParsed.Should().BeFalse();

            commandContext.UserOutput.Received(1).WriteLine(ConnectCommand.InvalidSocketChannel);
        }
コード例 #7
0
        public void Connect_Should_Connect_To_Node()
        {
            var commandContext = TestCommandHelpers.GenerateCliFullCommandContext();

            TestCommandHelpers.AddClientSocketRegistry(commandContext, _testScheduler);

            var commands = new List <ICommand> {
                new ConnectCommand(commandContext, _logger)
            };
            var console = new CatalystCli(commandContext.UserOutput, commands);

            var isCommandParsed = console.ParseCommand("connect", "-n", "test");

            isCommandParsed.Should().BeTrue();

            commandContext.SocketClientRegistry.Registry.Count.Should().Be(1);
            commandContext.UserOutput.Received(1)
            .WriteLine($"Connected to Node {commandContext.GetConnectedNode("test").Channel.RemoteAddress}");
        }