コード例 #1
0
        public async Task LCPRP_PackageVersion()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var testEnvDTEProjectAdapter = new EnvDTEProjectAdapterMock(randomTestFolder);
                testEnvDTEProjectAdapter
                .Setup(x => x.TargetNuGetFramework)
                .Returns(new NuGetFramework("netstandard13"));
                testEnvDTEProjectAdapter
                .Setup(x => x.Version)
                .Returns("2.2.3");

                var testProject = new LegacyCSProjPackageReferenceProject(
                    project: testEnvDTEProjectAdapter.Object,
                    projectId: "",
                    callerIsUnitTest: true);

                var testDependencyGraphCacheContext = new DependencyGraphCacheContext();

                // Act
                var installedPackages = await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext);

                // Assert
                Assert.Equal(new NuGetVersion("2.2.3"), installedPackages.First().Version);
            }
        }
コード例 #2
0
        private async Task <object> MigrateProjectToPackageRefAsync(string projectUniqueName)
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var project = _solutionManager.Value.GetDTEProject(projectUniqueName);

            if (project == null)
            {
                throw new InvalidOperationException(string.Format(VsResources.Error_ProjectNotInCache, projectUniqueName));
            }

            var projectSafeName = await EnvDTEProjectInfoUtility.GetCustomUniqueNameAsync(project);

            var nuGetProject = _solutionManager.Value.GetNuGetProject(projectSafeName);

            // If the project already has PackageReference, do nothing.
            if (nuGetProject is LegacyCSProjPackageReferenceProject)
            {
                return(new VsProjectJsonToPackageReferenceMigrateResult(success: true, errorMessage: null));
            }

            try
            {
                _solutionManager.Value.SaveProject(nuGetProject);

                var legacyPackageRefBasedProject = new LegacyCSProjPackageReferenceProject(
                    new EnvDTEProjectAdapter(project),
                    VsHierarchyUtility.GetProjectId(project));

                await ProjectJsonToPackageRefMigrator.MigrateAsync(
                    legacyPackageRefBasedProject,
                    legacyPackageRefBasedProject.MSBuildProjectPath);

                var result = new VsProjectJsonToPackageReferenceMigrateResult(success: true, errorMessage: null);
                _solutionManager.Value.SaveProject(nuGetProject);
                await _solutionManager.Value.UpdateNuGetProjectToPackageRef(nuGetProject);

                return(result);
            }
            catch (Exception ex)
            {
                // reload the project in memory from the file on disk, discarding any changes that might have
                // been made as a result of an incomplete migration.
                ReloadProject(project);
                return(new VsProjectJsonToPackageReferenceMigrateResult(success: false, errorMessage: ex.Message));
            }
        }
コード例 #3
0
        public async Task LCPRP_WhenThereIsNoBaseIntermediateOutputPath_ThrowsException()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var testEnvDTEProjectAdapter = new Mock <IEnvDTEProjectAdapter>();

                var testProject = new LegacyCSProjPackageReferenceProject(
                    project: testEnvDTEProjectAdapter.Object,
                    projectId: String.Empty,
                    callerIsUnitTest: true);

                // Act & Assert
                await Assert.ThrowsAsync <InvalidDataException>(
                    () => testProject.GetAssetsFilePathAsync());
            }
        }
コード例 #4
0
        public async Task LCPRP_PackageTargetFallback()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var testEnvDTEProjectAdapter = new EnvDTEProjectAdapterMock(randomTestFolder);
                testEnvDTEProjectAdapter
                .Setup(x => x.PackageTargetFallback)
                .Returns("portable-net45+win8;dnxcore50");
                testEnvDTEProjectAdapter
                .Setup(x => x.TargetNuGetFramework)
                .Returns(new NuGetFramework("netstandard13"));

                var testProject = new LegacyCSProjPackageReferenceProject(
                    project: testEnvDTEProjectAdapter.Object,
                    projectId: "",
                    callerIsUnitTest: true);

                var testDependencyGraphCacheContext = new DependencyGraphCacheContext();

                // Act
                var installedPackages = await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext);

                // Assert
                Assert.Equal(
                    new List <NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+win8"), NuGetFramework.Parse("dnxcore50")
                },
                    installedPackages.First().TargetFrameworks.First().Imports.ToList());
                Assert.IsType(typeof(FallbackFramework), installedPackages.First().TargetFrameworks.First().FrameworkName);
                Assert.Equal(new List <NuGetFramework>()
                {
                    NuGetFramework.Parse("portable-net45+win8"), NuGetFramework.Parse("dnxcore50")
                },
                             ((FallbackFramework)(installedPackages.First().TargetFrameworks.First().FrameworkName)).Fallback);
            }
        }
コード例 #5
0
        public async Task LCPRP_Dependency_PackageVersion()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var testEnvDTEProjectAdapter = new EnvDTEProjectAdapterMock(randomTestFolder);
                testEnvDTEProjectAdapter
                .Setup(x => x.TargetNuGetFramework)
                .Returns(new NuGetFramework("netstandard13"));
                testEnvDTEProjectAdapter
                .Setup(x => x.GetLegacyCSProjPackageReferences(It.IsAny <Array>()))
                .Returns(new LegacyCSProjPackageReference[]
                {
                    new LegacyCSProjPackageReference(
                        name: "packageA",
                        version: "1.*",
                        metadataElements: null,
                        metadataValues: null,
                        targetNuGetFramework: new NuGetFramework("netstandard13"))
                });

                var testProject = new LegacyCSProjPackageReferenceProject(
                    project: testEnvDTEProjectAdapter.Object,
                    projectId: "",
                    callerIsUnitTest: true);

                var testDependencyGraphCacheContext = new DependencyGraphCacheContext();

                // Act
                var packageSpec = await testProject.GetPackageSpecsAsync(testDependencyGraphCacheContext);

                // Assert
                var dependency = packageSpec.First().Dependencies.First();
                Assert.NotNull(dependency);
                Assert.Equal("packageA", dependency.LibraryRange.Name);
                Assert.Equal(VersionRange.Parse("1.*"), dependency.LibraryRange.VersionRange);
            }
        }
コード例 #6
0
        public async Task LCPRP_AssetsFileLocation()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var testBaseIntermediateOutputPath = Path.Combine(randomTestFolder, "obj");
                TestDirectory.Create(testBaseIntermediateOutputPath);
                var testEnvDTEProjectAdapter = new Mock <IEnvDTEProjectAdapter>();
                testEnvDTEProjectAdapter
                .Setup(x => x.BaseIntermediateOutputPath)
                .Returns(testBaseIntermediateOutputPath);

                var testProject = new LegacyCSProjPackageReferenceProject(
                    project: testEnvDTEProjectAdapter.Object,
                    projectId: String.Empty,
                    callerIsUnitTest: true);

                // Act
                var assetsPath = await testProject.GetAssetsFilePathAsync();

                // Assert
                Assert.Equal(Path.Combine(testBaseIntermediateOutputPath, "project.assets.json"), assetsPath);
            }
        }