コード例 #1
0
        private async Task CreateFeeds(string rootV2, string rootV3, string rootUnzip, string rootPackagesConfig, params PackageIdentity[] packages)
        {
            foreach (var package in packages)
            {
                SimpleTestPackageUtility.CreateFolderFeedV2(rootV2, package);
                await SimpleTestPackageUtility.CreateFolderFeedV3(rootV3, package);

                SimpleTestPackageUtility.CreateFolderFeedUnzip(rootUnzip, package);
                await SimpleTestPackageUtility.CreateFolderFeedPackagesConfigAsync(rootPackagesConfig, package);
            }
        }
コード例 #2
0
        public async Task CreatePathContextAsync_FromPackagesConfig()
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var userPackageFolder = Path.Combine(testDirectory.Path, "packagesA");
                Directory.CreateDirectory(userPackageFolder);

                await SimpleTestPackageUtility.CreateFolderFeedPackagesConfigAsync(
                    userPackageFolder,
                    new PackageIdentity("Foo", NuGetVersion.Parse("1.0.1")));

                var settings = Mock.Of <ISettings>();
                Mock.Get(settings)
                .Setup(x => x.GetSection("config"))
                .Returns(() => new VirtualSettingSection("config",
                                                         new AddItem("globalPackagesFolder", userPackageFolder),
                                                         new AddItem("repositoryPath", userPackageFolder)));

                var target = new VsPathContextProvider(
                    settings,
                    Mock.Of <IVsSolutionManager>(),
                    Mock.Of <ILogger>(),
                    getLockFileOrNullAsync: null,
                    _telemetryProvider.Object);

                var project = new Mock <MSBuildNuGetProject>(
                    Mock.Of <IMSBuildProjectSystem>(), userPackageFolder, testDirectory.Path);

                project
                .Setup(x => x.GetInstalledPackagesAsync(It.IsAny <CancellationToken>()))
                .ReturnsAsync(new[]
                {
                    new PackageReference(
                        new PackageIdentity("Foo", NuGetVersion.Parse("1.0.1")),
                        NuGetFramework.AnyFramework)
                });

                // Act
                var actual = await target.CreatePathContextAsync(project.Object, CancellationToken.None);

                // Assert
                Assert.NotNull(actual);
                Assert.Equal(userPackageFolder, actual.UserPackageFolder);

                string actualPackageDirectory = null;

                var packageRootA = Path.Combine(userPackageFolder, "Foo.1.0.1");
                var assetFileA   = Path.Combine(packageRootA, "lib", "net45", "a.dll");
                Assert.True(actual.TryResolvePackageAsset(assetFileA, out actualPackageDirectory));
                Assert.Equal(packageRootA, actualPackageDirectory, ignoreCase: true);
            }
        }
コード例 #3
0
        public async Task CreatePathContextAsync_FromPackagesConfig()
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var userPackageFolder = Path.Combine(testDirectory.Path, "packagesA");
                Directory.CreateDirectory(userPackageFolder);

                await SimpleTestPackageUtility.CreateFolderFeedPackagesConfigAsync(
                    userPackageFolder,
                    new PackageIdentity("Foo", NuGetVersion.Parse("1.0.1")));

                var solutionManager = new Mock <IVsSolutionManager>();
                solutionManager
                .Setup(x => x.SolutionDirectory)
                .Returns(testDirectory.Path);

                var settings = Mock.Of <ISettings>();
                Mock.Get(settings)
                .Setup(x => x.GetValue("config", "globalPackagesFolder", true))
                .Returns(() => userPackageFolder);
                Mock.Get(settings)
                .Setup(x => x.GetValue("config", "repositoryPath", true))
                .Returns(() => userPackageFolder);

                var pacakgesConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
                                <packages>
                                    <package id=""Foo"" version=""1.0.1"" targetFramework=""net45"" />
                                </packages>";

                var project1 = new DirectoryInfo(Path.Combine(testDirectory, "project1"));
                project1.Create();
                var projectFullPath = Path.Combine(project1.FullName, "project1.csproj");
                File.WriteAllText(Path.Combine(project1.FullName, "packages.config"), pacakgesConfig);

                var projectUniqueName = Guid.NewGuid().ToString();
                var project           = new Mock <EnvDTE.Project>();
                var vsProjectAdapter  = new Mock <IVsProjectAdapter>();
                vsProjectAdapter
                .Setup(x => x.FullProjectPath)
                .Returns(projectFullPath);
                vsProjectAdapter
                .Setup(x => x.ProjectDirectory)
                .Returns(project1.FullName);
                vsProjectAdapter
                .Setup(x => x.BuildProperties.GetPropertyValueAsync("ProjectAssetsFile"))
                .Returns(Task.FromResult(string.Empty));
                vsProjectAdapter
                .Setup(x => x.GetTargetFrameworkAsync())
                .Returns(Task.FromResult(NuGetFramework.AnyFramework));

                var vsProjectAdapterProvider = new Mock <IVsProjectAdapterProvider>();
                vsProjectAdapterProvider
                .Setup(x => x.CreateAdapterForFullyLoadedProjectAsync(project.Object))
                .Returns(Task.FromResult(vsProjectAdapter.Object));

                var target = new VsPathContextProvider(
                    settings,
                    solutionManager.Object,
                    Mock.Of <ILogger>(),
                    vsProjectAdapterProvider.Object,
                    getLockFileOrNull: null);

                // Act
                var actual = await target.CreatePathContextAsync(project.Object, projectUniqueName, CancellationToken.None);

                // Assert
                Assert.NotNull(actual);
                Assert.Equal(userPackageFolder, actual.UserPackageFolder);

                string actualPackageDirectory = null;

                var packageRootA = Path.Combine(userPackageFolder, "Foo.1.0.1");
                var assetFileA   = Path.Combine(packageRootA, "lib", "net45", "a.dll");
                Assert.True(actual.TryResolvePackageAsset(assetFileA, out actualPackageDirectory));
                Assert.Equal(packageRootA, actualPackageDirectory, ignoreCase: true);
            }
        }
コード例 #4
0
        public async Task EnumeratePackagesAsync_ForPackagesConfig_ReturnsOrderedItems()
        {
            var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();

            using (var testDirectory = TestDirectory.Create())
            {
                var testSettings = PopulateSettingsWithSources(sourceRepositoryProvider, testDirectory);

                var solutionDirectory = Path.Combine(testDirectory.Path, "solutionA");
                Directory.CreateDirectory(solutionDirectory);
                var testSolutionManager = new TestSolutionManager(solutionDirectory);

                var userPackageFolder = Path.Combine(testDirectory.Path, "packagesA");
                Directory.CreateDirectory(userPackageFolder);

                testSettings.SetValue("config", "repositoryPath", userPackageFolder);

                var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(
                    solutionDirectory, testSettings);

                var packageBar = new SimpleTestPackageContext
                {
                    Id      = "Bar",
                    Version = "1.0.2"
                };

                var packageFoo = new SimpleTestPackageContext
                {
                    Id           = "Foo",
                    Version      = "1.0.1",
                    Dependencies = new List <SimpleTestPackageContext> {
                        packageBar
                    }
                };

                await SimpleTestPackageUtility.CreateFolderFeedPackagesConfigAsync(
                    packagesFolderPath,
                    packageFoo,
                    packageBar);

                var target = new InstalledPackageEnumerator(
                    testSolutionManager,
                    testSettings,
                    getLockFileOrNullAsync: _ => Task.FromResult <LockFile>(null));

                var projectSystem = Mock.Of <IMSBuildProjectSystem>();
                Mock.Get(projectSystem)
                .SetupGet(x => x.TargetFramework)
                .Returns(NuGetFramework.Parse("net45"));

                var project = new Mock <MSBuildNuGetProject>(
                    projectSystem, packagesFolderPath, testDirectory.Path);

                project
                .Setup(x => x.GetInstalledPackagesAsync(It.IsAny <CancellationToken>()))
                .ReturnsAsync(new[]
                {
                    new PackageReference(
                        new PackageIdentity("Foo", NuGetVersion.Parse("1.0.1")),
                        NuGetFramework.Parse("net45")),
                    new PackageReference(
                        new PackageIdentity("Bar", NuGetVersion.Parse("1.0.2")),
                        NuGetFramework.Parse("net45"))
                })
                .Verifiable();

                testSolutionManager.NuGetProjects.Add(project.Object);

                var testPackageManager = new NuGetPackageManager(
                    sourceRepositoryProvider,
                    testSettings,
                    packagesFolderPath);

                // Act
                var installedPackages = await target.EnumeratePackagesAsync(
                    testPackageManager,
                    CancellationToken.None);

                // Assert: Order is important!
                installedPackages.Should().Equal(
                    new PackageItem(
                        new PackageIdentity("Bar", NuGetVersion.Parse("1.0.2")),
                        Path.Combine(packagesFolderPath, "Bar.1.0.2")),
                    new PackageItem(
                        new PackageIdentity("Foo", NuGetVersion.Parse("1.0.1")),
                        Path.Combine(packagesFolderPath, "Foo.1.0.1")));

                project.Verify();
            }
        }