當前位置: 首頁>>代碼示例>>C#>>正文


C# MockProjectPackageRepository.Exists方法代碼示例

本文整理匯總了C#中NuGet.VisualStudio.Test.MockProjectPackageRepository.Exists方法的典型用法代碼示例。如果您正苦於以下問題:C# MockProjectPackageRepository.Exists方法的具體用法?C# MockProjectPackageRepository.Exists怎麽用?C# MockProjectPackageRepository.Exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NuGet.VisualStudio.Test.MockProjectPackageRepository的用法示例。


在下文中一共展示了MockProjectPackageRepository.Exists方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UpdatePackagesWithOperationsAddPackageCorrectly

        public void UpdatePackagesWithOperationsAddPackageCorrectly()
        {
            // Arrange            
            var localRepository = new MockSharedPackageRepository();

            var projectRepository = new MockProjectPackageRepository(localRepository);
            var sourceRepository = new MockPackageRepository();
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            var A1 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello1" });
            var A2 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello2" });
            var A3 = PackageUtility.CreatePackage("A", "3.0", new[] { "hello3" });

            var B1 = PackageUtility.CreatePackage("B", "1.0", new[] { "world1" });
            var B2 = PackageUtility.CreatePackage("B", "2.0", new[] { "world2" });

            sourceRepository.AddPackage(A2);
            sourceRepository.AddPackage(A3);
            sourceRepository.AddPackage(B1);
            sourceRepository.AddPackage(B2);

            localRepository.AddPackage(A1);
            localRepository.AddPackage(B1);

            projectRepository.Add(A1);
            projectRepository.Add(B1);

            var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
            var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);
 
            var operations = new PackageOperation[] {
                new PackageOperation(A3, PackageAction.Install),
                new PackageOperation(B2, PackageAction.Install)
            };

            // Act
            packageManager.UpdatePackages(projectManager, new[] { A3, B2 }, operations, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance);

            // Assert
            Assert.True(localRepository.Exists("A", new SemanticVersion("3.0")));
            Assert.False(localRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.False(localRepository.Exists("A", new SemanticVersion("1.0")));

            Assert.True(localRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.False(localRepository.Exists("B", new SemanticVersion("1.0")));

            Assert.True(projectRepository.Exists("A", new SemanticVersion("3.0")));
            Assert.True(projectRepository.Exists("B", new SemanticVersion("2.0")));
        }
開發者ID:shrknt35,項目名稱:sonarlint-vs,代碼行數:49,代碼來源:VsPackageManagerTest.cs

示例2: InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig2

        public void InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig2(bool skipAssemblyReferences)
        {
            // Arrange
            // Source repository has A -> B, where B is a project-level package and A is a meta-package.
            // We want to make sure A is added to the packages.config of the project, and NOT packages.config of the solution
            var localRepository = new MockSharedPackageRepository();

            var sourceRepository = new MockPackageRepository();
            var packageA = PackageUtility.CreatePackage("A", "2.0", tools: new[] { "install.ps1" });
            sourceRepository.Add(packageA);

            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(projectSystem);

            var packageManager = new VsPackageManager(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem,
                localRepository,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            var projectRepository = new MockProjectPackageRepository(localRepository);
            var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, projectRepository);

            // Act
            packageManager.InstallPackage(
                projectManager,
                "A",
                new SemanticVersion("2.0"),
                ignoreDependencies: false,
                allowPrereleaseVersions: true,
                skipAssemblyReferences: skipAssemblyReferences,
                logger: null);

            // Assert
            Assert.True(!projectRepository.Exists("A", new SemanticVersion("2.0")));

            // assert that packages.config for solution-level is created.
            Assert.True(localRepository.IsSolutionReferenced("A", new SemanticVersion("2.0")));
        }
開發者ID:shrknt35,項目名稱:sonarlint-vs,代碼行數:42,代碼來源:VsPackageManagerTest.cs

示例3: InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig

        public void InstallSolutionLevelPackageAddEntryToSolutionPackagesConfig(bool allowPrerelease)
        {
            // Arrange
            // Source repository has A -> B, where B is a project-level package and A is a meta-package.
            // We want to make sure A is added to the packages.config of the project, and NOT packages.config of the solution
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();

            var sourceRepository = new MockPackageRepository();
            var packageA = PackageUtility.CreatePackage("A", "2.0", tools: new[] { "install.ps1" });
            sourceRepository.Add(packageA);

            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(projectSystem);

            var packageManager = new VsPackageManager(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem,
                localRepository.Object,
                new Mock<IRecentPackageRepository>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            var projectRepository = new MockProjectPackageRepository(localRepository.Object);
            var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);

            localRepository.Setup(r => r.IsReferenced(It.IsAny<string>(), It.IsAny<SemanticVersion>())).
                Returns((string id, SemanticVersion version) => projectRepository.Exists(id, version));

            // Act
            packageManager.InstallPackage(
                projectManager,
                "A",
                new SemanticVersion("2.0"),
                ignoreDependencies: false,
                allowPrereleaseVersions: allowPrerelease,
                logger: null);

            // Assert
            Assert.True(!projectRepository.Exists("A", new SemanticVersion("2.0")));

            // assert that packages.config for solution-level is created.
            localRepository.Verify(r => r.AddPackageReferenceEntry("A", new SemanticVersion("2.0")), Times.Once());
        }
開發者ID:themotleyfool,項目名稱:NuGet,代碼行數:44,代碼來源:VsPackageManagerTest.cs

示例4: InstallMetaPackageDoesNotAddEntryToSolutionPackagesConfig2

        public void InstallMetaPackageDoesNotAddEntryToSolutionPackagesConfig2(bool skipAssemblyReferences)
        {
            // Arrange
            // Source repository has A -> B, where B is a project-level package and A is a meta-package.
            // We want to make sure A is added to the packages.config of the project, and NOT packages.config of the solution
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();

            var sourceRepository = new MockPackageRepository();
            var packageB = PackageUtility.CreatePackage("B", "1.0", new string[] { "hello.txt" });
            var packageA = PackageUtility.CreatePackage("A", "2.0", new string[] { "world" }, dependencies: new[] { new PackageDependency("B") });
            sourceRepository.Add(packageA);
            sourceRepository.Add(packageB);

            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(projectSystem);

            var packageManager = new VsPackageManager(
                TestUtils.GetSolutionManager(),
                sourceRepository,
                new Mock<IFileSystemProvider>().Object,
                projectSystem,
                localRepository.Object,
                new Mock<IDeleteOnRestartManager>().Object,
                new Mock<VsPackageInstallerEvents>().Object);

            var projectRepository = new MockProjectPackageRepository(localRepository.Object);
            var projectManager = new ProjectManager(localRepository.Object, pathResolver, projectSystem, projectRepository);

            localRepository.Setup(r => r.IsReferenced(It.IsAny<string>(), It.IsAny<SemanticVersion>())).
                Returns((string id, SemanticVersion version) => projectRepository.Exists(id, version));

            // Act
            packageManager.InstallPackage(
                projectManager, 
                "A", 
                new SemanticVersion("2.0"), 
                ignoreDependencies: false, 
                allowPrereleaseVersions: true, 
                skipAssemblyReferences: skipAssemblyReferences, 
                logger: null);

            // Assert
            Assert.True(projectRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.True(projectRepository.Exists("B", new SemanticVersion("1.0")));

            // assert that packages.config for solution-level is not created.
            Assert.False(localRepository.Object.IsSolutionReferenced("A", new SemanticVersion("2.0")));
            Assert.False(localRepository.Object.IsSolutionReferenced("B", new SemanticVersion("1.0")));
        }
開發者ID:shrknt35,項目名稱:sonarlint-vs,代碼行數:49,代碼來源:VsPackageManagerTest.cs

示例5: UpdatePackagesEndToEndWhereNewerVersionPackageDoesNotHaveDependencyLikeOlderVersion

        public void UpdatePackagesEndToEndWhereNewerVersionPackageDoesNotHaveDependencyLikeOlderVersion()
        {
            // Arrange            
            var localRepository = new MockSharedPackageRepository();

            var projectRepository = new MockProjectPackageRepository(localRepository);
            var sourceRepository = new MockPackageRepository();
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            var A1 = PackageUtility.CreatePackage("A", "1.0", new[] { "hello1" }, dependencies: new[] { PackageDependency.CreateDependency("B", "1.0") });
            var A2 = PackageUtility.CreatePackage("A", "2.0", new[] { "hello2" }, dependencies: new[] { PackageDependency.CreateDependency("C", "1.0") });

            var B1 = PackageUtility.CreatePackage("B", "1.0", new[] { "world1" });
            var B2 = PackageUtility.CreatePackage("B", "2.0", new[] { "world2" });

            var C1 = PackageUtility.CreatePackage("C", "1.0", new[] { "galaxy1" });
            var C2 = PackageUtility.CreatePackage("C", "2.0", new[] { "galaxy2" });

            sourceRepository.AddPackage(A1);
            sourceRepository.AddPackage(A2);
            sourceRepository.AddPackage(B1);
            sourceRepository.AddPackage(B2);
            sourceRepository.AddPackage(C1);
            sourceRepository.AddPackage(C2);

            localRepository.AddPackage(A1);
            localRepository.AddPackage(B1);
            localRepository.AddPackage(C1);

            projectRepository.Add(A1);
            projectRepository.Add(B1);
            projectRepository.Add(C1);

            var packageManager = new VsPackageManager(TestUtils.GetSolutionManager(), sourceRepository, new Mock<IFileSystemProvider>().Object, fileSystem, localRepository, new Mock<IDeleteOnRestartManager>().Object, new Mock<VsPackageInstallerEvents>().Object);
            var projectManager = new ProjectManager(localRepository, pathResolver, new MockProjectSystem(), projectRepository);

            var installWalker = new InstallWalker(
                localRepository,
                sourceRepository,
                null,
                logger: NullLogger.Instance,
                ignoreDependencies: false,
                allowPrereleaseVersions: true);

            IList<IPackage> updatePackagesByDependencyOrder;
            var updatePackages = new List<IPackage> { A2, B2, C2 };
            var operationsForShowingLicense = installWalker.ResolveOperations(updatePackages, out updatePackagesByDependencyOrder);

            // Act
            packageManager.UpdatePackages(projectManager, updatePackagesByDependencyOrder, operationsForShowingLicense, updateDependencies: true, allowPrereleaseVersions: true, logger: NullLogger.Instance);

            // Assert
            // NOTE THAT BELOW, there is no uninstall operation for B1 but only for C1. Because A2 depends on C1 only where A1 depends on B1 only
            // And, the operations are resolved for A2 NOT A1
            Assert.True(operationsForShowingLicense.Count == 4);
            Assert.True(operationsForShowingLicense[0].Package == A2 && operationsForShowingLicense[0].Action == PackageAction.Install);
            Assert.True(operationsForShowingLicense[1].Package == B2 && operationsForShowingLicense[1].Action == PackageAction.Install);
            Assert.True(operationsForShowingLicense[2].Package == C1 && operationsForShowingLicense[2].Action == PackageAction.Uninstall);
            Assert.True(operationsForShowingLicense[3].Package == C2 && operationsForShowingLicense[3].Action == PackageAction.Install);

            Assert.True(updatePackagesByDependencyOrder.Count == 3);
            Assert.True(updatePackagesByDependencyOrder[0] == C2);
            Assert.True(updatePackagesByDependencyOrder[1] == A2);
            Assert.True(updatePackagesByDependencyOrder[2] == B2);

            Assert.True(localRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.False(localRepository.Exists("A", new SemanticVersion("1.0")));

            Assert.True(localRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.False(localRepository.Exists("B", new SemanticVersion("1.0")));

            Assert.True(localRepository.Exists("C", new SemanticVersion("2.0")));
            Assert.False(localRepository.Exists("C", new SemanticVersion("1.0")));

            Assert.True(projectRepository.Exists("A", new SemanticVersion("2.0")));
            Assert.True(projectRepository.Exists("B", new SemanticVersion("2.0")));
            Assert.True(projectRepository.Exists("C", new SemanticVersion("2.0")));
        }
開發者ID:Berzeger,項目名稱:NuGet,代碼行數:78,代碼來源:VsPackageManagerTest.cs


注:本文中的NuGet.VisualStudio.Test.MockProjectPackageRepository.Exists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。