private static ArgumentSyntax DefineCommand(string args) { var cmd = new ServerShowCommand(NoopSettings(), (u, k) => new Mock <IAcmeContext>().Object); Assert.Equal(CommandGroup.Server.Command, cmd.Group.Command); return(ArgumentSyntax.Parse(args.Split(' '), syntax => { syntax.HandleErrors = false; syntax.DefineCommand("noop"); cmd.Define(syntax); })); }
public async Task CanProcessCommand() { var serverUri = new Uri("http://acme.com/d"); var settingsMock = new Mock <IUserSettings>(MockBehavior.Strict); settingsMock.Setup(m => m.GetDefaultServer()).ReturnsAsync(LetsEncryptV2); var ctxMock = new Mock <IAcmeContext>(MockBehavior.Strict); ctxMock.Setup(m => m.GetDirectory()).ReturnsAsync(MockDirectoryV2); var(console, stdOutput, errOutput) = MockConsole(); var cmd = new ServerShowCommand( settingsMock.Object, (u, k) => ctxMock.Object); var command = cmd.Define(); await command.InvokeAsync($"show --server {serverUri}", console.Object); Assert.True(errOutput.Length == 0, errOutput.ToString()); var ret = JsonConvert.DeserializeObject(stdOutput.ToString()); Assert.Equal( JsonConvert.SerializeObject(new { location = serverUri, resource = MockDirectoryV2 }, JsonSettings), JsonConvert.SerializeObject(ret, JsonSettings)); errOutput.Clear(); stdOutput.Clear(); await command.InvokeAsync($"show", console.Object); Assert.True(errOutput.Length == 0, errOutput.ToString()); ret = JsonConvert.DeserializeObject(stdOutput.ToString()); Assert.Equal( JsonConvert.SerializeObject(new { location = LetsEncryptV2, resource = MockDirectoryV2 }, JsonSettings), JsonConvert.SerializeObject(ret, JsonSettings)); }
public async Task CanProcessCommand() { var serverUri = new Uri("http://acme.com/d"); var settingsMock = new Mock <IUserSettings>(MockBehavior.Strict); settingsMock.Setup(m => m.GetDefaultServer()).ReturnsAsync(LetsEncryptV2); var ctxMock = new Mock <IAcmeContext>(MockBehavior.Strict); ctxMock.Setup(m => m.GetDirectory()).ReturnsAsync(MockDirectoryV2); var cmd = new ServerShowCommand(settingsMock.Object, (u, k) => ctxMock.Object); var syntax = DefineCommand($"show --server {serverUri}"); var ret = await cmd.Execute(syntax); Assert.Equal( JsonConvert.SerializeObject(new { location = serverUri, resource = MockDirectoryV2 }), JsonConvert.SerializeObject(ret)); syntax = DefineCommand($"show"); ret = await cmd.Execute(syntax); Assert.Equal( JsonConvert.SerializeObject(new { location = LetsEncryptV2, resource = MockDirectoryV2 }), JsonConvert.SerializeObject(ret)); }