public async Task When_repositories_exist_and_they_are_not_mirrored_Then_should_mirror()
        {
            var automation = new MirrorAutomationLogic(new Mock <ILogger>().Object);
            var scanner    = new Mock <IRepositorySource>();

            scanner.Setup(x => x.GetRepositoriesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new IRepository[]
            {
                new Repository {
                    Name = "Repo1"
                },
                new Repository {
                    Name = "Repo2"
                }
            }));
            var mirror = new Mock <IMirrorService>();

            mirror.Setup(x => x.GetExistingMirrorsAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new Mirror[0]));
            var targets = new[]
            {
                new Mock <IRepositoryTarget>().Object
            };
            await automation.ProcessAsync(scanner.Object, mirror.Object, targets, CancellationToken.None);

            mirror.Verify(x => x.SetupMirrorAsync(It.Is <IRepository>(r => r.Name == "Repo1"), It.IsAny <CancellationToken>()), Times.Once);
            mirror.Verify(x => x.SetupMirrorAsync(It.Is <IRepository>(r => r.Name == "Repo2"), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task When_no_repositories_exist_should_not_mirror_anything()
        {
            var automation = new MirrorAutomationLogic(new Mock <ILogger>().Object);
            var scanner    = new Mock <IRepositorySource>();

            scanner.Setup(x => x.GetRepositoriesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new IRepository[0]));
            var mirror = new Mock <IMirrorService>();

            mirror.Setup(x => x.GetExistingMirrorsAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new Mirror[0]));
            var targets = new[]
            {
                new Mock <IRepositoryTarget>().Object
            };
            await automation.ProcessAsync(scanner.Object, mirror.Object, targets, CancellationToken.None);

            mirror.Verify(x => x.SetupMirrorAsync(It.IsAny <IRepository>(), It.IsAny <CancellationToken>()), Times.Never);
        }
Ejemplo n.º 3
0
        public static async Task ScanRepositoriesAsync(
            [TimerTrigger(Schedule.Every5Minutes, RunOnStartup = true)] TimerInfo timer,
            ILogger log,
            CancellationToken cancellationToken)
        {
            var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage") ?? throw new ArgumentNullException("Storage connection string not set");
            var storageProvider  = new AzureBlobStorageProvider(connectionString, "configuration");

            var configurations = await LoadConfigFilesAsync(storageProvider, cancellationToken);

            var configParser = new ConfigurationParser(log);

            foreach (var cfg in configurations)
            {
                var automation    = new MirrorAutomationLogic(log);
                var source        = configParser.GetRepositorySource(cfg.Source);
                var mirrorService = configParser.GetMirrorService(cfg.MirrorViaConfig, source);
                var targets       = configParser.GetRepositoryTargets(cfg.TargetConfig);
                log.LogInformation($"Processing source {source.SourceId} (to be replicated to {Join(", ", " and ", targets.Select(t => t.TargetId))})");
                await automation.ProcessAsync(source, mirrorService, targets, cancellationToken);
            }
        }