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


C# MockVsPackageManager.ReinstallPackage方法代码示例

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


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

示例1: ReinstallPackagesRestoresPackagesWithSameIdAndDifferentVersionsInAllProjectsCallingAnotherOverload

        public void ReinstallPackagesRestoresPackagesWithSameIdAndDifferentVersionsInAllProjectsCallingAnotherOverload()
        {
            // Arrange
            var localRepositoryMock = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var localRepository = localRepositoryMock.Object;

            var sourceRepository = new MockPackageRepository();
            var projectSystem1 = new MockProjectSystem();
            var pathResolver1 = new DefaultPackagePathResolver(projectSystem1);
            var packageReferenceRepository1 = new PackageReferenceRepository(projectSystem1, localRepository);
            var projectManager1 = new ProjectManager(localRepository, pathResolver1, projectSystem1, packageReferenceRepository1);

            var projectSystem2 = new MockProjectSystem();
            var pathResolver2 = new DefaultPackagePathResolver(projectSystem2);
            var packageReferenceRepository2 = new PackageReferenceRepository(projectSystem2, localRepository);
            var projectManager2 = new ProjectManager(localRepository, pathResolver2, projectSystem2, packageReferenceRepository2);

            var project1 = TestUtils.GetProject("Project1");
            var project2 = TestUtils.GetProject("Project2");

            var packageManager = new MockVsPackageManager(
                TestUtils.GetSolutionManager(projects: new[] { project1, project2 }),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem2,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            packageManager.RegisterProjectManager(project1, projectManager1);
            packageManager.RegisterProjectManager(project2, projectManager2);

            // A and A3 are two packages with the same id, but different version.
            // A is installed into project1, A3 into project2
            // Then A is changed to A2 and A3 is changed to A4. 
            // We verified that A2 and A4 are reinstalled
            var packageA = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "content.txt" },
                new[] { "lib\\ref.dll" });

            var packageA2 = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "foo.txt" },
                new[] { "lib\\bar.dll" });

            var A3 = PackageUtility.CreatePackage(
                "A",
                "2.0",
                new[] { "hello.txt" },
                new[] { "lib\\comma.dll" });

            var A4 = PackageUtility.CreatePackage(
                "A",
                "2.0",
                new[] { "world.txt" },
                new[] { "lib\\dude.dll" });

            sourceRepository.Add(packageA);
            sourceRepository.Add(A3);

            // install package A -> project 1
            // and package B -> project 2
            packageManager.InstallPackage(projectManager1, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
            packageManager.InstallPackage(projectManager2, "A", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectSystem1.FileExists("content.txt"));
            Assert.True(projectSystem1.ReferenceExists("ref.dll"));

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.True(projectManager2.LocalRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.True(projectSystem2.FileExists("hello.txt"));
            Assert.True(projectSystem2.ReferenceExists("comma.dll"));

            // now change the package A and B to different packages
            sourceRepository.RemovePackage(packageA);
            sourceRepository.RemovePackage(A3);
            sourceRepository.AddPackage(packageA2);
            sourceRepository.AddPackage(A4);

            localRepositoryMock.Setup(p => p.IsReferenced("A", new SemanticVersion("1.2-alpha"))).Returns((string id, SemanticVersion version) => projectManager1.LocalRepository.Exists(id, version));
            localRepositoryMock.Setup(p => p.IsReferenced("A", new SemanticVersion("2.0"))).Returns((string id, SemanticVersion version) => projectManager2.LocalRepository.Exists(id, version));

            // Act
            packageManager.ReinstallPackage("A", updateDependencies: true, allowPrereleaseVersions: false, logger: NullLogger.Instance, eventListener: NullPackageOperationEventListener.Instance);

            // Assert
            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager1.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));

            Assert.False(projectSystem1.FileExists("content.txt"));
            Assert.True(projectSystem1.FileExists("foo.txt"));
            Assert.False(projectSystem1.ReferenceExists("ref.dll"));
            Assert.True(projectSystem1.ReferenceExists("bar.dll"));

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("2.0")));
//.........这里部分代码省略.........
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:101,代码来源:VsPackageManagerTest.Reinstall.cs

示例2: ReinstallOnePackageInOneProjectSetOperationToUpdate

        public void ReinstallOnePackageInOneProjectSetOperationToUpdate()
        {
            // Arrange
            var localRepository = new MockSharedPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var projectRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(projectSystem);
            var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);

            var project = TestUtils.GetProject("project runway", projectFiles: new[] { "dotnetjunky.cs" });

            var packageManager = new MockVsPackageManager(
                TestUtils.GetSolutionManager(defaultProjectName: "project runway", projects: new[] { project }),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);
            packageManager.RegisterProjectManager(project, projectManager);

            var package = PackageUtility.CreatePackage("phuong", "1.0", new[] { "hello" });
            localRepository.AddPackage(package);
            projectRepository.AddPackage(package);
            sourceRepository.AddPackage(package);

            // Act
            packageManager.ReinstallPackage(
                projectManager,
                "phuong",
                updateDependencies: true,
                allowPrereleaseVersions: true,
                logger: NullLogger.Instance);

            // Assert
            Assert.Equal("Reinstall", sourceRepository.LastOperation);
            Assert.Equal("phuong", sourceRepository.LastMainPackageId);
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:39,代码来源:VsPackageManagerTest.Operation.cs


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