public async Task GetPackageSpecsAsync_WithProjectReference_Succeeds()
        {
            // Arrange
            using (var randomTestFolder = TestDirectory.Create())
            {
                var framework = NuGetFramework.Parse("netstandard13");

                var projectAdapter = CreateProjectAdapter(randomTestFolder);

                var projectServices = new TestProjectSystemServices();
                projectServices.SetupProjectDependencies(
                    new ProjectRestoreReference
                {
                    ProjectUniqueName = "TestProjectA",
                    ProjectPath       = Path.Combine(randomTestFolder, "TestProjectA")
                });

                var testProject = new LegacyPackageReferenceProject(
                    projectAdapter,
                    Guid.NewGuid().ToString(),
                    projectServices,
                    _threadingService);

                var testDependencyGraphCacheContext = new DependencyGraphCacheContext();

                await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

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

                // Assert
                Assert.NotNull(packageSpecs);

                var actualRestoreSpec = packageSpecs.Single();
                SpecValidationUtility.ValidateProjectSpec(actualRestoreSpec);

                var actualDependency = actualRestoreSpec.RestoreMetadata.TargetFrameworks.Single().ProjectReferences.Single();
                Assert.NotNull(actualDependency);
                Assert.Equal("TestProjectA", actualDependency.ProjectUniqueName);

                // Verify
                Mock.Get(projectServices.ReferencesReader)
                .Verify(
                    x => x.GetProjectReferencesAsync(It.IsAny <Common.ILogger>(), CancellationToken.None),
                    Times.AtLeastOnce);
            }
        }
        public async void DependencyGraphRestoreUtility_LegacyPackageRef_Restore_GenerateLockFile()
        {
            using (var packageSource = TestDirectory.Create())
            {
                // Arrange
                var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(
                    new List <Configuration.PackageSource>()
                {
                    new Configuration.PackageSource(packageSource.Path)
                });

                using (var testSolutionManager = new TestSolutionManager(true))
                    using (var randomProjectFolderPath = TestDirectory.Create())
                    {
                        var testSettings            = PopulateSettingsWithSources(sourceRepositoryProvider, randomProjectFolderPath);
                        var testNuGetProjectContext = new TestNuGetProjectContext();
                        var deleteOnRestartManager  = new TestDeleteOnRestartManager();
                        var nuGetPackageManager     = new NuGetPackageManager(
                            sourceRepositoryProvider,
                            testSettings,
                            testSolutionManager,
                            deleteOnRestartManager);

                        // set up projects
                        var projectTargetFrameworkStr = "net45";
                        var fullProjectPathB          = Path.Combine(randomProjectFolderPath, "ProjectB", "project2.csproj");
                        var projectNamesB             = new ProjectNames(
                            fullName: fullProjectPathB,
                            uniqueName: Path.GetFileName(fullProjectPathB),
                            shortName: Path.GetFileNameWithoutExtension(fullProjectPathB),
                            customUniqueName: Path.GetFileName(fullProjectPathB));
                        var vsProjectAdapterB = new TestVSProjectAdapter(
                            fullProjectPathB,
                            projectNamesB,
                            projectTargetFrameworkStr);

                        var projectServicesB = new TestProjectSystemServices();
                        projectServicesB.SetupInstalledPackages(
                            NuGetFramework.Parse(projectTargetFrameworkStr),
                            new LibraryDependency
                        {
                            LibraryRange = new LibraryRange(
                                "packageB",
                                VersionRange.Parse("1.*"),
                                LibraryDependencyTarget.Package)
                        });

                        var legacyPRProjectB = new LegacyPackageReferenceProject(
                            vsProjectAdapterB,
                            Guid.NewGuid().ToString(),
                            projectServicesB,
                            _threadingService);

                        var projectPathA     = Path.Combine(randomProjectFolderPath, "ProjectA");
                        var fullProjectPathA = Path.Combine(projectPathA, "project1.csproj");
                        var projectNamesA    = new ProjectNames(
                            fullName: fullProjectPathA,
                            uniqueName: Path.GetFileName(fullProjectPathA),
                            shortName: Path.GetFileNameWithoutExtension(fullProjectPathA),
                            customUniqueName: Path.GetFileName(fullProjectPathA));
                        var vsProjectAdapterA = new TestVSProjectAdapter(
                            fullProjectPathA,
                            projectNamesA,
                            projectTargetFrameworkStr,
                            restorePackagesWithLockFile: "true");

                        var projectServicesA = new TestProjectSystemServices();
                        projectServicesA.SetupInstalledPackages(
                            NuGetFramework.Parse(projectTargetFrameworkStr),
                            new LibraryDependency
                        {
                            LibraryRange = new LibraryRange(
                                "packageA",
                                VersionRange.Parse("1.*"),
                                LibraryDependencyTarget.Package)
                        });
                        projectServicesA.SetupProjectDependencies(
                            new ProjectRestoreReference
                        {
                            ProjectUniqueName = fullProjectPathB,
                            ProjectPath       = fullProjectPathB
                        });

                        var legacyPRProjectA = new LegacyPackageReferenceProject(
                            vsProjectAdapterA,
                            Guid.NewGuid().ToString(),
                            projectServicesA,
                            _threadingService);
                        testSolutionManager.NuGetProjects.Add(legacyPRProjectB);
                        testSolutionManager.NuGetProjects.Add(legacyPRProjectA);

                        var testLogger     = new TestLogger();
                        var restoreContext = new DependencyGraphCacheContext(testLogger, testSettings);
                        var providersCache = new RestoreCommandProvidersCache();

                        var packageContextA = new SimpleTestPackageContext("packageA", "1.0.0");
                        packageContextA.AddFile("lib/net45/a.dll");
                        var packageContextB = new SimpleTestPackageContext("packageB", "1.0.0");
                        packageContextB.AddFile("lib/net45/b.dll");
                        var packages = new List <SimpleTestPackageContext>()
                        {
                            packageContextA, packageContextB
                        };
                        SimpleTestPackageUtility.CreateOPCPackages(packages, packageSource);

                        var dgSpec = await DependencyGraphRestoreUtility.GetSolutionRestoreSpec(testSolutionManager, restoreContext);

                        // Act
                        var restoreSummaries = await DependencyGraphRestoreUtility.RestoreAsync(
                            testSolutionManager,
                            dgSpec,
                            restoreContext,
                            providersCache,
                            (c) => { },
                            sourceRepositoryProvider.GetRepositories(),
                            Guid.Empty,
                            false,
                            true,
                            testLogger,
                            CancellationToken.None);

                        // Assert
                        foreach (var restoreSummary in restoreSummaries)
                        {
                            Assert.True(restoreSummary.Success);
                            Assert.False(restoreSummary.NoOpRestore);
                        }

                        Assert.True(File.Exists(Path.Combine(projectPathA, "packages.lock.json")));
                        var lockFile = PackagesLockFileFormat.Read(Path.Combine(projectPathA, "packages.lock.json"));
                        Assert.Equal(1, lockFile.Targets.Count);

                        Assert.Equal(".NETFramework,Version=v4.5", lockFile.Targets[0].Name);
                        Assert.Equal(3, lockFile.Targets[0].Dependencies.Count);
                        Assert.Equal("packageA", lockFile.Targets[0].Dependencies[0].Id);
                        Assert.Equal(PackageDependencyType.Direct, lockFile.Targets[0].Dependencies[0].Type);
                        Assert.Equal("packageB", lockFile.Targets[0].Dependencies[1].Id);
                        Assert.Equal(PackageDependencyType.Transitive, lockFile.Targets[0].Dependencies[1].Type);
                        Assert.Equal("project2", lockFile.Targets[0].Dependencies[2].Id);
                        Assert.Equal(PackageDependencyType.Project, lockFile.Targets[0].Dependencies[2].Type);
                    }
            }
        }