예제 #1
0
        public void GivenTheHelpWithACommandArgumentShowTheCorrespondingHelp(string command)
        {
            var writer      = new MemoryConsoleWriter();
            var application = CompositionRootWithMyWriter(writer);

            // Run application without a command
            Assert.True(application.Execute(new[] { "help", command }));

            Assert.NotEmpty(writer.Lines[0]);
        }
예제 #2
0
        public void GivenNoCommandThenGiveHint()
        {
            var writer = new MemoryConsoleWriter();

            var application = CompositionRootWithMyWriter(writer);

            // Run application without a command
            application.Execute(new string[] { });

            // Test the output
            Assert.Collection(writer.Lines, line => Assert.Equal("Maybe run 'program help'", line));
        }
예제 #3
0
        public void GivenTheHelpCommandWithNoArgumentReturnTheDefaultHelp()
        {
            var writer = new MemoryConsoleWriter();

            var application = CompositionRootWithMyWriter(writer);

            // Run application without a command
            application.Execute(new[] { "help" });

            // Test the output
            Assert.Equal("program <command> [<arguments>] [<options>]:", writer.Lines[0]);
        }
예제 #4
0
        public void GivenAListOfTagsToTheCreateCommandThenTheListCommandListsThemCorrectly()
        {
            var tag = MockTagStore.Create();

            var      tagParser = new TagParser((name, parent) => new Tag(tag, name, parent));
            ICommand addTag    = new AddTagCommand(tagParser);

            List <string> taxPeriods = new List <string> {
                ":tax_period:2016", ":tax_period:2017", ":tax_period:2018", ":tax_period:2019"
            };
            List <string> movieRating = new List <string> {
                ":movie:bad", ":movie:average", ":movie:good", ":movie:great"
            };

            var mockOptions = new Mock <IOptionParser>();

            addTag.Execute(taxPeriods, mockOptions.Object);
            addTag.Execute(movieRating, mockOptions.Object);

            Assert.Collection(tag.Tags,
                              item => Assert.Equal("2016", item.Name),
                              item => Assert.Equal("tax_period", item.Parent?.Name),
                              item => Assert.Equal(taxPeriods[2], item.FullName),
                              item => Assert.Equal(taxPeriods[3], item.FullName),
                              item => Assert.Equal("bad", item.Name),
                              item => Assert.Equal("movie", item.Parent?.Name),
                              item => Assert.Equal(movieRating[2], item.FullName),
                              item => Assert.Equal(movieRating[3], item.FullName)
                              );

            var      console  = new MemoryConsoleWriter();
            ICommand listTags = new ListTagsCommand(tag, console);

            listTags.Execute(Enumerable.Empty <string>(), mockOptions.Object);

            Assert.Collection(console.Lines,
                              line => Assert.Equal("Used tags: ", line),
                              line => Assert.Equal("* :tax_period:2016 (0) ", line),
                              line => Assert.Equal("* :tax_period:2017 (0) ", line),
                              line => Assert.Equal("* :tax_period:2018 (0) ", line),
                              line => Assert.Equal("* :tax_period:2019 (0) ", line),
                              line => Assert.Equal("* :movie:bad       (0) ", line),
                              line => Assert.Equal("* :movie:average   (0) ", line),
                              line => Assert.Equal("* :movie:good      (0) ", line),
                              line => Assert.Equal("* :movie:great     (0) ", line)
                              );
        }
예제 #5
0
        private static ArgumentParser CompositionRootWithMyWriter(MemoryConsoleWriter writer)
        {
            // CLI Application CompositionRoot
            var compositionRoot = new CompositionRoot()
                                  .Register();

            // We override the Console Output to the Memory Writer
            compositionRoot.Builder.Register(context => writer).As <IConsoleWriter>();

            OverrideDatabase(compositionRoot);
            OverrideConsoleApplicationInformationProvider(compositionRoot);

            // Return The application Object
            return(compositionRoot
                   .Build()
                   .Resolve <ArgumentParser>());
        }