• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# PackageReferenceRepository类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中PackageReferenceRepository的典型用法代码示例。如果您正苦于以下问题:C# PackageReferenceRepository类的具体用法?C# PackageReferenceRepository怎么用?C# PackageReferenceRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PackageReferenceRepository类属于命名空间,在下文中一共展示了PackageReferenceRepository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetPackagesNoPackagesConfigReturnsEmptyList

        public void GetPackagesNoPackagesConfigReturnsEmptyList()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A");
            repository.Object.AddPackage(packageA);
            var fileSystem = new MockFileSystem();
            var referenceRepository = new PackageReferenceRepository(fileSystem, repository.Object);

            // Act
            var packages = referenceRepository.GetPackages().ToList();

            // Assert
            Assert.AreEqual(0, packages.Count);
        }
开发者ID:grendello,项目名称:nuget,代码行数:15,代码来源:PackageReferenceRepositoryTest.cs


示例2: RegisterIfNecessaryDoesNotRegistersWithSharedRepositoryIfRepositoryDoesNotContainsPackages

        public void RegisterIfNecessaryDoesNotRegistersWithSharedRepositoryIfRepositoryDoesNotContainsPackages()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>();
            string path = null;
            sharedRepository.Setup(m => m.RegisterRepository(It.IsAny<string>()))
                            .Callback<string>(p => path = p);
            var fileSystem = new MockFileSystem();

            // Act
            var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
            referenceRepository.RegisterIfNecessary();

            // Assert
            Assert.Null(path);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:16,代码来源:PackageReferenceRepositoryTest.cs


示例3: RegisterIfNecessaryRegistersWithSharedRepositoryIfRepositoryContainsPackages

        public void RegisterIfNecessaryRegistersWithSharedRepositoryIfRepositoryContainsPackages()
        {
            // Arrange
            var sharedRepository = new Mock<MockPackageRepository>().As<ISharedPackageRepository>();
            string path = null;
            sharedRepository.Setup(m => m.RegisterRepository(It.IsAny<string>()))
                            .Callback<string>(p => path = p);
            var fileSystem = new MockFileSystem();
            IPackage package = PackageUtility.CreatePackage("A");
            sharedRepository.Object.AddPackage(package);

            // Act
            var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
            referenceRepository.AddPackage(package);
            referenceRepository.RegisterIfNecessary();

            // Assert
            Assert.Equal(@"C:\MockFileSystem\packages.config", path);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:19,代码来源:PackageReferenceRepositoryTest.cs


示例4: GetProjectManager

        public override IProjectManager GetProjectManager(Project project)
        {
            IProjectManager projectManager;
            if (_projectManagers.TryGetValue(project, out projectManager))
            {
                return projectManager;
            }

            var projectSystem = new MockVsProjectSystem(project);
            var localRepository = new PackageReferenceRepository(
                new MockFileSystem(project.GetFullPath()),
                project.Name,
                LocalRepository);
            projectManager = new ProjectManager(
                this,
                PathResolver, 
                projectSystem,
                localRepository);
            _projectManagers[project] = projectManager;
            return projectManager;
        }
开发者ID:rikoe,项目名称:nuget,代码行数:21,代码来源:MockVsPackageManager.cs


示例5: AddPackageAddsEntryToPackagesConfigWithTargetFramework

        public void AddPackageAddsEntryToPackagesConfigWithTargetFramework()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>();
            string path = null;
            sharedRepository.Setup(m => m.RegisterRepository(It.IsAny<string>()))
                            .Callback<string>(p => path = p);
            var fileSystem = new MockFileSystem();
            var referenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: sharedRepository.Object);
            //var package = PackageUtility.CreatePackage("A");

            // Act
            referenceRepository.AddPackage("A", new SemanticVersion("1.0"), false, new FrameworkName("Silverlight, Version=2.0"));

            // Assert
            Assert.Equal(@"C:\MockFileSystem\packages.config", path);
            Assert.True(fileSystem.FileExists("packages.config"));
            AssertConfig(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" targetFramework=""sl20"" />
</packages>", fileSystem.ReadAllText("packages.config"));
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:22,代码来源:PackageReferenceRepositoryTest.cs


示例6: AddPackageAddsEntryToPackagesConfig

        public void AddPackageAddsEntryToPackagesConfig()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>();
            string path = null;
            sharedRepository.Setup(m => m.RegisterRepository(It.IsAny<string>()))
                            .Callback<string>(p => path = p);
            var fileSystem = new MockFileSystem();
            var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
            var package = PackageUtility.CreatePackage("A");

            // Act
            referenceRepository.AddPackage(package);

            // Assert
            Assert.Equal(@"C:\MockFileSystem\packages.config", path);
            Assert.True(fileSystem.FileExists("packages.config"));
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
</packages>", fileSystem.ReadAllText("packages.config"));
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:22,代码来源:PackageReferenceRepositoryTest.cs


示例7: AddPackageDoesNotAddEntryToPackagesConfigIfExists

        public void AddPackageDoesNotAddEntryToPackagesConfigIfExists()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>();
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
            var package = PackageUtility.CreatePackage("A");

            // Act
            referenceRepository.AddPackage(package);

            // Assert
            Assert.True(fileSystem.FileExists("packages.config"));
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
</packages>", fileSystem.ReadAllText("packages.config"));
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:22,代码来源:PackageReferenceRepositoryTest.cs


示例8: CreateProjectManager

        private IProjectManager CreateProjectManager(Project project)
        {
            // Create the project system
            IProjectSystem projectSystem = VsProjectSystemFactory.CreateProjectSystem(project, _fileSystemProvider);

            var repository = new PackageReferenceRepository(projectSystem, _sharedRepository);

            // Ensure the logger is null while registering the repository
            FileSystem.Logger = null;
            Logger = null;

            // Ensure that this repository is registered with the shared repository if it needs to be
            repository.RegisterIfNecessary();

            // The source repository of the project is an aggregate since it might need to look for all
            // available packages to perform updates on dependent packages
            var sourceRepository = CreateProjectManagerSourceRepository();

            var projectManager = new ProjectManager(sourceRepository, PathResolver, projectSystem, repository);

            // The package reference repository also provides constraints for packages (via the allowedVersions attribute)
            projectManager.ConstraintProvider = repository;
            return projectManager;
        }
开发者ID:nickfloyd,项目名称:NuGet,代码行数:24,代码来源:VSPackageManager.cs


示例9: PackageReferenceRepositoryDoNotFindLatestPackageIfItDoesNotExist

        public void PackageReferenceRepositoryDoNotFindLatestPackageIfItDoesNotExist()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("A", "1.5");
            var packageD = PackageUtility.CreatePackage("A", "2.0-beta");
            repository.Object.AddPackage(packageA);
            repository.Object.AddPackage(packageB);
            repository.Object.AddPackage(packageC);
            repository.Object.AddPackage(packageD);

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
  <package id=""B"" version=""2.0"" />
  <package id=""A"" version=""1.5"" />
  <package id=""A"" version=""2.0-beta"" />
</packages>");

            ILatestPackageLookup referenceRepository = new PackageReferenceRepository(
                fileSystem,
                repository.Object);

            // Act
            SemanticVersion latestVersion;
            bool result = referenceRepository.TryFindLatestPackageById("C", out latestVersion);

            // Assert
            Assert.False(result);
            Assert.Null(latestVersion);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:34,代码来源:PackageReferenceRepositoryTest.cs


示例10: GetPackageReferencesReturnsFalseForNonExistentId

        public void GetPackageReferencesReturnsFalseForNonExistentId()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <packages>
          <package id=""A"" version=""1.3.4"" />
          <package id=""A"" version=""2.5-beta"" />
          <package id=""B"" version=""1.0"" />
          <package id=""C"" version=""2.1.4"" />
        </packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var sharedRepository = new Mock<MockPackageRepository>().As<ISharedPackageRepository>();
            var packageReferenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);

            // Act
            SemanticVersion version;
            bool result = packageReferenceRepository.TryFindLatestPackageById("does-not-exist", out version);

            // Assert
            Assert.False(result);
            Assert.Null(version);
        }
开发者ID:anurse,项目名称:NuGet,代码行数:23,代码来源:PackageReferenceRepositoryTest.cs


示例11: ReinstallPackagesSkipReinstallingForPackagesThatDoNotExistInSource

        public void ReinstallPackagesSkipReinstallingForPackagesThatDoNotExistInSource()
        {
            // 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 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-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" });

            localRepository.AddPackage(packageA);
            localRepository.AddPackage(packageB);
            projectManager.LocalRepository.AddPackage(packageA);
            projectManager.LocalRepository.AddPackage(packageB);

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

            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.",
                "B 2.0",
                "x:\\MockFileSystem")
            ).Verifiable();

            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-alpha",
                "x:\\MockFileSystem")
            ).Verifiable();

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

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

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

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


示例12: MockPackageRepository

        public void ReinstallPackagesDoesNotThrowWithNewDependencyWhenProjectFrameworkChangesIfAllowPrereleaseParameterIsFalseAndPackageVersionIsPrerelease()
        {
            // Arrange
            var localRepository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>().Object;
            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETFramework, Version=v4.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.CreatePackageWithDependencySets(
                "A",
                "1.2-alpha",
                new[] { "contentA.txt" },
                dependencySets: new PackageDependencySet[] {
                    new PackageDependencySet(new FrameworkName(".NETFramework, Version=v4.0"),
                                             new [] { new PackageDependency("B")}),
                    new PackageDependencySet(new FrameworkName("Silverlight, Version=v5.0"),
                                             new [] { new PackageDependency("C")})
                });

            var packageB = PackageUtility.CreatePackage(
                "B",
                "1.0",
                new[] { "contentB.txt" });

            var packageC = PackageUtility.CreatePackage(
                "C",
                "2.0-beta",
                new[] { "contentC.txt" });

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

            packageManager.InstallPackage(projectManager, "A", new SemanticVersion("1.2-alpha"), ignoreDependencies: false, allowPrereleaseVersions: true, logger: null);
            Assert.True(packageManager.LocalRepository.Exists("A"));
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.True(packageManager.LocalRepository.Exists("B"));
            Assert.True(projectManager.LocalRepository.Exists("B"));
            Assert.False(packageManager.LocalRepository.Exists("C"));
            Assert.False(projectManager.LocalRepository.Exists("C"));
            Assert.True(projectSystem.FileExists("contentA.txt"));
            Assert.True(projectSystem.FileExists("contentB.txt"));
            Assert.False(projectSystem.FileExists("contentC.txt"));

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

            // Act
            packageManager.ReinstallPackage(projectManager, "A", updateDependencies: true, allowPrereleaseVersions: false, logger: null);
            
            // Assert
            Assert.True(packageManager.LocalRepository.Exists("A"));
            Assert.True(projectManager.LocalRepository.Exists("A"));
            Assert.False(packageManager.LocalRepository.Exists("B"));
            Assert.False(projectManager.LocalRepository.Exists("B"));
            Assert.True(packageManager.LocalRepository.Exists("C"));
            Assert.True(projectManager.LocalRepository.Exists("C"));
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:70,代码来源:VsPackageManagerTest.Reinstall.cs


示例13: CallingRestoreMissingPackagesMethodInstallMissingPackages

        public void CallingRestoreMissingPackagesMethodInstallMissingPackages()
        {
            // Scenario:
            // Project's packages.config specifies: A[1.0]
            // The solution's packages folder contains only A[1.0], B[1.2-alpha], C[2.0-RC1]
            // Call RestoreMissingPackages() will install B[1.2-alpha] and C[2.0-RC1] into the solution

            // Arrange
            string tempSolutionPath = "x:\\project1";

            var project = new Mock<Project>();

            // setup SolutionManager
            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.IsSolutionOpen).Returns(true);
            solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath);
            solutionManager.Setup(p => p.GetProjects()).Returns(new[] { project.Object });

            // setup file system
            var fileSystem = new Mock<IFileSystem>();
            fileSystem.Setup(p => p.DirectoryExists(".nuget")).Returns(true);
            fileSystem.Setup(p => p.FileExists(".nuget\\NuGet.exe")).Returns(true);
            fileSystem.Setup(p => p.FileExists(".nuget\\NuGet.targets")).Returns(true);

            var fileSystemProvider = new Mock<IFileSystemProvider>();
            fileSystemProvider.Setup(p => p.GetFileSystem(tempSolutionPath)).Returns(fileSystem.Object);

            // setup VsPackageManager
            string tempFile = @"<?xml version=""1.0"" encoding=""utf-8""?>
                <packages>
                    <package id=""A"" version=""1.0.0.0"" />
                    <package id=""B"" version=""1.2-alpha"" />
                    <package id=""C"" version=""2.0-RC1"" />
                </packages>";

            var projectFileSystem = new MockFileSystem();
            projectFileSystem.AddFile("packages.config", tempFile);

            var packageReferenceRepository = new PackageReferenceRepository(projectFileSystem, new Mock<ISharedPackageRepository>().Object);
            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.LocalRepository).Returns(packageReferenceRepository);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(PackageUtility.CreatePackage("A", "1.0"));

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.GetProjectManager(project.Object)).Returns(projectManager.Object);
            packageManager.Setup(p => p.LocalRepository).Returns(localRepository);

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(p => p.CreatePackageManager()).Returns(packageManager.Object);

            var packageRestore = CreateInstance(
                fileSystemProvider: fileSystemProvider.Object,
                solutionManager: solutionManager.Object,
                packageManagerFactory: packageManagerFactory.Object);

            Exception exception = null;
            var manualEvent = new ManualResetEventSlim();

            // Act
            packageRestore.RestoreMissingPackages().ContinueWith(
                task => 
                {
                    if (task.IsFaulted)
                    {
                        exception = task.Exception;
                        manualEvent.Set();
                        return;
                    }

                    try
                    {
                        // Assert
                        packageManager.Verify(p => p.InstallPackage("A", new SemanticVersion("1.0.0.0"), true, true), Times.Never());
                        packageManager.Verify(p => p.InstallPackage("B", new SemanticVersion("1.2-alpha"), true, true), Times.Once());
                        packageManager.Verify(p => p.InstallPackage("C", new SemanticVersion("2.0-RC1"), true, true), Times.Once());
                    }
                    catch (Exception testException)
                    {
                        exception = testException;
                    }
                    finally
                    {
                        manualEvent.Set();
                    }
                });

            manualEvent.Wait();

            Assert.Null(exception);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:92,代码来源:PackageRestoreManagerTest.cs


示例14: GetConstraintThrowsIfConstrainInvalid

        public void GetConstraintThrowsIfConstrainInvalid()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A");
            repository.Object.AddPackage(packageA);
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" allowedVersions=""[-1.3, 3)"" />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, repository.Object);


            // Act & Assert
            ExceptionAssert.Throws<InvalidDataException>(() => referenceRepository.GetConstraint("A"), "Unable to parse version value '[-1.3, 3)' from 'packages.config'.");
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:17,代码来源:PackageReferenceRepositoryTest.cs


示例15: GetConstraintReturnsConstraintListedForPackageIdInPackagesConfig

        public void GetConstraintReturnsConstraintListedForPackageIdInPackagesConfig()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A");
            repository.Object.AddPackage(packageA);
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" allowedVersions=""[1.0, 3.0)"" />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, repository.Object);


            // Act
            IVersionSpec constraint = referenceRepository.GetConstraint("A");

            // Assert
            Assert.NotNull(constraint);
            Assert.True(constraint.IsMinInclusive);
            Assert.False(constraint.IsMaxInclusive);
            Assert.Equal(new SemanticVersion("1.0"), constraint.MinVersion);
            Assert.Equal(new SemanticVersion("3.0"), constraint.MaxVersion);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:24,代码来源:PackageReferenceRepositoryTest.cs


示例16: RemovePackageRemovesEntryFromPackagesConfigDeletesFileAndUnregistersRepositoryIfLastEntry

        public void RemovePackageRemovesEntryFromPackagesConfigDeletesFileAndUnregistersRepositoryIfLastEntry()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>();
            string path = null;
            sharedRepository.Setup(m => m.UnregisterRepository(It.IsAny<string>()))
                            .Callback<string>(p => path = p);
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
            var package = PackageUtility.CreatePackage("A");

            // Act
            referenceRepository.RemovePackage(package);

            // Assert
            Assert.False(fileSystem.FileExists("packages.config"));
            Assert.NotNull(path);
            Assert.Equal(@"C:\MockFileSystem\packages.config", path);
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:23,代码来源:PackageReferenceRepositoryTest.cs


示例17: RemovingAndAddingPackageReferenceWithSameIdPreservesConstraint

        public void RemovingAndAddingPackageReferenceWithSameIdPreservesConstraint()
        {
            // Arrange
            var sharedRepository = new Mock<ISharedPackageRepository>();
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" allowedVersions=""[1.0, 5.0)"" />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);
            var A10 = PackageUtility.CreatePackage("A");
            var A20 = PackageUtility.CreatePackage("A", "2.0");

            // Act
            referenceRepository.RemovePackage(A10);
            referenceRepository.AddPackage(A20);

            // Assert
            Assert.True(fileSystem.FileExists("packages.config"));
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""2.0"" allowedVersions=""[1.0, 5.0)"" />
</packages>", fileSystem.ReadAllText("packages.config"));
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:24,代码来源:PackageReferenceRepositoryTest.cs


示例18: UpdatePackages

        private void UpdatePackages(string packagesConfigPath, IMSBuildProjectSystem project = null, string repositoryPath = null, IPackageRepository sourceRepository = null)
        {
            // Get the msbuild project
            project = project ?? GetMSBuildProject(packagesConfigPath);

            // Resolve the repository path
            repositoryPath = repositoryPath ?? GetReposioryPath(project.Root);

            var pathResolver = new DefaultPackagePathResolver(repositoryPath);

            // Create the local and source repositories
            var localRepository = new PackageReferenceRepository(project, new SharedPackageRepository(repositoryPath));
            sourceRepository = sourceRepository ?? AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            IPackageConstraintProvider constraintProvider = localRepository;

            Console.WriteLine(NuGetResources.UpdatingProject, project.ProjectName);
            UpdatePackages(localRepository, sourceRepository, constraintProvider, pathResolver, project);
            project.Save();
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:19,代码来源:UpdateCommand.cs


示例19: MockFileSystem

        public void CallingCheckForMissingPackagesRaisesThePackagesMissingStatusChangedEventWithTrueValueIfPackagesFolderIsMissing()
        {
            // Scenario:
            // Project's packages.config specifies: A[1.0]
            // The solution's packages folder doesn't contain any packages

            // Arrange
            string tempSolutionPath = "x:\\project1";

            var project = new Mock<Project>();

            // setup SolutionManager
            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.IsSolutionOpen).Returns(true);
            solutionManager.Setup(p => p.SolutionDirectory).Returns(tempSolutionPath);
            solutionManager.Setup(p => p.GetProjects()).Returns(new[] { project.Object });

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

            // setup VsPackageManager
            var projectFileSystem = new MockFileSystem();
            projectFileSystem.AddFile("packages.config", 
                @"<?xml version=""1.0"" encoding=""utf-8""?>
                <packages>
                    <package id=""A"" version=""1.0.0.0"" />
                </packages>");

            var packageReferenceRepository = new PackageReferenceRepository(projectFileSystem, projectName: null, sourceRepository: new Mock<ISharedPackageRepository>().Object);
            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.LocalRepository).Returns(packageReferenceRepository);

            var localRepository = new MockSharedPackageRepository();

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.GetProjectManager(project.Object)).Returns(projectManager.Object);
            packageManager.Setup(p => p.LocalRepository).Returns(localRepository);

            var packageManagerFactory = new Mock<IVsPackageManagerFactory>();
            packageManagerFactory.Setup(p => p.CreatePackageManager()).Returns(packageManager.Object);

            var packageRestore = CreateInstance(
                fileSystemProvider: fileSystemProvider.Object,
                solutionManager: solutionManager.Object,
                packageManagerFactory: packageManagerFactory.Object);

            bool? packagesMissing = null;
            packageRestore.PackagesMissingStatusChanged += (o, e) =>
            {
                packagesMissing = e.PackagesMissing;
            };

            // Act
            packageRestore.CheckForMissingPackages();

            // Assert
            Assert.Equal(true, packagesMissing);
        }
开发者ID:rikoe,项目名称:nuget,代码行数:60,代码来源:PackageRestoreManagerTest.cs


示例20: GetPackagesReturnsOnlyValidPackagesFromSourceRepositoryListedInPackagesConfig

        public void GetPackagesReturnsOnlyValidPackagesFromSourceRepositoryListedInPackagesConfig()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A");
            repository.Object.AddPackage(packageA);
            var packageC = PackageUtility.CreatePackage("C", "2.0");
            repository.Object.AddPackage(packageC);
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""C"" version=""2.0"" />
  <package id=""B"" version=""1.0"" />
  <package id=""A"" version=""1.0"" />
  <package id="""" version=""1.0"" />
  <package id=""G"" version="""" />
  <package />
</packages>");
            var referenceRepository = new PackageReferenceRepository(fileSystem, repository.Object);


            // Act
            var packages = referenceRepository.GetPackages().ToList();

            // Assert
            Assert.Equal(2, packages.Count);
            Assert.Same(packageC, packages[0]);
            Assert.Same(packageA, packages[1]);
            Assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""C"" version=""2.0"" />
  <package id=""B"" version=""1.0"" />
  <package id=""A"" version=""1.0"" />
  <package id="""" version=""1.0"" />
  <package id=""G"" version="""" />
  <package />
</packages>", fileSystem.ReadAllText("packages.config"));
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:38,代码来源:PackageReferenceRepositoryTest.cs



注:本文中的PackageReferenceRepository类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PackageSource类代码示例发布时间:2022-05-24
下一篇:
C# PackageReferenceFile类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap