Ejemplo n.º 1
0
        private void VerifyCommand(Action <string, Mock <IListPackageCommandRunner>, CommandLineApplication, Func <LogLevel> > verify)
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var projectPath = Path.Combine(testDirectory, "project.csproj");
                File.WriteAllText(projectPath, string.Empty);

                var logLevel          = LogLevel.Information;
                var logger            = new TestCommandOutputLogger();
                var testApp           = new CommandLineApplication();
                var mockCommandRunner = new Mock <IListPackageCommandRunner>();
                mockCommandRunner
                .Setup(m => m.ExecuteCommandAsync(It.IsAny <ListPackageArgs>()))
                .Returns(Task.CompletedTask);

                testApp.Name = "dotnet nuget_test";
                ListPackageCommand.Register(testApp,
                                            () => logger,
                                            ll => logLevel = ll,
                                            () => mockCommandRunner.Object);

                // Act & Assert
                try
                {
                    verify(projectPath, mockCommandRunner, testApp, () => logLevel);
                }
                finally
                {
                    XPlatTestUtils.DisposeTemporaryFile(projectPath);
                }
            }
        }
        public void AddPkg_RemoveParsing(string packageOption, string package,
                                         string projectOption, string project)
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var projectPath = Path.Combine(testDirectory, project);
                File.Create(projectPath).Dispose();
                var argList = new List <string>()
                {
                    "remove",
                    packageOption,
                    package,
                    projectOption,
                    projectPath
                };

                var logger            = new TestCommandOutputLogger();
                var testApp           = new CommandLineApplication();
                var mockCommandRunner = new Mock <IPackageReferenceCommandRunner>();
                mockCommandRunner
                .Setup(m => m.ExecuteCommand(It.IsAny <PackageReferenceArgs>(), It.IsAny <MSBuildAPIUtility>()))
                .ReturnsAsync(0);

                testApp.Name = "dotnet nuget_test";
                RemovePackageReferenceCommand.Register(testApp,
                                                       () => logger,
                                                       () => mockCommandRunner.Object);

                // Act
                var result = testApp.Execute(argList.ToArray());

                XPlatTestUtils.DisposeTemporaryFile(projectPath);

                // Assert
                mockCommandRunner.Verify(m => m.ExecuteCommand(It.Is <PackageReferenceArgs>(p =>
                                                                                            p.PackageId == package &&
                                                                                            p.ProjectPath == projectPath),
                                                               It.IsAny <MSBuildAPIUtility>()));

                Assert.Equal(0, result);
            }
        }
Ejemplo n.º 3
0
        public void BasicListPackageParsing_Interactive()
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var projectPath = Path.Combine(testDirectory, "project.csproj");
                File.WriteAllText(projectPath, string.Empty);

                var argList = new List <string>()
                {
                    "list",
                    "--interactive",
                    projectPath
                };

                var logger            = new TestCommandOutputLogger();
                var testApp           = new CommandLineApplication();
                var mockCommandRunner = new Mock <IListPackageCommandRunner>();
                mockCommandRunner
                .Setup(m => m.ExecuteCommandAsync(It.IsAny <ListPackageArgs>()))
                .Returns(Task.CompletedTask);

                testApp.Name = "dotnet nuget_test";
                ListPackageCommand.Register(testApp,
                                            () => logger,
                                            () => mockCommandRunner.Object);

                // Act
                var result = testApp.Execute(argList.ToArray());

                XPlatTestUtils.DisposeTemporaryFile(projectPath);

                // Assert
                mockCommandRunner.Verify();
                Assert.NotNull(HttpHandlerResourceV3.CredentialService);
                Assert.Equal(0, result);
            }
        }
Ejemplo n.º 4
0
        public void AddPkg_ArgParsing(string packageOption, string package, string versionOption, string version, string dgFileOption,
                                      string dgFilePath, string projectOption, string project, string frameworkOption, string frameworkString, string sourceOption,
                                      string sourceString, string packageDirectoryOption, string packageDirectory, string noRestoreSwitch)
        {
            // Arrange
            var projectPath = Path.Combine(Path.GetTempPath(), project);

            File.Create(projectPath).Dispose();

            var argList = new List <string>()
            {
                "add",
                packageOption,
                package,
                versionOption,
                version,
                dgFileOption,
                dgFilePath,
                projectOption,
                projectPath
            };

            if (!string.IsNullOrEmpty(frameworkOption))
            {
                argList.Add(frameworkOption);
                argList.Add(frameworkString);
            }
            if (!string.IsNullOrEmpty(sourceOption))
            {
                argList.Add(sourceOption);
                argList.Add(sourceString);
            }
            if (!string.IsNullOrEmpty(packageDirectoryOption))
            {
                argList.Add(packageDirectoryOption);
                argList.Add(packageDirectory);
            }
            if (!string.IsNullOrEmpty(noRestoreSwitch))
            {
                argList.Add(noRestoreSwitch);
            }

            var logger            = new TestCommandOutputLogger();
            var testApp           = new CommandLineApplication();
            var mockCommandRunner = new Mock <IPackageReferenceCommandRunner>();

            mockCommandRunner
            .Setup(m => m.ExecuteCommand(It.IsAny <PackageReferenceArgs>(), It.IsAny <MSBuildAPIUtility>()))
            .ReturnsAsync(0);

            testApp.Name = "dotnet nuget_test";
            AddPackageReferenceCommand.Register(testApp,
                                                () => logger,
                                                () => mockCommandRunner.Object);

            // Act
            var result = testApp.Execute(argList.ToArray());

            XPlatTestUtils.DisposeTemporaryFile(projectPath);

            // Assert
            mockCommandRunner.Verify(m => m.ExecuteCommand(It.Is <PackageReferenceArgs>(p => p.PackageDependency.Id == package &&
                                                                                        p.PackageDependency.VersionRange.OriginalString == version &&
                                                                                        p.ProjectPath == projectPath &&
                                                                                        p.DgFilePath == dgFilePath &&
                                                                                        p.NoRestore == !string.IsNullOrEmpty(noRestoreSwitch) &&
                                                                                        (string.IsNullOrEmpty(frameworkOption) || !string.IsNullOrEmpty(frameworkOption) && p.Frameworks.SequenceEqual(MSBuildStringUtility.Split(frameworkString))) &&
                                                                                        (string.IsNullOrEmpty(sourceOption) || !string.IsNullOrEmpty(sourceOption) && p.Sources.SequenceEqual(MSBuildStringUtility.Split(sourceString))) &&
                                                                                        (string.IsNullOrEmpty(packageDirectoryOption) || !string.IsNullOrEmpty(packageDirectoryOption) && p.PackageDirectory == packageDirectory)),
                                                           It.IsAny <MSBuildAPIUtility>()));

            Assert.Equal(0, result);
        }