Esempio n. 1
0
        public static void Locals_List_Succeeds(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                // Arrange
                var mockGlobalPackagesDirectory = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"global-packages"));
                var mockHttpCacheDirectory      = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"http-cache"));
                var mockTmpCacheDirectory       = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"temp"));

                DotnetCliUtil.CreateTestFiles(mockGlobalPackagesDirectory.FullName);
                DotnetCliUtil.CreateTestFiles(mockHttpCacheDirectory.FullName);
                DotnetCliUtil.CreateTestFiles(mockTmpCacheDirectory.FullName);

                // Act
                var result = CommandRunner.Run(
                    DotnetCli,
                    Directory.GetCurrentDirectory(),
                    $"{XplatDll} {args}",
                    waitForExit: true,
                    environmentVariables: new Dictionary <string, string>
                {
                    { "NUGET_PACKAGES", mockGlobalPackagesDirectory.FullName },
                    { "NUGET_HTTP_CACHE_PATH", mockHttpCacheDirectory.FullName },
                    { RuntimeEnvironmentHelper.IsWindows ? "TMP" : "TMPDIR", mockTmpCacheDirectory.FullName }
                });
                // Unix uses TMPDIR as environment variable as opposed to TMP on windows

                // Assert
                DotnetCliUtil.VerifyResultSuccess(result, string.Empty);
            }
        }
Esempio n. 2
0
        public static void Locals_Success_InvalidFlags_HelpMessage(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            // Arrange
            var expectedResult = string.Concat("Specify --help for a list of available options and commands.",
                                               Environment.NewLine, "error: Unrecognized option '", args.Split(null)[1], "'");

            // Act
            var result = CommandRunner.Run(
                DotnetCli,
                Directory.GetCurrentDirectory(),
                $"{XplatDll} {args}",
                waitForExit: true);

            // Assert
            DotnetCliUtil.VerifyResultFailure(result, expectedResult);
        }
Esempio n. 3
0
        public static void Locals_Success_InvalidResourceName_HelpMessage(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            // Arrange
            var expectedResult = string.Concat("error: An invalid local resource name was provided. " +
                                               "Please provide one of the following values: http-cache, temp, global-packages, all.");

            // Act
            var result = CommandRunner.Run(
                DotnetCli,
                Directory.GetCurrentDirectory(),
                $"{XplatDll} {args}",
                waitForExit: true);

            // Assert
            DotnetCliUtil.VerifyResultFailure(result, expectedResult);
        }
Esempio n. 4
0
        public static void Trust_List_Empty_Succeeds(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                // Arrange
                var mockPackagesDirectory = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"packages"));

                // Act
                CommandRunnerResult result = CommandRunner.Run(
                    DotnetCli,
                    mockPackagesDirectory.FullName,
                    $"{XplatDll} {args}",
                    waitForExit: true);

                // Assert
                DotnetCliUtil.VerifyResultSuccess(result, "There are no trusted signers.");
            }
        }
Esempio n. 5
0
        public static void Locals_Success_BothFlags_HelpMessage(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            // Arrange
            var expectedResult = string.Concat("error: Both operations, --list and --clear, are not supported in the same command. Please specify only one operation.",
                                               Environment.NewLine,
                                               "error: usage: NuGet locals <all | http-cache | global-packages | temp> [--clear | -c | --list | -l]",
                                               Environment.NewLine,
                                               "error: For more information, visit http://docs.nuget.org/docs/reference/command-line-reference");

            // Act
            var result = CommandRunner.Run(
                DotnetCli,
                Directory.GetCurrentDirectory(),
                $"{XplatDll} {args}",
                waitForExit: true);

            // Assert
            DotnetCliUtil.VerifyResultFailure(result, expectedResult);
        }
        public static void Locals_Success_InvalidArguments_HelpMessage(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            // Arrange
            var expectedResult = string.Concat("error: No Cache Type was specified.",
                                               Environment.NewLine,
                                               "error: usage: NuGet locals <all | http-cache | global-packages | temp | plugins-cache> [--clear | -c | --list | -l]",
                                               Environment.NewLine,
                                               "error: For more information, visit https://docs.nuget.org/docs/reference/command-line-reference");

            // Act
            var result = CommandRunner.Run(
                DotnetCli,
                Directory.GetCurrentDirectory(),
                $"{XplatDll} {args}",
                waitForExit: true);

            // Assert
            DotnetCliUtil.VerifyResultFailure(result, expectedResult);
        }
Esempio n. 7
0
        public static void Locals_Clear_Succeeds(string args)
        {
            Assert.NotNull(DotnetCli);
            Assert.NotNull(XplatDll);

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                // Arrange
                var mockGlobalPackagesDirectory = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"global-packages"));
                var mockHttpCacheDirectory      = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"http-cache"));
                var mockTmpDirectory            = Directory.CreateDirectory(Path.Combine(mockBaseDirectory.Path, @"temp"));
                var mockTmpCacheDirectory       = Directory.CreateDirectory(Path.Combine(mockTmpDirectory.FullName, @"NuGetScratch"));

                DotnetCliUtil.CreateTestFiles(mockGlobalPackagesDirectory.FullName);
                DotnetCliUtil.CreateTestFiles(mockHttpCacheDirectory.FullName);
                DotnetCliUtil.CreateTestFiles(mockTmpCacheDirectory.FullName);

                var cacheType = args.Split(null)[1].StartsWith("-") ? args.Split(null)[2] : args.Split(null)[1];

                // Act
                var result = CommandRunner.Run(
                    DotnetCli,
                    Directory.GetCurrentDirectory(),
                    $"{XplatDll} {args}",
                    waitForExit: true,
                    environmentVariables: new Dictionary <string, string>
                {
                    { "NUGET_PACKAGES", mockGlobalPackagesDirectory.FullName },
                    { "NUGET_HTTP_CACHE_PATH", mockHttpCacheDirectory.FullName },
                    { RuntimeEnvironmentHelper.IsWindows ? "TMP" : "TMPDIR", mockTmpDirectory.FullName }
                });
                // Unix uses TMPDIR as environment variable as opposed to TMP on windows

                // Assert
                if (cacheType == "all")
                {
                    DotnetCliUtil.VerifyClearSuccess(mockGlobalPackagesDirectory.FullName);
                    DotnetCliUtil.VerifyClearSuccess(mockHttpCacheDirectory.FullName);
                    DotnetCliUtil.VerifyClearSuccess(mockTmpCacheDirectory.FullName);

                    // Assert clear message
                    DotnetCliUtil.VerifyResultSuccess(result, "Clearing NuGet global packages cache:");
                    DotnetCliUtil.VerifyResultSuccess(result, "Clearing NuGet HTTP cache:");
                    DotnetCliUtil.VerifyResultSuccess(result, "Clearing NuGet Temp cache:");
                    DotnetCliUtil.VerifyResultSuccess(result, "Local resources cleared.");
                }
                else if (cacheType == "global-packages")
                {
                    // Global packages cache should be cleared
                    DotnetCliUtil.VerifyClearSuccess(mockGlobalPackagesDirectory.FullName);

                    // Http cache and Temp cahce should be untouched
                    DotnetCliUtil.VerifyNoClear(mockHttpCacheDirectory.FullName);
                    DotnetCliUtil.VerifyNoClear(mockTmpCacheDirectory.FullName);

                    // Assert clear message
                    DotnetCliUtil.VerifyResultSuccess(result, "Clearing NuGet global packages cache:");
                    DotnetCliUtil.VerifyResultSuccess(result, "Local resources cleared.");
                }
                else if (cacheType == "http-cache")
                {
                    // Http cache should be cleared
                    DotnetCliUtil.VerifyClearSuccess(mockHttpCacheDirectory.FullName);

                    // Global packages cache and temp cache should be untouched
                    DotnetCliUtil.VerifyNoClear(mockGlobalPackagesDirectory.FullName);
                    DotnetCliUtil.VerifyNoClear(mockTmpCacheDirectory.FullName);

                    // Assert clear message
                    DotnetCliUtil.VerifyResultSuccess(result, "Clearing NuGet HTTP cache:");
                    DotnetCliUtil.VerifyResultSuccess(result, "Local resources cleared.");
                }
                else if (cacheType == "temp")
                {
                    // Temp cache should be cleared
                    DotnetCliUtil.VerifyClearSuccess(mockTmpCacheDirectory.FullName);

                    // Global packages cache and Http cache should be un touched
                    DotnetCliUtil.VerifyNoClear(mockGlobalPackagesDirectory.FullName);
                    DotnetCliUtil.VerifyNoClear(mockHttpCacheDirectory.FullName);

                    // Assert clear message
                    DotnetCliUtil.VerifyResultSuccess(result, "Clearing NuGet Temp cache:");
                    DotnetCliUtil.VerifyResultSuccess(result, "Local resources cleared.");
                }
            }
        }