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); }
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 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); }
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")); }
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(); }
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); }
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}"); }