public async Task TestBuildIntegratedNuGetPackageSpecNameMatchesFilePath()
        {
            // Arrange
            var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("1.0.0"));

            using (var randomTestPackageSourcePath = TestDirectory.Create())
                using (var randomPackagesFolderPath = TestDirectory.Create())
                    using (var randomProjectFolderPath = TestDirectory.Create())
                    {
                        var randomConfig = Path.Combine(randomProjectFolderPath, "project.json");
                        var token        = CancellationToken.None;

                        CreateConfigJson(randomConfig);

                        var projectTargetFramework  = NuGetFramework.Parse("netcore50");
                        var testNuGetProjectContext = new TestNuGetProjectContext();

                        var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(
                            projectTargetFramework,
                            testNuGetProjectContext,
                            randomProjectFolderPath,
                            "msbuildName");

                        var projectFilePath = Path.Combine(randomProjectFolderPath, "fileName.csproj");

                        var buildIntegratedProject = new ProjectJsonBuildIntegratedNuGetProject(randomConfig, projectFilePath, msBuildNuGetProjectSystem);

                        var spec = await buildIntegratedProject.GetPackageSpecsAsync(new DependencyGraphCacheContext());

                        // Assert
                        Assert.Equal(projectFilePath, buildIntegratedProject.MSBuildProjectPath);
                        Assert.Equal("fileName", buildIntegratedProject.ProjectName);
                        Assert.Equal("fileName", spec.Single().Name);
                    }
        }
Exemple #2
0
        public async Task GetPackageSpecsAsync_ProjectHasOneProjectReference_RestoreMetadataHasProjectReference()
        {
            FilePath directory = Util.CreateTmpDir("ProjectJsonNuGetTests");
            string   expectedProjectFileName = directory.Combine("ReferencedProject.csproj");
            var      projectToBeReferenced   = CreateDotNetProject("ReferencedProject", expectedProjectFileName);
            string   mainProjectFileName     = directory.Combine("MainTest.csproj");
            var      mainProject             = CreateDotNetProject("MainTest", mainProjectFileName);

            CreateSolution(mainProject, projectToBeReferenced);
            var projectReference = ProjectReference.CreateProjectReference(projectToBeReferenced);

            mainProject.References.Add(projectReference);
            CreateProjectJsonNuGetProject(mainProject);
            var context = new DependencyGraphCacheContext();

            var specs = await projectJsonNuGetProject.GetPackageSpecsAsync(context);

            var spec            = specs [0];
            var targetFramework = spec.RestoreMetadata.TargetFrameworks.FirstOrDefault();

            Assert.AreEqual(1, specs.Count);
            Assert.AreEqual(1, spec.RestoreMetadata.TargetFrameworks.Count);
            Assert.AreEqual(1, targetFramework.ProjectReferences.Count);
            Assert.AreEqual(expectedProjectFileName, targetFramework.ProjectReferences [0].ProjectPath);
        }
        public async Task BuildIntegratedNuGetProject_GetPackageSpecForRestore_NoReferences()
        {
            // Arrange
            using (var randomProjectFolderPath = TestDirectory.Create())
            {
                var projectJsonPath = Path.Combine(randomProjectFolderPath, "project.json");
                CreateConfigJson(projectJsonPath);

                var projectTargetFramework    = NuGetFramework.Parse("netcore50");
                var testNuGetProjectContext   = new TestNuGetProjectContext();
                var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, testNuGetProjectContext, randomProjectFolderPath);
                var projectFilePath           = Path.Combine(randomProjectFolderPath, $"{msBuildNuGetProjectSystem.ProjectName}.csproj");
                var buildIntegratedProject    = new ProjectJsonBuildIntegratedNuGetProject(projectJsonPath, projectFilePath, msBuildNuGetProjectSystem);

                var referenceContext = new DependencyGraphCacheContext(new TestLogger());

                // Act
                var actual = (await buildIntegratedProject.GetPackageSpecsAsync(referenceContext)).SingleOrDefault();

                // Assert
                Assert.NotNull(actual);
                Assert.Equal(msBuildNuGetProjectSystem.ProjectName, actual.Name);
                Assert.Equal(projectJsonPath, actual.FilePath);
                Assert.NotNull(actual.RestoreMetadata);
                Assert.Equal(ProjectStyle.ProjectJson, actual.RestoreMetadata.ProjectStyle);
                Assert.Equal(projectFilePath, actual.RestoreMetadata.ProjectPath);
                Assert.Equal(msBuildNuGetProjectSystem.ProjectName, actual.RestoreMetadata.ProjectName);
                Assert.Equal(projectFilePath, actual.RestoreMetadata.ProjectUniqueName);
                Assert.Equal(1, actual.TargetFrameworks.Count);
                Assert.Equal(projectTargetFramework, actual.TargetFrameworks[0].FrameworkName);
                Assert.Empty(actual.TargetFrameworks[0].Imports);

                Assert.Empty(actual.Dependencies);
                Assert.Empty(actual.TargetFrameworks[0].Dependencies);
                Assert.Empty(actual.RestoreMetadata.TargetFrameworks.SelectMany(e => e.ProjectReferences));
            }
        }