Пример #1
0
        private static async Task PublishAppAsync(string path, string outputPath)
        {
            var resolvedPath = Path.GetFullPath(path);

            Console.WriteLine($"Publishing {resolvedPath}");

            var process = new DotNetProcess();

            try
            {
                process.Start($"publish {resolvedPath} -r {GetRuntimeIdentifier()} -c Release -o {outputPath} --self-contained");
                await process.WaitForExitAsync().TimeoutAfter(Timeout);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while publishing app.", ex);
            }
            finally
            {
                var exitCode = process.HasExited ? (int?)process.ExitCode : null;

                process.Dispose();

                var output = process.GetOutput();
                Console.WriteLine("Publish output:");
                Console.WriteLine(output);

                if (exitCode != null && exitCode.Value != 0)
                {
                    throw new Exception($"Non-zero exit code returned: {exitCode}");
                }
            }
        }
        private void BuildProject()
        {
            Logger.LogInformation(string.Empty);
            Logger.LogInformation($"Building package {Package.PackageInfo.Name} [{Package.PackageInfo.Version}]");
            Logger.LogInformation(string.Empty);

            DotNetProcess.Build(_projectFilePath);
        }
        private void AddNugetDependencies()
        {
            EnsurePackageData();

            IList <string> messageNugetPackages;

            // If package is a meta package use dependencies
            // form package info (parsed package.xml)
            // else use real dependencies retrieved form
            // message files.
            if (Package.PackageInfo.IsMetaPackage)
            {
                messageNugetPackages = Package.Parser
                                       .PackageDependencies
                                       .Select(x => NameMapper.ResolveNugetPackageName(x))
                                       .Distinct()
                                       .ToList();
            }
            else
            {
                messageNugetPackages = Package.Parser
                                       .ExternalTypeDependencies
                                       .Select(x => NameMapper.ResolveNugetPackageName(x))
                                       .Distinct()
                                       .ToList();
            }

            if (!messageNugetPackages.Any())
            {
                return;
            }

            Logger.LogInformation($"Restoring package dependencies");

            foreach (var dependency in messageNugetPackages)
            {
                Logger.LogInformation($"  {dependency}");

                try
                {
                    DotNetProcess.AddPackage(_projectFilePath, dependency);
                }
                catch (ProcessFailedException e)
                {
                    Environment.ExitCode |= (int)ExitCodes.CouldNotAddDependency;
                    throw new DependencyNotFoundException(dependency,
                                                          $"Could not add dependency {dependency}.", e);
                }
            }
            Logger.LogInformation(string.Empty);
        }
Пример #4
0
        public async Task RunWebsiteAndCallWithClient_Success()
        {
            var projectDirectory = typeof(LinkerTests).Assembly
                                   .GetCustomAttributes <AssemblyMetadataAttribute>()
                                   .Single(a => a.Key == "ProjectDirectory")
                                   .Value;

            var tempPath = Path.GetTempPath();
            var linkerTestsClientPath  = Path.Combine(tempPath, "LinkerTestsClient");
            var linkerTestsWebsitePath = Path.Combine(tempPath, "LinkerTestsWebsite");

            EnsureDeleted(linkerTestsClientPath);
            EnsureDeleted(linkerTestsWebsitePath);

            try
            {
                using var websiteProcess = new WebsiteProcess();
                using var clientProcess  = new DotNetProcess();

                try
                {
                    var publishWebsiteTask = PublishAppAsync(projectDirectory + @"\..\..\testassets\LinkerTestsWebsite\LinkerTestsWebsite.csproj", linkerTestsWebsitePath);
                    var publishClientTask  = PublishAppAsync(projectDirectory + @"\..\..\testassets\LinkerTestsClient\LinkerTestsClient.csproj", linkerTestsClientPath);

                    await Task.WhenAll(publishWebsiteTask, publishClientTask).TimeoutAfter(Timeout);

                    websiteProcess.Start(Path.Combine(linkerTestsWebsitePath, "LinkerTestsWebsite.dll"));
                    await websiteProcess.WaitForReadyAsync().TimeoutAfter(Timeout);

                    clientProcess.Start(Path.Combine(linkerTestsClientPath, $"LinkerTestsClient.dll {websiteProcess.ServerPort}"));
                    await clientProcess.WaitForExitAsync().TimeoutAfter(Timeout);

                    Assert.AreEqual(0, clientProcess.ExitCode);
                }
                finally
                {
                    Console.WriteLine("Website output:");
                    Console.WriteLine(websiteProcess.GetOutput());
                    Console.WriteLine("Client output:");
                    Console.WriteLine(clientProcess.GetOutput());
                }
            }
            finally
            {
                EnsureDeleted(linkerTestsClientPath);
                EnsureDeleted(linkerTestsWebsitePath);
            }
        }