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

            const string hash = "8bd6648ed130ac9ece0f89cd9a8fbbfd2608427a";

            bool ok = await cli.CatAsync(hash);

            mock.Verify(
                mock => mock.GetObjectAsync(
                    It.Is <string>(s => s == hash),
                    It.IsAny <ObjectType>()),
                Times.Once);
        }
Beispiel #2
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);
        }