Exemplo n.º 1
0
        public async Task <SettingsContainer> CaptureSettings(FileSettings settingsIn,
                                                              bool addLabels = false)
        {
            var logger       = Substitute.For <IConfigureLogLevel>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            SettingsContainer settingsOut = null;
            var engine = Substitute.For <IGitHubEngine>();
            await engine.Run(Arg.Do <SettingsContainer>(x => settingsOut = x));


            fileSettings.Get().Returns(settingsIn);

            var command = new RepositoryCommand(engine, logger, fileSettings);

            command.GitHubToken         = "testToken";
            command.GitHubRepositoryUri = "http://github.com/test/test";

            if (addLabels)
            {
                command.Label = new[] { "runLabel1", "runLabel2" };
            }

            await command.OnExecute();

            return(settingsOut);
        }
Exemplo n.º 2
0
        public async Task ShouldInitialiseCollaborationFactory()
        {
            var engine       = Substitute.For <ICollaborationEngine>();
            var logger       = Substitute.For <IConfigureLogger>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            fileSettings.GetSettings().Returns(FileSettings.Empty());

            var settingReader   = new GitHubSettingsReader();
            var settingsReaders = new List <ISettingsReader> {
                settingReader
            };
            var collaborationFactory = Substitute.For <ICollaborationFactory>();

            collaborationFactory.Settings.Returns(new CollaborationPlatformSettings());

            var command = new RepositoryCommand(engine, logger, fileSettings, collaborationFactory, settingsReaders)
            {
                PersonalAccessToken = "abc",
                RepositoryUri       = "http://github.com/abc/abc",
                ForkMode            = ForkMode.PreferSingleRepository
            };

            await command.OnExecute();

            collaborationFactory
            .Received(1)
            .Initialise(
                Arg.Is(new Uri("https://api.github.com")),
                Arg.Is("abc"),
                Arg.Is <ForkMode?>(ForkMode.PreferSingleRepository),
                Arg.Is((Platform?)null));
        }
Exemplo n.º 3
0
        public async Task ShouldCallEngineAndSucceedWithRequiredGithubParams()
        {
            var engine       = Substitute.For <ICollaborationEngine>();
            var logger       = Substitute.For <IConfigureLogger>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            fileSettings.GetSettings().Returns(FileSettings.Empty());

            var settingReader   = new GitHubSettingsReader();
            var settingsReaders = new List <ISettingsReader> {
                settingReader
            };
            var collaborationFactory = GetCollaborationFactory(settingsReaders);

            var command = new RepositoryCommand(engine, logger, fileSettings, collaborationFactory, settingsReaders)
            {
                PersonalAccessToken = "abc",
                RepositoryUri       = "http://github.com/abc/abc"
            };

            var status = await command.OnExecute();

            Assert.That(status, Is.EqualTo(0));
            await engine
            .Received(1)
            .Run(Arg.Any <SettingsContainer>());
        }
Exemplo n.º 4
0
        public async Task ShouldCallEngineAndNotSucceedWithoutParams()
        {
            var engine       = Substitute.For <IGitHubEngine>();
            var logger       = Substitute.For <IConfigureLogLevel>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            fileSettings.Get().Returns(FileSettings.Empty());

            var command = new RepositoryCommand(engine, logger, fileSettings);

            var status = await command.OnExecute();

            Assert.That(status, Is.EqualTo(-1));
            await engine
            .DidNotReceive()
            .Run(Arg.Any <SettingsContainer>());
        }
Exemplo n.º 5
0
        public static async Task <(SettingsContainer settingsContainer, CollaborationPlatformSettings platformSettings)> CaptureSettings(
            FileSettings settingsIn,
            bool addLabels          = false,
            int?maxPackageUpdates   = null,
            int?maxOpenPullRequests = null
            )
        {
            var logger       = Substitute.For <IConfigureLogger>();
            var fileSettings = Substitute.For <IFileSettingsCache>();
            var environmentVariablesProvider = Substitute.For <IEnvironmentVariablesProvider>();

            fileSettings.GetSettings().Returns(settingsIn);

            var settingReader   = new GitHubSettingsReader(new MockedGitDiscoveryDriver(), environmentVariablesProvider);
            var settingsReaders = new List <ISettingsReader> {
                settingReader
            };
            var collaborationFactory = GetCollaborationFactory(environmentVariablesProvider, settingsReaders);

            SettingsContainer settingsOut = null;
            var engine = Substitute.For <ICollaborationEngine>();
            await engine.Run(Arg.Do <SettingsContainer>(x => settingsOut = x));

            var command = new RepositoryCommand(engine, logger, fileSettings, collaborationFactory, settingsReaders);

            command.PersonalAccessToken = "testToken";
            command.RepositoryUri       = "http://github.com/test/test";

            if (addLabels)
            {
                command.Label = new List <string> {
                    "runLabel1", "runLabel2"
                };
            }

            command.MaxPackageUpdates   = maxPackageUpdates;
            command.MaxOpenPullRequests = maxOpenPullRequests;

            await command.OnExecute();

            return(settingsOut, collaborationFactory.Settings);
        }
Exemplo n.º 6
0
        public async Task ShouldCallEngineAndSucceedWithRequiredGithubParams()
        {
            var engine       = Substitute.For <IGitHubEngine>();
            var logger       = Substitute.For <IConfigureLogLevel>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            fileSettings.Get().Returns(FileSettings.Empty());

            var command = new RepositoryCommand(engine, logger, fileSettings);

            command.GitHubToken         = "abc";
            command.GitHubRepositoryUri = "http://github.com/abc/abc";

            var status = await command.OnExecute();

            Assert.That(status, Is.EqualTo(0));
            await engine
            .Received(1)
            .Run(Arg.Any <SettingsContainer>());
        }
Exemplo n.º 7
0
        public async Task ShouldCallEngineAndNotSucceedWithoutParams()
        {
            var engine       = Substitute.For <ICollaborationEngine>();
            var logger       = Substitute.For <IConfigureLogger>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            fileSettings.GetSettings().Returns(FileSettings.Empty());

            var settingReader   = new GitHubSettingsReader();
            var settingsReaders = new List <ISettingsReader> {
                settingReader
            };
            var collaborationFactory = GetCollaborationFactory(settingsReaders);

            var command = new RepositoryCommand(engine, logger, fileSettings, collaborationFactory, settingsReaders);

            var status = await command.OnExecute();

            Assert.That(status, Is.EqualTo(-1));
            await engine
            .DidNotReceive()
            .Run(Arg.Any <SettingsContainer>());
        }
Exemplo n.º 8
0
        public async Task ShouldInitialisePlatformFromFile()
        {
            var engine       = Substitute.For <ICollaborationEngine>();
            var logger       = Substitute.For <IConfigureLogger>();
            var fileSettings = Substitute.For <IFileSettingsCache>();

            fileSettings.GetSettings().Returns(
                new FileSettings
            {
                Platform = Platform.BitbucketLocal
            });

            var settingReader   = new GitHubSettingsReader(new MockedGitDiscoveryDriver(), _environmentVariablesProvider);
            var settingsReaders = new List <ISettingsReader> {
                settingReader
            };
            var collaborationFactory = Substitute.For <ICollaborationFactory>();

            collaborationFactory.Settings.Returns(new CollaborationPlatformSettings());

            var command = new RepositoryCommand(engine, logger, fileSettings, collaborationFactory, settingsReaders)
            {
                PersonalAccessToken = "abc",
                RepositoryUri       = "http://github.com/abc/abc",
                ForkMode            = null
            };

            await command.OnExecute();

            await collaborationFactory
            .Received(1)
            .Initialise(
                Arg.Is(new Uri("https://api.github.com")),
                Arg.Is("abc"),
                Arg.Is((ForkMode?)null),
                Arg.Is((Platform?)Platform.BitbucketLocal));
        }