Пример #1
0
        private async Task <IReadOnlyCollection <string> > RunSetupAsync()
        {
            string rootDirectory = VcsTestPathHelper.GetRootDirectory();

            string appRootDirectory = Path.Combine(rootDirectory, "src", "Milou.Deployer.Web.IisHost");

            string[] args =
            {
                $"{ConfigurationConstants.ContentBasePath}={appRootDirectory}",
            };

            _cancellationTokenSource.Token.Register(() => Console.WriteLine("App cancellation token triggered"));

            Builder = new StringBuilder();
            var writer = new StringWriter(Builder);

            void AddTestLogging(LoggerConfiguration loggerConfiguration)
            {
                loggerConfiguration
                .WriteTo.TextWriter(writer)
                .WriteTo.Debug();
            }

            App = await App.CreateAsync(_cancellationTokenSource, AddTestLogging, args);

            App.Logger.Information("Restart time is set to {RestartIntervalInSeconds} seconds",
                                   CancellationTimeoutInSeconds);

            return(args);
        }
        protected override async Task BeforeInitialize(CancellationToken cancellationToken)
        {
            var portPoolRange = new PortPoolRange(5200, 5299);

            TestSiteHttpPort = TcpHelper.GetAvailablePort(portPoolRange);

            TestConfiguration = await new TestPathHelper().CreateTestConfigurationAsync(cancellationToken);

            Environment.SetEnvironmentVariable("TestDeploymentTargetPath", TestConfiguration.SiteAppRoot.FullName);
            Environment.SetEnvironmentVariable("TestDeploymentUri", $"http://localhost:{TestSiteHttpPort.Port}");

            string deployerDir = Path.Combine(VcsTestPathHelper.GetRootDirectory(), "tools", "milou.deployer");

            const string milouDeployerWebTestsIntegration = "Milou.Deployer.Web.Tests.Integration";

            ImmutableArray <KeyValue> keys = new List <KeyValue>
            {
                new KeyValue(Deployer.Core.Configuration.ConfigurationKeys.NuGetSource, milouDeployerWebTestsIntegration, null),
                new KeyValue(ConfigurationConstants.NugetConfigFile, TestConfiguration.NugetConfigFile.FullName, null),
                new KeyValue(Deployer.Core.Configuration.ConfigurationKeys.NuGetConfig, TestConfiguration.NugetConfigFile.FullName, null),
                new KeyValue(Deployer.Core.Configuration.ConfigurationKeys.LogLevel, "Verbose", null),
            }.ToImmutableArray();

            var    jsonConfigurationSerializer  = new JsonConfigurationSerializer();
            string serializedConfigurationItems = jsonConfigurationSerializer.Serialize(new ConfigurationItems("1.0", keys));

            string settingsFile = Path.Combine(deployerDir, $"{Environment.MachineName}.settings.json");

            FilesToClean.Add(new FileInfo(settingsFile));

            await File.WriteAllTextAsync(settingsFile, serializedConfigurationItems, Encoding.UTF8, cancellationToken);

            var integrationTestProjectDirectory = new DirectoryInfo(Path.Combine(VcsTestPathHelper.GetRootDirectory(),
                                                                                 "src",
                                                                                 milouDeployerWebTestsIntegration));

            FileInfo[] nugetPackages = integrationTestProjectDirectory.GetFiles("*.nupkg");

            if (nugetPackages.Length == 0)
            {
                throw new DeployerAppException($"Could not find nuget test packages located in {integrationTestProjectDirectory.FullName}");
            }

            foreach (FileInfo nugetPackage in nugetPackages)
            {
                nugetPackage.CopyTo(Path.Combine(TestConfiguration.NugetPackageDirectory.FullName, nugetPackage.Name));
            }

            Environment.SetEnvironmentVariable(Deployer.Core.Configuration.ConfigurationKeys.KeyValueConfigurationFile, settingsFile);

            Environment.SetEnvironmentVariable(ConfigurationConstants.NugetConfigFile,
                                               TestConfiguration.NugetConfigFile.FullName);

            Environment.SetEnvironmentVariable(ConfigurationConstants.NuGetPackageSourceName,
                                               milouDeployerWebTestsIntegration);

            Environment.SetEnvironmentVariable(
                $"{ConfigurationConstants.AutoDeployConfiguration}:default:StartupDelayInSeconds",
                "0");

            Environment.SetEnvironmentVariable(
                $"{ConfigurationConstants.AutoDeployConfiguration}:default:afterDeployDelayInSeconds",
                "1");

            Environment.SetEnvironmentVariable(
                $"{ConfigurationConstants.AutoDeployConfiguration}:default:MetadataTimeoutInSeconds",
                "10");

            Environment.SetEnvironmentVariable(
                $"{ConfigurationConstants.AutoDeployConfiguration}:default:enabled",
                "true");

            DirectoriesToClean.Add(TestConfiguration.BaseDirectory);
        }