public async Task CreateNewAlreadyExist()
        {
            var gitHubClient       = Substitute.For <IGitHubClient>();
            var repositoriesClient = Substitute.For <IRepositoriesClient>();

            gitHubClient.Repository.Returns(repositoriesClient);

            var userClient = Substitute.For <IUsersClient>();

            userClient.Current().Returns(EmptyUser());

            gitHubClient.User.Returns(userClient);

            repositoriesClient.Get("login", "arepo").Returns(new Repository(0));
            repositoriesClient.Create(Arg.Is <NewRepository>(n => n.Name == "arepo"))
            .Throws(new RepositoryExistsException("arepo", new ApiValidationException()));

            var consoleService = Substitute.For <IConsoleService>();
            var handler        = new RemoteGithubCommandHandlerAsync(gitHubClient, consoleService);

            consoleService.AskForConfirmation().Returns(true);

            consoleService.ReadInputNumber(min: 1, max: 3).Returns(Option.Some(1));

            var repository = await handler.HandleAsync(new RemoteGithubCommand("arepo"));

            consoleService.Received(1).AskForConfirmation();
        }
        public async Task ChoiceExit()
        {
            var gitHubClient   = Substitute.For <IGitHubClient>();
            var consoleService = Substitute.For <IConsoleService>();
            var handler        = new RemoteGithubCommandHandlerAsync(gitHubClient, consoleService);

            consoleService.ReadInputNumber(min: 1, max: 3).Returns(Option.None <int>());

            var repository = await handler.HandleAsync(new RemoteGithubCommand("arepo"));

            Assert.Null(repository.ValueOrDefault());
        }
        public async Task CreateNew()
        {
            var gitHubClient       = Substitute.For <IGitHubClient>();
            var repositoriesClient = Substitute.For <IRepositoriesClient>();

            gitHubClient.Repository.Returns(repositoriesClient);

            repositoriesClient.Create(Arg.Is <NewRepository>(n => n.Name == "arepo")).Returns(new Repository(1));

            var consoleService = Substitute.For <IConsoleService>();
            var handler        = new RemoteGithubCommandHandlerAsync(gitHubClient, consoleService);

            consoleService.ReadInputNumber(min: 1, max: 3).Returns(Option.Some(1));

            var repository = await handler.HandleAsync(new RemoteGithubCommand("arepo"));

            Assert.NotNull(repository.ValueOrDefault());
        }
        public async Task ChooseItLater()
        {
            var gitHubClient       = Substitute.For <IGitHubClient>();
            var repositoriesClient = Substitute.For <IRepositoriesClient>();

            gitHubClient.Repository.Returns(repositoriesClient);
            repositoriesClient.GetAllForCurrent().Returns(new List <Repository>()
            {
                new Repository(0),
                new Repository(1)
            });

            var consoleService = Substitute.For <IConsoleService>();

            consoleService.ReadLine().Returns("");
            consoleService.ReadInputNumber(min: 1, max: 3).Returns(Option.Some(3));

            var handler = new RemoteGithubCommandHandlerAsync(gitHubClient, consoleService);

            var repository = await handler.HandleAsync(new RemoteGithubCommand("arepo"));

            Assert.Null(repository.ValueOrDefault());
        }