Пример #1
0
        public async Task CanProcessCommand()
        {
            var orderLoc = new Uri("http://acme.com/o/1");
            var order    = new Order
            {
                Identifiers = new[] {
                    new Identifier {
                        Value = "*.a.com"
                    },
                    new Identifier {
                        Value = "*.b.com"
                    },
                }
            };

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

            settingsMock.Setup(m => m.GetDefaultServer()).ReturnsAsync(LetsEncryptV2);
            settingsMock.Setup(m => m.GetAccountKey(LetsEncryptV2)).ReturnsAsync(GetKeyV2());

            var orderMock = new Mock <IOrderContext>(MockBehavior.Strict);

            orderMock.SetupGet(m => m.Location).Returns(orderLoc);
            orderMock.Setup(m => m.Resource()).ReturnsAsync(order);

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

            ctxMock.Setup(m => m.GetDirectory()).ReturnsAsync(MockDirectoryV2);
            ctxMock.Setup(m => m.Order(orderLoc)).Returns(orderMock.Object);

            var fileMock = new Mock <IFileUtil>(MockBehavior.Strict);

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

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

            await command.InvokeAsync($"show {orderLoc}", console.Object);

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

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

            ctxMock.Verify(m => m.Order(orderLoc), Times.Once);
        }
Пример #2
0
        private static ArgumentSyntax DefineCommand(string args)
        {
            var cmd = new OrderShowCommand(
                NoopSettings(), (u, k) => new Mock <IAcmeContext>().Object, new FileUtil());

            Assert.Equal(CommandGroup.Order.Command, cmd.Group.Command);
            return(ArgumentSyntax.Parse(args.Split(' '), syntax =>
            {
                syntax.HandleErrors = false;
                syntax.DefineCommand("noop");
                cmd.Define(syntax);
            }));
        }
Пример #3
0
        public async Task CanProcessCommand()
        {
            var orderLoc = new Uri("http://acme.com/o/1");
            var order    = new Order
            {
                Identifiers = new[] {
                    new Identifier {
                        Value = "*.a.com"
                    },
                    new Identifier {
                        Value = "*.b.com"
                    },
                }
            };

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

            settingsMock.Setup(m => m.GetDefaultServer()).ReturnsAsync(LetsEncryptV2);
            settingsMock.Setup(m => m.GetAccountKey(LetsEncryptV2)).ReturnsAsync(GetKeyV2());

            var orderMock = new Mock <IOrderContext>(MockBehavior.Strict);

            orderMock.SetupGet(m => m.Location).Returns(orderLoc);
            orderMock.Setup(m => m.Resource()).ReturnsAsync(order);

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

            ctxMock.Setup(m => m.GetDirectory()).ReturnsAsync(MockDirectoryV2);
            ctxMock.Setup(m => m.Order(orderLoc)).Returns(orderMock.Object);

            var fileMock = new Mock <IFileUtil>(MockBehavior.Strict);

            var cmd = new OrderShowCommand(
                settingsMock.Object, (u, k) => ctxMock.Object, fileMock.Object);

            var syntax = DefineCommand($"show {orderLoc}");
            var ret    = await cmd.Execute(syntax);

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

            ctxMock.Verify(m => m.Order(orderLoc), Times.Once);
        }