Beispiel #1
0
        public async Task CallsRepoInit()
        {
            var mock = new Mock <IRepo>();
            var cli  = new Cli(mock.Object);

            bool ok = await cli.InitAsync();

            mock.Verify(mock => mock.InitAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
Beispiel #2
0
        public async Task ReturnsFalse_WhenRepoReturnsFalse()
        {
            var mock = new Mock <IRepo>();

            mock.Setup(m => m.InitAsync(It.IsAny <CancellationToken>())).ReturnsAsync(true);
            var cli = new Cli(mock.Object);

            bool ok = await cli.InitAsync();

            ok.Should().BeTrue($"{nameof(IRepo.InitAsync)} returned true");
        }
Beispiel #3
0
        static async Task Main(string[] args)
        {
            ICli cli = new Cli(new FileRepo(new ObjectFactory(), new AutoCrlfFilter()));
            var  app = new CommandLineApplication
            {
                Name        = "dullgit",
                Description = "A dull implementation of Git in C#"
            };

            app.HelpOption();

            app.OnExecute(() =>
            {
                Console.WriteLine("Specify a command");
                app.ShowHelp();
                return(1);
            });

            app.Command("init", config =>
            {
                config.Description = "Initialize a repository";
                config.OnExecuteAsync(async ct => await cli
                                      .InitAsync(ct)
                                      .ConfigureAwait(false) ? 0 : 1);
            });

            app.Command("hash-object", config =>
            {
                config.Description   = "Compute a hash";
                CommandArgument path = config.Argument("path", "File to hash").IsRequired();
                config.OnExecuteAsync(async ct => await cli
                                      .HashAsync(path.Value)
                                      .ConfigureAwait(false) ? 0 : 1);
            });

            app.Command("cat-file", config =>
            {
                config.Description   = "Get object contents";
                CommandArgument path = config.Argument("hash", "Object hash").IsRequired();
                config.OnExecuteAsync(async ct => await cli
                                      .CatAsync(path.Value)
                                      .ConfigureAwait(false) ? 0 : 1);
            });

            await app
            .ExecuteAsync(args)
            .ConfigureAwait(false);
        }