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


C# MockPackageRepository.Add方法代码示例

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


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

示例1: ReinstallPackagesRestoresPackageWithTheSameVersion

        public void ReinstallPackagesRestoresPackageWithTheSameVersion()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(projectSystem);
            var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository());

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

            var packageA = PackageUtility.CreatePackage("A", "1.2", new[] { "content.txt" });
            sourceRepository.Add(packageA);
            localRepository.AddPackage(packageA);
            projectManager.LocalRepository.AddPackage(packageA);

            // Act
            packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: null);

            // Assert
            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:30,代码来源:VsPackageManagerTest.Reinstall.cs

示例2: ReinstallPackagesSkipsReinstallingIfPackageDoesNotExistAndLogWarning

        public void ReinstallPackagesSkipsReinstallingIfPackageDoesNotExistAndLogWarning()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem();
            var pathResolver = new DefaultPackagePathResolver(projectSystem);
            var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, new MockPackageRepository());

            var installerEvents = new Mock<VsPackageInstallerEvents>(MockBehavior.Strict);
            int eventCount = 0;
            RegisterInstallerEvents(installerEvents, _ => eventCount++);

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

            var packageA = PackageUtility.CreatePackage("A", "1.2", new[] { "content.txt" });
            sourceRepository.Add(packageA);
            localRepository.AddPackage(packageA);
            projectManager.LocalRepository.AddPackage(packageA);

            // remove package from source repository to simulate missing package condition
            sourceRepository.Remove(packageA);

            var logger = new Mock<ILogger>();
            logger.Setup(s => s.Log(
                MessageLevel.Warning, 
                "Skipped reinstalling package '{0}' in project '{1}' because the package does not exist in the package source.", 
                "A 1.2",
                "x:\\MockFileSystem")
            ).Verifiable();

            // Act
            packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: true, logger: logger.Object);

            // Assert
            logger.Verify();
            Assert.Equal(0, eventCount);

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2")));
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:48,代码来源:VsPackageManagerTest.Reinstall.cs

示例3: UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite

        public void UpdatePackageOverwriteAllFilesWhenFileConflictActionSetToOverwrite()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var constraintProvider = NullConstraintProvider.Instance;
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            var projectSystem = new MockProjectSystem();
            projectSystem.AddFile("one.txt", "this is one");
            projectSystem.AddFile("two.txt", "this is two");

            var packages = new List<IPackage>();
            var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" });
            var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "one.txt", "two.txt" });
            localRepository.Add(package_A10);
            sourceRepository.Add(package_A12);

            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p));
            sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable());

            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository);

            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") });

            var console = new Mock<IConsole>();
            console.Setup(c => c.ResolveFileConflict(It.IsAny<string>())).Returns(FileConflictResolution.Ignore);

            var updateCommand = new UpdateCommand()
            {
                RepositoryFactory = repositoryFactory.Object,
                SourceProvider = packageSourceProvider.Object,
                Console = console.Object,
                FileConflictAction = FileConflictAction.Overwrite
            };

            // Act
            updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);

            // Assert
            Assert.True(localRepository.Exists("A", new SemanticVersion("1.2")));
            Assert.Equal("content\\one.txt", projectSystem.ReadAllText("one.txt"));
            Assert.Equal("content\\two.txt", projectSystem.ReadAllText("two.txt"));
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:47,代码来源:UpdateCommandTest.cs

示例4: SelfUpdateNoNuGetExeInNuGetExePackageThrows

        public void SelfUpdateNoNuGetExeInNuGetExePackageThrows()
        {
            // Arrange
            var factory = new Mock<IPackageRepositoryFactory>();
            var sourceProvider = new Mock<IPackageSourceProvider>();
            var repository = new MockPackageRepository();
            repository.Add(PackageUtility.CreatePackage("NuGet.CommandLine", "3.0"));
            factory.Setup(m => m.CreateRepository(It.IsAny<string>())).Returns(repository);

            ConsoleInfo consoleInfo = GetConsoleInfo();
            var updateCmd = new UpdateCommand(factory.Object, sourceProvider.Object);
            updateCmd.Console = consoleInfo.Console;
            updateCmd.Console = consoleInfo.Console;

            // Act & Assert
            ExceptionAssert.Throws<CommandLineException>(() => updateCmd.SelfUpdate("c:\foo.exe", new SemanticVersion("2.0")), "Invalid NuGet.CommandLine package. Unable to locate NuGet.exe within the package.");
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:17,代码来源:UpdateCommandTest.cs

示例5: SelfUpdateOlderVersionDoesNotUpdate

        public void SelfUpdateOlderVersionDoesNotUpdate()
        {
            // Arrange
            var factory = new Mock<IPackageRepositoryFactory>();
            var sourceProvider = new Mock<IPackageSourceProvider>();
            var repository = new MockPackageRepository();
            repository.Add(PackageUtility.CreatePackage("NuGet.CommandLine", "1.0"));
            factory.Setup(m => m.CreateRepository(It.IsAny<string>())).Returns(repository);

            ConsoleInfo consoleInfo = GetConsoleInfo();
            var updateCmd = new UpdateCommand(factory.Object, sourceProvider.Object);
            updateCmd.Console = consoleInfo.Console;

            // Act
            updateCmd.SelfUpdate("c:\foo.exe", new SemanticVersion("2.0"));

            // Assert
            Assert.Equal("NuGet.exe is up to date.", consoleInfo.WrittenLines[0]);
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:19,代码来源:UpdateCommandTest.cs

示例6: SelfUpdateNewVersionUpdatesExe

        public void SelfUpdateNewVersionUpdatesExe()
        {
            // Arrange
            var factory = new Mock<IPackageRepositoryFactory>();
            var repository = new MockPackageRepository();
            IPackage package = PackageUtility.CreatePackage("NuGet.CommandLine", "3.0", tools: new[] { "NuGet.exe" });
            repository.Add(package);
            factory.Setup(m => m.CreateRepository(It.IsAny<string>())).Returns(repository);

            ConsoleInfo consoleInfo = GetConsoleInfo();
            var selfUpdater = new MockSelfUpdater(factory.Object);
            selfUpdater.Console = consoleInfo.Console;

            // Act
            selfUpdater.SelfUpdate(@"c:\NuGet.exe", new SemanticVersion("2.0"));

            // Assert
            Assert.True(selfUpdater.MovedFiles.ContainsKey(@"c:\NuGet.exe"));
            Assert.Equal(@"c:\NuGet.exe.old", selfUpdater.MovedFiles[@"c:\NuGet.exe"]);
            Assert.True(selfUpdater.UpdatedFiles.ContainsKey(@"c:\NuGet.exe"));
            Assert.Equal(@"tools\NuGet.exe", selfUpdater.UpdatedFiles[@"c:\NuGet.exe"]);
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:22,代码来源:SelfUpdaterTests.cs

示例7: UpdatePackageAddsPackagesToSharedPackageRepositoryWhenReferencesAreAdded

        public void UpdatePackageAddsPackagesToSharedPackageRepositoryWhenReferencesAreAdded()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();
            var constraintProvider = NullConstraintProvider.Instance;
            var fileSystem = new MockFileSystem();
            var pathResolver = new DefaultPackagePathResolver(fileSystem);
            var projectSystem = new MockProjectSystem();
            var packages = new List<IPackage>();
            var package_A10 = PackageUtility.CreatePackage("A", "1.0", content: new[] { "1.txt" });
            var package_A12 = PackageUtility.CreatePackage("A", "1.2", content: new[] { "1.txt" });
            localRepository.Add(package_A10);
            sourceRepository.Add(package_A12);
            
            var sharedRepository = new Mock<ISharedPackageRepository>(MockBehavior.Strict);
            sharedRepository.SetupSet(s => s.PackageSaveMode = PackageSaveModes.Nupkg);
            sharedRepository.Setup(s => s.AddPackage(package_A12)).Callback<IPackage>(p => packages.Add(p)).Verifiable();
            sharedRepository.Setup(s => s.GetPackages()).Returns(packages.AsQueryable());
            
            var repositoryFactory = new Mock<IPackageRepositoryFactory>();
            repositoryFactory.Setup(s => s.CreateRepository(It.IsAny<string>())).Returns(sourceRepository);
            var packageSourceProvider = new Mock<IPackageSourceProvider>();
            packageSourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { new PackageSource("foo-source") });

            var updateCommand = new UpdateCommand()
            {
                RepositoryFactory = repositoryFactory.Object,
                SourceProvider = packageSourceProvider.Object
            };

            // Act
            updateCommand.UpdatePackages(localRepository, fileSystem, sharedRepository.Object, sourceRepository, constraintProvider, pathResolver, projectSystem);

            // Assert
            sharedRepository.Verify();
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:37,代码来源:UpdateCommandTest.cs

示例8: EnsurePackageDownloadsUsesMachineCacheIfAvailable

        public void EnsurePackageDownloadsUsesMachineCacheIfAvailable()
        {
            // Arrange
            var hashBytes = new byte[] { 1, 2, 3, 4 };
            var hash = Convert.ToBase64String(hashBytes);
            var zipPackage = PackageUtility.CreatePackage("A", "1.2");

            var hashProvider = new Mock<IHashProvider>(MockBehavior.Strict);
            hashProvider.Setup(h => h.CalculateHash(It.IsAny<byte[]>())).Returns(hashBytes);

            var mockRepository = new MockPackageRepository();
            mockRepository.Add(zipPackage);

            var servicePackage = new DataServicePackage
            {
                Id = "A",
                Version = "1.2",
                PackageHash = hash,
                HashProvider = hashProvider.Object,
            };

            // Act
            servicePackage.EnsurePackage(mockRepository);

            // Assert
            Assert.Equal(zipPackage, servicePackage._package);
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:27,代码来源:DataServicePackageTest.cs

示例9: ResolvingDependencyForUpdateWithConflictingDependents

        public void ResolvingDependencyForUpdateWithConflictingDependents()
        {
            // Arrange
            var localRepository = new MockPackageRepository();
            var sourceRepository = new MockPackageRepository();

            // A 1.0 -> B [1.0]
            IPackage A10 = PackageUtility.CreatePackage("A", "1.0",
                                                            dependencies: new List<PackageDependency> {
                                                                    PackageDependency.CreateDependency("B", "[1.0]")
                                                                }, content: new[] { "a1" });

            // A 2.0 -> B (any version)
            IPackage A20 = PackageUtility.CreatePackage("A", "2.0",
                                                            dependencies: new List<PackageDependency> {
                                                                    new PackageDependency("B")
                                                                }, content: new[] { "a2" });

            IPackage B10 = PackageUtility.CreatePackage("B", "1.0", content: new[] { "b1" });
            IPackage B101 = PackageUtility.CreatePackage("B", "1.0.1", content: new[] { "b101" });
            IPackage B20 = PackageUtility.CreatePackage("B", "2.0", content: new[] { "a2" });
            localRepository.Add(A10);
            localRepository.Add(B10);
            sourceRepository.AddPackage(A10);
            sourceRepository.AddPackage(A20);
            sourceRepository.AddPackage(B10);
            sourceRepository.AddPackage(B101);
            sourceRepository.AddPackage(B20);

            IPackageOperationResolver resolver = new UpdateWalker(localRepository,
                                                                  sourceRepository,
                                                                  new DependentsWalker(localRepository),
                                                                  NullConstraintProvider.Instance,
                                                                  NullLogger.Instance,
                                                                  updateDependencies: true,
                                                                  allowPrereleaseVersions: false) { AcceptedTargets = PackageTargets.Project };

            // Act
            var packages = resolver.ResolveOperations(B101).ToList();

            // Assert
            Assert.Equal(4, packages.Count);
            AssertOperation("A", "1.0", PackageAction.Uninstall, packages[0]);
            AssertOperation("B", "1.0", PackageAction.Uninstall, packages[1]);
            AssertOperation("A", "2.0", PackageAction.Install, packages[2]);
            AssertOperation("B", "1.0.1", PackageAction.Install, packages[3]);
        }
开发者ID:Berzeger,项目名称:NuGet,代码行数:47,代码来源:PackageWalkerTest.cs

示例10: ReinstallPackagesRestoresPackageInAllProjectsWithNewContentIfSourcePackageChanges

        public void ReinstallPackagesRestoresPackageInAllProjectsWithNewContentIfSourcePackageChanges()
        {
            // 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);

            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 packageB = PackageUtility.CreatePackage(
                "B",
                "2.0",
                new[] { "hello.txt" },
                new[] { "lib\\comma.dll" });

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

            sourceRepository.Add(packageA);
            sourceRepository.Add(packageB);

            // 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, "B", 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("B", new SemanticVersion("2.0")));
            Assert.True(projectManager2.LocalRepository.Exists("B", 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(packageB);
            sourceRepository.AddPackage(packageA2);
            sourceRepository.AddPackage(packageB2);

            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("B", new SemanticVersion("2.0"))).Returns((string id, SemanticVersion version) => projectManager2.LocalRepository.Exists(id, version));

            // Act
            packageManager.ReinstallPackages(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("B", new SemanticVersion("2.0")));
            Assert.True(projectManager2.LocalRepository.Exists("B", new SemanticVersion("2.0")));

            Assert.False(projectSystem2.FileExists("hello.txt"));
            Assert.True(projectSystem2.FileExists("world.txt"));
//.........这里部分代码省略.........
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:101,代码来源:VsPackageManagerTest.Reinstall.cs

示例11: ReinstallPackagesRestoresAllPackagesInAProjectWithNewContentIfProjectFrameworkChanges

        public void ReinstallPackagesRestoresAllPackagesInAProjectWithNewContentIfProjectFrameworkChanges()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v3.0"));
            var pathResolver = new DefaultPackagePathResolver(projectSystem);

            var packageReferenceRepository = new PackageReferenceRepository(projectSystem, localRepository);
            var projectManager = new ProjectManager(localRepository, pathResolver, projectSystem, packageReferenceRepository);

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

            var packageA = PackageUtility.CreatePackage(
                "A",
                "1.2-alpha",
                new[] { "net30\\content.txt", "silverlight40\\content4.txt" },
                new[] { "lib\\net30\\ref.dll", "lib\\silverlight40\\refsl.dll" });

            var packageB = PackageUtility.CreatePackage(
                "B",
                "2.0",
                new[] { "net30\\contentB.txt", "silverlight40\\content4B.txt" },
                new[] { "lib\\net30\\refB.dll", "lib\\silverlight40\\refslB.dll" });

            sourceRepository.Add(packageA);
            sourceRepository.Add(packageB);

            packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
            packageManager.InstallPackage(projectManager, "B", new SemanticVersion("2.0"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);

            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectSystem.FileExists("content.txt"));
            Assert.False(projectSystem.FileExists("content4.txt"));
            Assert.True(projectSystem.ReferenceExists("ref.dll"));
            Assert.False(projectSystem.ReferenceExists("refsl.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B"));
            Assert.True(projectManager.LocalRepository.Exists("B"));
            Assert.True(projectSystem.FileExists("contentB.txt"));
            Assert.False(projectSystem.FileExists("content4B.txt"));
            Assert.True(projectSystem.ReferenceExists("refB.dll"));
            Assert.False(projectSystem.ReferenceExists("refslB.dll"));

            // now change project's target framework to silverlight
            projectSystem.ChangeTargetFramework(new FrameworkName("Silverlight, Version=v4.0"));

            // Act
            packageManager.ReinstallPackages(projectManager, updateDependencies: true, allowPrereleaseVersions: false, logger: null);

            // Assert
            Assert.True(packageManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.True(projectManager.LocalRepository.Exists("A", new SemanticVersion("1.2-alpha")));
            Assert.False(projectSystem.FileExists("content.txt"));
            Assert.True(projectSystem.FileExists("content4.txt"));
            Assert.False(projectSystem.ReferenceExists("ref.dll"));
            Assert.True(projectSystem.ReferenceExists("refsl.dll"));

            Assert.True(packageManager.LocalRepository.Exists("B"));
            Assert.True(projectManager.LocalRepository.Exists("B"));
            Assert.False(projectSystem.FileExists("contentB.txt"));
            Assert.True(projectSystem.FileExists("content4B.txt"));
            Assert.False(projectSystem.ReferenceExists("refB.dll"));
            Assert.True(projectSystem.ReferenceExists("refslB.dll"));
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:73,代码来源:VsPackageManagerTest.Reinstall.cs

示例12: 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

示例13: TestRecentSwitchWorkCorrectly

        public void TestRecentSwitchWorkCorrectly()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var repository = new MockPackageRepository();
            repository.Add(packageA);
            repository.Add(packageB);
            repository.Add(packageC);

            var cmdlet = BuildCmdlet(false, repository);
            cmdlet.Recent = true;

            // Act
            var packages = cmdlet.GetResults().OfType<IPackage>().ToList();

            // Assert
            Assert.AreEqual(3, packages.Count);
            Assert.AreSame(packageA, packages[0]);
            Assert.AreSame(packageB, packages[1]);
            Assert.AreSame(packageC, packages[2]);
        }
开发者ID:larsw,项目名称:nuget,代码行数:24,代码来源:GetPackageCommandTest.cs

示例14: 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

示例15: CallingEnableCurrentSolutionSetupEverythingCorrectly

        public void CallingEnableCurrentSolutionSetupEverythingCorrectly()
        {
            // Arrange
            string tempSolutionPath = CreateTempFolder();

            // setup SolutionManager
            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.IsSolutionOpen).Returns(true);
            solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath);

            // setup file system
            var fileSystem = new PhysicalFileSystem(tempSolutionPath);
            var fileSystemProvider = new Mock<IFileSystemProvider>();
            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem);

            var nugetFolderFileSystem = new PhysicalFileSystem(tempSolutionPath + "\\.nuget");
            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath + "\\.nuget")).Returns(nugetFolderFileSystem);

            // setup DTE
            var dte = new Mock<DTE>();

            var projectItems = new Mock<ProjectItems>();
            var solutionFolder = new Mock<Project>();
            solutionFolder.Setup(s => s.Name).Returns(".nuget");
            solutionFolder.SetupGet(s => s.ProjectItems).Returns(projectItems.Object);

            var solution = new Mock<Solution>();
            solution.As<Solution2>().Setup(p => p.AddSolutionFolder(".nuget")).Returns(solutionFolder.Object);

            var projects = new MockProjects(new Project[0]);
            solution.As<Solution2>().Setup(s => s.Projects).Returns(projects);
            dte.SetupGet(p => p.Solution).Returns(solution.Object);

            // setup package repository
            var packageRepository = new MockPackageRepository();
            packageRepository.Add(PackageUtility.CreatePackage(
                "NuGet.Build",
                version: "1.0",
                tools: new string[] { "NuGet.targets" },
                dependencies: new PackageDependency[] { new PackageDependency("NuGet.CommandLine") }));
            packageRepository.Add(PackageUtility.CreatePackage(
                "NuGet.CommandLine",
                version: "1.0",
                tools: new string[] { "NuGet.exe" }));
            var packageRepositoryFactory = new Mock<IPackageRepositoryFactory>();
            packageRepositoryFactory.Setup(p => p.CreateRepository(NuGetConstants.DefaultFeedUrl)).Returns(packageRepository);

            var packageRestore = CreateInstance(
                dte.Object,
                solutionManager.Object,
                fileSystemProvider.Object,
                packageRepositoryFactory.Object);

            // Act 
            packageRestore.EnableCurrentSolutionForRestore(quietMode: true);

            // Assert

            // verify that the files are copied to the .nuget sub folder under solution
            Assert.True(Directory.Exists(Path.Combine(tempSolutionPath, ".nuget")));
            Assert.True(File.Exists(Path.Combine(tempSolutionPath, ".nuget\\NuGet.exe")));
            Assert.True(File.Exists(Path.Combine(tempSolutionPath, ".nuget\\NuGet.targets")));

            // verify that solution folder 'nuget' is added to solution
            solution.As<Solution2>().Verify(p => p.AddSolutionFolder(".nuget"));
            projectItems.Verify(p => p.AddFromFile(tempSolutionPath + "\\.nuget\\NuGet.exe"));
            projectItems.Verify(p => p.AddFromFile(tempSolutionPath + "\\.nuget\\NuGet.targets"));

            // verify that the Source Control mode is disabled
            var settings = new Settings(nugetFolderFileSystem);
            Assert.True(settings.IsSourceControlDisabled());

            // clean up
            Directory.Delete(tempSolutionPath, recursive: true);
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:75,代码来源:PackageRestoreManagerTest.cs


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