Esempio n. 1
0
        public static async Task <IEnumerable <CachingValidations> > ExecuteAsync(ICachingTest test, ICachingCommand command, INuGetExe nuGetExe, CachingType caching, ServerType server)
        {
            using (var testFolder = TestDirectory.Create())
                using (var mockServer = new MockServer())
                {
                    var tc = new CachingTestContext(testFolder, mockServer, nuGetExe);

                    // Enable this flag to launch the debugger when the nuget.exe process starts. This also increases
                    // logging verbosity and command timeout.
                    //
                    // tc.Debug = true;

                    tc.NoCache        = caching.HasFlag(CachingType.NoCache);
                    tc.DirectDownload = caching.HasFlag(CachingType.DirectDownload);
                    tc.CurrentSource  = server == ServerType.V2 ? tc.V2Source : tc.V3Source;

                    tc.ClearHttpCache();
                    var validations = new List <CachingValidations>();
                    for (var i = 0; i < test.IterationCount; i++)
                    {
                        var args = await test.PrepareTestAsync(tc, command);

                        var result = tc.Execute(args);
                        validations.Add(test.Validate(tc, command, result));
                    }

                    return(validations);
                }
        }
Esempio n. 2
0
        private CommandRunnerResult Execute(CachingTestContext context, string args, bool debug)
        {
            _hasExecuted = true;

            var timeout = 60 * 1000 * 1;

            if (debug)
            {
                args    += " -Verbosity detailed --debug";
                timeout *= 60;
            }

            var environmentVariables = new Dictionary <string, string>
            {
                { "NUGET_PACKAGES", context.GlobalPackagesPath }
            };

            if (_supportsIsolatedHttpCache)
            {
                environmentVariables["NUGET_HTTP_CACHE_PATH"] = context.IsolatedHttpCachePath;
            }

            return(CommandRunner.Run(
                       _pathToExe,
                       context.WorkingPath,
                       args,
                       timeOutInMilliseconds: timeout,
                       waitForExit: true,
                       environmentVariables: environmentVariables));
        }
        public CachingValidations Validate(CachingTestContext context, ICachingCommand command, CommandRunnerResult result)
        {
            var validations = new CachingValidations();

            validations.Add(
                CachingValidationType.CommandSucceeded,
                result.Item1 == 0);


            validations.Add(CachingValidationType.RestoreNoOp, result.AllOutput.Contains("No further actions are required to complete the restore"));

            validations.Add(
                CachingValidationType.PackageInstalled,
                command.IsPackageInstalled(context, context.PackageIdentityA));

            var path = command.GetInstalledPackagePath(context, context.PackageIdentityA);

            validations.Add(
                CachingValidationType.PackageFromGlobalPackagesFolderUsed,
                path != null && context.IsPackageAVersionA(path));

            validations.Add(
                CachingValidationType.PackageFromSourceNotUsed,
                path == null || !context.IsPackageAVersionB(path));

            return(validations);
        }
Esempio n. 4
0
        public string PrepareArguments(CachingTestContext context, PackageIdentity identity)
        {
            context.WritePackagesConfig(identity);

            var args = $"install {context.PackagesConfigPath} -OutputDirectory {context.OutputPackagesPath}";

            return(context.FinishArguments(args));
        }
Esempio n. 5
0
        public Task <string> PrepareTestAsync(CachingTestContext context, ICachingCommand command)
        {
            // The package is available on the source.
            context.IsPackageBAvailable = true;

            var args = command.PrepareArguments(context, context.PackageIdentityB);

            return(Task.FromResult(args));
        }
        public string PrepareArguments(CachingTestContext context, PackageIdentity identity)
        {
            context.WriteProjectJson(identity);
            context.WriteProject();

            var args = $"restore {context.ProjectPath}";

            return(context.FinishArguments(args));
        }
        public async Task <string> PrepareTestAsync(CachingTestContext context, ICachingCommand command)
        {
            // The package is available in the global packages folder.
            await context.AddToGlobalPackagesFolderAsync(context.PackageIdentityB, context.PackageBPath);

            // The package is not available on the source.
            context.IsPackageBAvailable = false;

            return(command.PrepareArguments(context, context.PackageIdentityB));
        }
        public async Task <string> PrepareTestAsync(CachingTestContext context, ICachingCommand command)
        {
            // Add the first version of the package to the global packages folder.
            await context.AddToGlobalPackagesFolderAsync(context.PackageIdentityA, context.PackageAVersionAPath);

            // A different version of the same package is available on the source.
            context.CurrentPackageAPath = context.PackageAVersionBPath;
            context.IsPackageAAvailable = true;

            return(command.PrepareArguments(context, context.PackageIdentityA));
        }
        public Task <string> PrepareTestAsync(CachingTestContext context, ICachingCommand command)
        {
            // Populate the output packages path with a leftover .directdownload file.
            Directory.CreateDirectory(context.OutputPackagesPath);
            var path = Path.Combine(context.OutputPackagesPath, $"leftover.nugetdirectdownload");

            File.WriteAllText(path, string.Empty);

            var args = command.PrepareArguments(context, context.PackageIdentityA);

            return(Task.FromResult(args));
        }
        public Task <string> PrepareTestAsync(CachingTestContext context, ICachingCommand command)
        {
            // The second version of the package is available on the source.
            context.IsPackageAAvailable = true;
            context.CurrentPackageAPath = context.PackageAVersionBPath;

            // Add the first version of the package to the HTTP.
            context.AddPackageToHttpCache(context.PackageIdentityA, context.PackageAVersionAPath);

            var args = command.PrepareArguments(context, context.PackageIdentityA);

            return(Task.FromResult(args));
        }
Esempio n. 11
0
        public CachingValidations Validate(CachingTestContext context, ICachingCommand command, CommandRunnerResult result)
        {
            var validations = new CachingValidations();

            validations.Add(
                CachingValidationType.CommandSucceeded,
                result.ExitCode == 0);

            validations.Add(
                CachingValidationType.PackageInHttpCache,
                context.IsPackageInHttpCache(context.PackageIdentityB));

            return(validations);
        }
        public CachingValidations Validate(CachingTestContext context, ICachingCommand command, CommandRunnerResult result)
        {
            var validations = new CachingValidations();

            validations.Add(
                CachingValidationType.CommandSucceeded,
                result.Item1 == 0);

            validations.Add(
                CachingValidationType.DirectDownloadFilesDoNotExist,
                !Directory.EnumerateFiles(context.OutputPackagesPath, "*.nugetdirectdownload").Any());

            return(validations);
        }
Esempio n. 13
0
        public CachingValidations Validate(CachingTestContext context, ICachingCommand command, CommandRunnerResult result)
        {
            var validations = new CachingValidations();

            validations.Add(
                CachingValidationType.CommandSucceeded,
                result.Item1 == 0);

            validations.Add(
                CachingValidationType.PackageInGlobalPackagesFolder,
                context.IsPackageInGlobalPackagesFolder(context.PackageIdentityB));

            return(validations);
        }
Esempio n. 14
0
 public void ClearHttpCache(CachingTestContext context)
 {
     if (_supportsIsolatedHttpCache)
     {
         if (_hasExecuted)
         {
             Directory.Delete(context.IsolatedHttpCachePath, recursive: true);
         }
         else
         {
             // Do nothing, the HTTP cache is still clean.
         }
     }
     else
     {
         Execute(context, "locals http-cache -Clear", debug: false);
     }
 }
Esempio n. 15
0
        public string GetHttpCachePath(CachingTestContext context)
        {
            if (_supportsIsolatedHttpCache)
            {
                return(context.IsolatedHttpCachePath);
            }
            else
            {
                var result = Execute(context, "locals http-cache -list", debug: false);

                var stdout = result.Output.Trim();

                // Example:
                //   stdout = http-cache: C:\Users\jver\AppData\Local\NuGet\v3-cache
                //   path   = C:\Users\jver\AppData\Local\NuGet\v3-cache
                var path = stdout.Split(new[] { ':' }, 2)[1].Trim();

                return(path);
            }
        }
        public CachingValidations Validate(CachingTestContext context, ICachingCommand command, CommandRunnerResult result)
        {
            var validations = new CachingValidations();

            validations.Add(
                CachingValidationType.CommandSucceeded,
                result.Item1 == 0);

            validations.Add(
                CachingValidationType.PackageInstalled,
                command.IsPackageInstalled(context, context.PackageIdentityA));

            var path = command.GetInstalledPackagePath(context, context.PackageIdentityA);

            validations.Add(
                CachingValidationType.PackageFromHttpCacheUsed,
                path != null && context.IsPackageAVersionA(path));

            validations.Add(
                CachingValidationType.PackageFromSourceNotUsed,
                path == null || !context.IsPackageAVersionB(path));

            return(validations);
        }
Esempio n. 17
0
 public bool IsPackageInstalled(CachingTestContext context, PackageIdentity identity)
 {
     return(context.IsPackageInOutputDirectory(identity));
 }
Esempio n. 18
0
 public CommandRunnerResult Execute(CachingTestContext context, string args)
 {
     return(Execute(context, args, context.Debug));
 }
 public bool IsPackageInstalled(CachingTestContext context, PackageIdentity identity)
 {
     return(context.IsPackageInGlobalPackagesFolder(identity));
 }
 public string GetInstalledPackagePath(CachingTestContext context, PackageIdentity identity)
 {
     return(context.GetPackagePathInGlobalPackagesFolder(identity));
 }
Esempio n. 21
0
 public string GetInstalledPackagePath(CachingTestContext context, PackageIdentity identity)
 {
     return(context.GetPackagePathInOutputDirectory(identity));
 }
Esempio n. 22
0
        public string PrepareArguments(CachingTestContext context, PackageIdentity identity)
        {
            var args = $"install {identity.Id} -Version {identity.Version} -OutputDirectory {context.OutputPackagesPath}";

            return(context.FinishArguments(args));
        }