Esempio n. 1
0
        public async Task CanProcessCommand()
        {
            var serverUri = new Uri("http://acme.com/d");

            var settingsMock = new Mock <IUserSettings>(MockBehavior.Strict);

            settingsMock.Setup(m => m.SetDefaultServer(serverUri)).Returns(Task.CompletedTask);

            var ctxMock = new Mock <IAcmeContext>(MockBehavior.Strict);

            ctxMock.Setup(m => m.GetDirectory()).ReturnsAsync(MockDirectoryV2);

            var cmd    = new ServerSetCommand(settingsMock.Object, (u, k) => ctxMock.Object);
            var syntax = DefineCommand($"set {serverUri}");

            var ret = await cmd.Execute(syntax);

            Assert.Equal(
                JsonConvert.SerializeObject(ret),
                JsonConvert.SerializeObject(new
            {
                location = serverUri,
                resource = MockDirectoryV2
            }));

            syntax = DefineCommand($"set");
            await Assert.ThrowsAsync <ArgumentSyntaxException>(() => cmd.Execute(syntax));
        }
Esempio n. 2
0
        private static ArgumentSyntax DefineCommand(string args)
        {
            var cmd = new ServerSetCommand(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);
            }));
        }
Esempio n. 3
0
        public async Task CanProcessCommand()
        {
            var serverUri = new Uri("http://acme.com/d");

            var settingsMock = new Mock <IUserSettings>(MockBehavior.Strict);

            settingsMock.Setup(m => m.SetDefaultServer(serverUri)).Returns(Task.CompletedTask);

            var ctxMock = new Mock <IAcmeContext>(MockBehavior.Strict);

            ctxMock.Setup(m => m.GetDirectory()).ReturnsAsync(MockDirectoryV2);

            var(console, stdOutput, errOutput) = MockConsole();

            var cmd = new ServerSetCommand(
                settingsMock.Object, (u, k) => ctxMock.Object);
            var command = cmd.Define();

            await command.InvokeAsync($"set {serverUri}", console.Object);

            Assert.True(errOutput.Length == 0, errOutput.ToString());
            var ret = JsonConvert.DeserializeObject(stdOutput.ToString());

            Assert.Equal(
                JsonConvert.SerializeObject(ret, JsonSettings),
                JsonConvert.SerializeObject(new
            {
                location = serverUri,
                resource = MockDirectoryV2
            }, JsonSettings));

            errOutput.Clear();
            stdOutput.Clear();

            await command.InvokeAsync($"set", console.Object);

            Assert.False(errOutput.Length == 0, "Should print error");
        }