当前位置: 首页>>代码示例>>C#>>正文


C# InstallPackageCommand.Execute方法代码示例

本文整理汇总了C#中InstallPackageCommand.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# InstallPackageCommand.Execute方法的具体用法?C# InstallPackageCommand.Execute怎么用?C# InstallPackageCommand.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InstallPackageCommand的用法示例。


在下文中一共展示了InstallPackageCommand.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InstallPackageCmdletPassesParametersCorrectlyWhenIdAndVersionAreSpecified

        public void InstallPackageCmdletPassesParametersCorrectlyWhenIdAndVersionAreSpecified()
        {
            // Arrange
            var vsPackageManager = new MockVsPackageManager();
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager);

            var cmdlet = new InstallPackageCommand(
                TestUtils.GetSolutionManager(), 
                packageManagerFactory.Object, 
                null, 
                new Mock<IVsPackageSourceProvider>().Object, 
                null, 
                null,
                new Mock<IVsCommonOperations>().Object,
                new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Id = "my-id";
            cmdlet.Version = new SemanticVersion("2.8");

            // Act
            cmdlet.Execute();

            // Assert
            Assert.Equal("my-id", vsPackageManager.PackageId);
            Assert.Equal(new SemanticVersion("2.8"), vsPackageManager.Version);
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:26,代码来源:InstallPackageCommandTest.cs

示例2: InstallPackageCmdletUsesPackageManangerWithSourceIfSpecified

        public void InstallPackageCmdletUsesPackageManangerWithSourceIfSpecified()
        {
            // Arrange
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            var vsPackageManager = new MockVsPackageManager();
            var sourceVsPackageManager = new MockVsPackageManager();
            var mockPackageRepository = new MockPackageRepository();
            var sourceProvider = GetPackageSourceProvider(new PackageSource("somesource"));
            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            repositoryFactory.Setup(c => c.CreateRepository(It.Is<string>(s => s == "somesource"))).Returns(mockPackageRepository);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager);
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true)).Returns(sourceVsPackageManager);
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Source = "somesource";
            cmdlet.Id = "my-id";
            cmdlet.Version = new SemanticVersion("2.8");

            // Act
            cmdlet.Execute();

            // Assert
            Assert.Same(sourceVsPackageManager, cmdlet.PackageManager);
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:23,代码来源:InstallPackageCommandTest.cs

示例3: InstallPackageShouldPickUnListedPrereleasePackagesIfItSatisfiesContrainsAndOthersAreNot

        public void InstallPackageShouldPickUnListedPrereleasePackagesIfItSatisfiesContrainsAndOthersAreNot()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B", new VersionSpec { MinVersion = new SemanticVersion("1.0"), IsMinInclusive = true }) });
            var packageB1 = PackageUtility.CreatePackage("B", "0.0.9", listed: true);
            var packageB2 = PackageUtility.CreatePackage("B", "1.0.1-a", listed: false);
            var packageRepository = new MockPackageRepository { packageA, packageB1, packageB2 };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(packageManager.SolutionManager, packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert: packageA and packageB2 are installed.
            // packageB1 is not picked because it cannot be used as a dependency of packageA
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(2, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
            Assert.Equal(packageB2, installedPackages[1], PackageEqualityComparer.IdAndVersion);
        }
开发者ID:rikoe,项目名称:nuget,代码行数:26,代码来源:InstallPackageCommandTest.cs

示例4: InstallPackageWithoutSettingVersionDoNotInstallUnlistedPackage

        public void InstallPackageWithoutSettingVersionDoNotInstallUnlistedPackage()
        {
            // Arrange
            var packageA1 = PackageUtility.CreatePackage("A", "1.0.0");
            var packageA2 = PackageUtility.CreatePackage("A", "2.0.0", listed: false);
            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.Setup(s => s.GetPackages()).Returns(Enumerable.Empty<IPackage>().AsQueryable());
            sharedRepository.Setup(s => s.AddPackage(packageA1));

            var packageRepository = new MockPackageRepository { packageA1, packageA2 };
            var recentPackageRepository = new Mock<IRecentPackageRepository>();
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new MockFileSystem(), sharedRepository.Object, recentPackageRepository.Object, new VsPackageInstallerEvents());
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object);
            cmdlet.Id = "A";
            cmdlet.Execute();

            // Assert
            sharedRepository.Verify(s => s.AddPackage(packageA1), Times.Once());
            sharedRepository.Verify(s => s.AddPackage(packageA2), Times.Never());
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:24,代码来源:InstallPackageCommandTest.cs

示例5: InstallPackageCmdletOnlyOpenReadmeFileFromTheRootPackage

        public void InstallPackageCmdletOnlyOpenReadmeFileFromTheRootPackage()
        {
            // Arrange
            // A --> B
            var packageA = new Mock<IPackage>();
            packageA.Setup(p => p.Id).Returns("A");
            packageA.Setup(p => p.Version).Returns(new SemanticVersion("1.0"));
            var depSet = new PackageDependencySet(null, new[] { new PackageDependency("B") });
            packageA.Setup(p => p.DependencySets).Returns(new[] { depSet });
            packageA.Setup(p => p.Listed).Returns(true);
            var readme = new Mock<IPackageFile>();
            readme.Setup(f => f.Path).Returns("readMe.txt");
            readme.Setup(f => f.GetStream()).Returns(new MemoryStream());
            packageA.Setup(p => p.GetFiles()).Returns(new IPackageFile[] { readme.Object });

            var packageB = new Mock<IPackage>();
            packageB.Setup(p => p.Id).Returns("B");
            packageB.Setup(p => p.Version).Returns(new SemanticVersion("1.0"));
            var readmeB = new Mock<IPackageFile>();
            readmeB.Setup(f => f.Path).Returns("readMe.txt");
            readmeB.Setup(f => f.GetStream()).Returns(new MemoryStream());
            packageB.Setup(p => p.GetFiles()).Returns(new IPackageFile[] { readmeB.Object });

            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.Setup(s => s.GetPackages()).Returns(Enumerable.Empty<IPackage>().AsQueryable());
            sharedRepository.Setup(s => s.AddPackage(packageA.Object));
            sharedRepository.Setup(s => s.AddPackage(packageB.Object));
            sharedRepository.Setup(s => s.IsReferenced("A", new SemanticVersion("1.0"))).Returns(true);
            sharedRepository.Setup(s => s.IsReferenced("B", new SemanticVersion("1.0"))).Returns(true);

            var packageRepository = new MockPackageRepository { packageA.Object, packageB.Object };
            var packageManager = new VsPackageManager(
                TestUtils.GetSolutionManagerWithProjects("foo"), 
                packageRepository,
                new Mock<IFileSystemProvider>().Object,
                new MockFileSystem(),
                sharedRepository.Object,
                new Mock<IDeleteOnRestartManager>().Object,
                new VsPackageInstallerEvents());
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            var fileOperations = new Mock<IVsCommonOperations>();

            // Act
            var cmdlet = new InstallPackageCommand(
                TestUtils.GetSolutionManager(), 
                packageManagerFactory.Object, 
                null,
                new Mock<IVsPackageSourceProvider>().Object, 
                new Mock<IHttpClientEvents>().Object, 
                null, 
                fileOperations.Object,
                new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Id = "A";
            cmdlet.Execute();

            // Assert
            fileOperations.Verify(io => io.OpenFile(It.Is<string>(s => s.EndsWith("A.1.0\\readme.txt", StringComparison.OrdinalIgnoreCase))), Times.Once());
            fileOperations.Verify(io => io.OpenFile(It.Is<string>(s => s.EndsWith("B.1.0\\readme.txt", StringComparison.OrdinalIgnoreCase))), Times.Never());
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:61,代码来源:InstallPackageCommandTest.cs

示例6: InstallPackageInstallUnlistedPrereleasePackageIfVersionIsSet

        public void InstallPackageInstallUnlistedPrereleasePackageIfVersionIsSet()
        {
            // Arrange
            var packageA1 = PackageUtility.CreatePackage("A", "1.0.0");
            var packageA2 = PackageUtility.CreatePackage("A", "1.0.0-ReleaseCandidate", listed: false);
            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.Setup(s => s.GetPackages()).Returns(Enumerable.Empty<IPackage>().AsQueryable());
            sharedRepository.Setup(s => s.AddPackage(packageA2));
            sharedRepository.Setup(s => s.IsReferenced("A", new SemanticVersion("1.0.0-ReleaseCandidate"))).Returns(true);

            var packageRepository = new MockPackageRepository { packageA1, packageA2 };
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new VsPackageInstallerEvents());
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Id = "A";
            cmdlet.Version = new SemanticVersion("1.0.0-ReleaseCandidate");
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert
            sharedRepository.Verify(s => s.AddPackage(packageA1), Times.Never());
            sharedRepository.Verify(s => s.AddPackage(packageA2), Times.Once());
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:26,代码来源:InstallPackageCommandTest.cs

示例7: InstallPackageCmdletDoesNotInstallPrereleasePackageIfFlagIsNotPresent

        public void InstallPackageCmdletDoesNotInstallPrereleasePackageIfFlagIsNotPresent()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            var packageRepository = new MockPackageRepository { PackageUtility.CreatePackage("A", "1.0.0-a") };
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, new Mock<IDeleteOnRestartManager>().Object, null);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, null, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Id = "A";


            // Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => cmdlet.Execute(), "Unable to find package 'A'.");
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:17,代码来源:InstallPackageCommandTest.cs

示例8: InstallPackageCmdletCreatesFallbackRepository

        public void InstallPackageCmdletCreatesFallbackRepository()
        {
            // Arrange
            var productUpdateService = new Mock<IProductUpdateService>();
            IPackageRepository repoA = new MockPackageRepository(), repoB = new MockPackageRepository();
            var package = NuGet.Test.PackageUtility.CreatePackage("P1", dependencies: new[] { new PackageDependency("P2") });
            repoA.AddPackage(package);
            repoB.AddPackage(NuGet.Test.PackageUtility.CreatePackage("P2"));
            var sharedRepo = new Mock<ISharedPackageRepository>();
            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            repositoryFactory.Setup(c => c.CreateRepository("A")).Returns(repoA);
            repositoryFactory.Setup(c => c.CreateRepository("B")).Returns(repoB);
            var sourceProvider = GetPackageSourceProvider(new PackageSource("A"), new PackageSource("B"));
            var fileSystemProvider = new Mock<IFileSystemProvider>();
            fileSystemProvider.Setup(c => c.GetFileSystem(It.IsAny<string>(), It.IsAny<bool>())).Returns(new MockFileSystem());
            var repositorySettings = new Mock<IRepositorySettings>();
            repositorySettings.Setup(c => c.RepositoryPath).Returns(String.Empty);

            var solutionManager = new Mock<ISolutionManager>();
            var packageManagerFactory = new Mock<VsPackageManagerFactory>(solutionManager.Object, repositoryFactory.Object, sourceProvider, fileSystemProvider.Object, repositorySettings.Object, new Mock<VsPackageInstallerEvents>().Object);
            packageManagerFactory.Setup(f => f.GetConfigSettingsFileSystem(It.IsAny<string>())).Returns(new MockFileSystem());

            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManagerWithProjects("foo"), packageManagerFactory.Object, repositoryFactory.Object, sourceProvider, null, productUpdateService.Object, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object);
            cmdlet.Id = "P1";
            cmdlet.Source = "A";

            // Act
            cmdlet.Execute();

            // Assert
            // If we've come this far, P1 is successfully installed.
            Assert.True(true);
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:33,代码来源:InstallPackageCommandTest.cs

示例9: InstallPackageCmdletPassesIgnoreDependencySwitchCorrectly

        public void InstallPackageCmdletPassesIgnoreDependencySwitchCorrectly()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0.0", dependencies: new[] { new PackageDependency("B") });
            var packageB = PackageUtility.CreatePackage("B", "1.0.0");
            var packageRepository = new MockPackageRepository { packageA, packageB };
            var packageManager = new MockVsPackageManager2(
                @"c:\solution",
                packageRepository);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(
                packageManager.SolutionManager, 
                packageManagerFactory.Object, 
                null, 
                new Mock<IVsPackageSourceProvider>().Object, 
                null,
                null,
                new Mock<IVsCommonOperations>().Object,
                new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";
            cmdlet.IgnoreDependencies = new SwitchParameter(true);
            cmdlet.Execute();

            // Assert: only packageA is installed. packageB is not.
            var installedPackages = packageManager.LocalRepository.GetPackages().ToList();
            Assert.Equal(1, installedPackages.Count);
            Assert.Equal(packageA, installedPackages[0], PackageEqualityComparer.IdAndVersion);
        }
开发者ID:rikoe,项目名称:nuget,代码行数:31,代码来源:InstallPackageCommandTest.cs

示例10: InstallPackageCmdletInstallPrereleasePackageIfFlagIsPresent

        public void InstallPackageCmdletInstallPrereleasePackageIfFlagIsPresent()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0.0-a");
            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.SetupSet(s => s.PackageSaveMode = PackageSaveModes.Nupkg);
            sharedRepository.Setup(s => s.GetPackages()).Returns(Enumerable.Empty<IPackage>().AsQueryable());
            sharedRepository.Setup(s => s.AddPackage(packageA)).Verifiable();
            sharedRepository.Setup(s => s.IsReferenced("A", new SemanticVersion("1.0.0-a"))).Returns(true);
            var packageRepository = new MockPackageRepository { packageA };
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, new Mock<IDeleteOnRestartManager>().Object, new VsPackageInstallerEvents());
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(
                TestUtils.GetSolutionManager(), 
                packageManagerFactory.Object, 
                null, 
                new Mock<IVsPackageSourceProvider>().Object, 
                new Mock<IHttpClientEvents>().Object, 
                null,
                new Mock<IVsCommonOperations>().Object,
                new Mock<IDeleteOnRestartManager>().Object,
                true);

            cmdlet.Id = "A";
            cmdlet.IncludePrerelease = true;
            cmdlet.Execute();

            // Assert
            sharedRepository.Verify();
        }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:33,代码来源:InstallPackageCommandTest.cs

示例11: InstallPackageCmdletDoesNotInstallPrereleasePackageIfFlagIsNotPresent

        public void InstallPackageCmdletDoesNotInstallPrereleasePackageIfFlagIsNotPresent()
        {
            // Arrange
            var packageA1 = PackageUtility.CreatePackage("A", "1.0.0-a");
            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.SetupSet(s => s.PackageSaveMode = PackageSaveModes.Nupkg);

            var packageRepository = new MockPackageRepository { packageA1 };
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, new Mock<IDeleteOnRestartManager>().Object, null);
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, null, null, null, new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, true);
            cmdlet.Id = "A";


            // Assert
            ExceptionAssert.Throws<NotImplementedException>(() => cmdlet.Execute(), "WriteWarning");
            sharedRepository.Verify(s => s.AddPackage(packageA1), Times.Never());
        }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:21,代码来源:InstallPackageCommandTest.cs

示例12: FallbackToCacheDoesntHappenWhenAggregateIsUsedAndLocalSourceIsAvailable

        public void FallbackToCacheDoesntHappenWhenAggregateIsUsedAndLocalSourceIsAvailable()
        {
            // Arrange
            string localdrive = System.Environment.GetEnvironmentVariable("TEMP");
            var userSettings = new Mock<ISettings>();
            userSettings.Setup(s => s.GetSettingValues("packageSources", true)).Returns(new[]
            {
                new SettingValue("one", @"\\LetsHopeThisDirectory\IsNotAvaialble", false),
                new SettingValue("two", localdrive, false),
                new SettingValue("three", @"http://SomeHttpSource/NotAvailable", false),
            });

            userSettings.Setup(s => s.GetValues("activePackageSource"))
                        .Returns(new[] { new KeyValuePair<string, string>("All", @"(All)"),
                                         });

            var provider = new VsPackageSourceProvider(userSettings.Object, CreateDefaultSourceProvider(userSettings.Object), new

Mock<IVsShellInfo>().Object);
            var activeSource = provider.ActivePackageSource;

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            var vsPackageManager = new MockVsPackageManager();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager);
            var sourceVsPackageManager = new MockVsPackageManager();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true)).Returns(sourceVsPackageManager);

            //Act           
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(),
                packageManagerFactory.Object, repositoryFactory.Object,
                provider, null, null,
                new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, false);
            cmdlet.Id = "my-id";
            cmdlet.Execute();

            // Assert
            Assert.NotEqual(cmdlet.Source, NuGet.MachineCache.Default.Source);
        }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:39,代码来源:InstallPackageCommandTest.cs

示例13: InstallPackageCmdletFallsbackToCacheWhenNetworkIsUnavailable

        public void InstallPackageCmdletFallsbackToCacheWhenNetworkIsUnavailable()
        {
            // Arrange
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            var vsPackageManager = new MockVsPackageManager();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager);
            var sourceVsPackageManager = new MockVsPackageManager();
            packageManagerFactory.Setup(m => m.CreatePackageManager(It.IsAny<IPackageRepository>(), true)).Returns(sourceVsPackageManager);

            var userSettings = new Mock<ISettings>();
            userSettings.Setup(s => s.GetSettingValues("packageSources", true)).Returns(new[]
            {
                new SettingValue("one", @"\\LetsHopeThisDirectory\IsNotAvaialble", false),
            });

            userSettings.Setup(s => s.GetValues("activePackageSource"))
                        .Returns(new[] { new KeyValuePair<string, string>("one", @"\\LetsHopeThisDirectory\IsNotAvaialble") });

            var provider = new VsPackageSourceProvider(userSettings.Object, CreateDefaultSourceProvider(userSettings.Object), new

Mock<IVsShellInfo>().Object);
            var activeSource = provider.ActivePackageSource;


            //Act           
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(),
                packageManagerFactory.Object, repositoryFactory.Object,
                provider, null, null,
                new Mock<IVsCommonOperations>().Object, new Mock<IDeleteOnRestartManager>().Object, false);
            cmdlet.Id = "my-id";
            cmdlet.Execute();

            // Assert
            Assert.Equal(cmdlet.Source, NuGet.MachineCache.Default.Source);
        }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:36,代码来源:InstallPackageCommandTest.cs

示例14: InstallPackageShouldPickListedPackagesOverUnlistedOnesAsDependency

        public void InstallPackageShouldPickListedPackagesOverUnlistedOnesAsDependency()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0", dependencies: new[] { new PackageDependency("B", new VersionSpec { MinVersion = new SemanticVersion("0.5")})});
            var packageB1 = PackageUtility.CreatePackage("B", "1.0.0", listed: true);
            var packageB2 = PackageUtility.CreatePackage("B", "1.0.2", listed: false);
            var sharedRepository = new Mock<ISharedPackageRepository>();
            sharedRepository.Setup(s => s.GetPackages()).Returns(Enumerable.Empty<IPackage>().AsQueryable());
            sharedRepository.Setup(s => s.AddPackage(packageA)).Verifiable();
            sharedRepository.Setup(s => s.AddPackage(packageB1)).Verifiable();

            var packageRepository = new MockPackageRepository { packageA, packageB1, packageB2 };
            var recentPackageRepository = new Mock<IRecentPackageRepository>();
            var packageManager = new VsPackageManager(TestUtils.GetSolutionManagerWithProjects("foo"), packageRepository, new Mock<IFileSystemProvider>().Object, new MockFileSystem(), sharedRepository.Object, recentPackageRepository.Object, new VsPackageInstallerEvents());
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>(MockBehavior.Strict);
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(packageManager);

            // Act
            var cmdlet = new InstallPackageCommand(TestUtils.GetSolutionManager(), packageManagerFactory.Object, null, new Mock<IVsPackageSourceProvider>().Object, new Mock<IHttpClientEvents>().Object, null, new Mock<IVsCommonOperations>().Object);
            cmdlet.Id = "A";
            cmdlet.Execute();

            // Assert
            sharedRepository.Verify();
            sharedRepository.Verify(s => s.AddPackage(packageB2), Times.Never());
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:26,代码来源:InstallPackageCommandTest.cs

示例15: InstallPackageCmdletPassesIgnoreDependencySwitchCorrectly

        public void InstallPackageCmdletPassesIgnoreDependencySwitchCorrectly()
        {
            // Arrange
            var vsPackageManager = new MockVsPackageManager();
            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(m => m.CreatePackageManager()).Returns(vsPackageManager);

            var cmdlet = new InstallPackageCommand(
                TestUtils.GetSolutionManager(), 
                packageManagerFactory.Object, 
                null, 
                new Mock<IVsPackageSourceProvider>().Object, 
                null,
                null,
                new Mock<IVsCommonOperations>().Object);
            cmdlet.Id = "my-id";
            cmdlet.Version = new SemanticVersion("2.8");
            cmdlet.IgnoreDependencies = new SwitchParameter(true);

            // Act
            cmdlet.Execute();

            // Assert
            Assert.Equal("my-id", vsPackageManager.PackageId);
            Assert.Equal(new SemanticVersion("2.8"), vsPackageManager.Version);
            Assert.True(vsPackageManager.IgnoreDependencies);
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:27,代码来源:InstallPackageCommandTest.cs


注:本文中的InstallPackageCommand.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。