public void GetProjectRestoreMetadataFrameworkInfos_WhenProjectReferenceSpecified_CorrectTargetFrameworkDetected()
        {
            using (var testDirectory = TestDirectory.Create())
            {
                var projectA = new MockMSBuildProject(Path.Combine(testDirectory, "ProjectA", "ProjectA.csproj"));
                var projectB = new MockMSBuildProject(Path.Combine(testDirectory, "ProjectB", "ProjectB.csproj"));

                var projects = new Dictionary <NuGetFramework, IMSBuildProject>
                {
                    [FrameworkConstants.CommonFrameworks.Net45] = new MockMSBuildProject(testDirectory)
                    {
                        Items = new Dictionary <string, IList <IMSBuildItem> >
                        {
                            ["ProjectReference"] = new List <IMSBuildItem>
                            {
                                new MSBuildItem(@"ProjectA\ProjectA.csproj", new Dictionary <string, string> {
                                    ["FullPath"] = projectA.FullPath
                                }),
                                new MSBuildItem(@"ProjectB\ProjectB.csproj", new Dictionary <string, string> {
                                    ["FullPath"] = projectB.FullPath
                                }),
                            }
                        }
                    },
                    [FrameworkConstants.CommonFrameworks.NetStandard20] = new MockMSBuildProject(testDirectory)
                    {
                        Items = new Dictionary <string, IList <IMSBuildItem> >
                        {
                            ["ProjectReference"] = new List <IMSBuildItem>
                            {
                                new MSBuildItem(@"ProjectA\ProjectA.csproj", new Dictionary <string, string> {
                                    ["FullPath"] = projectA.FullPath
                                }),
                            }
                        }
                    }
                };

                var actual = MSBuildStaticGraphRestore.GetProjectRestoreMetadataFrameworkInfos(projects);

                actual.ShouldBeEquivalentTo(new[]
                {
                    new ProjectRestoreMetadataFrameworkInfo(FrameworkConstants.CommonFrameworks.Net45)
                    {
                        ProjectReferences = new List <ProjectRestoreReference>
                        {
                            new ProjectRestoreReference
                            {
                                ProjectPath       = projectA.FullPath,
                                ProjectUniqueName = projectA.FullPath
                            },
                            new ProjectRestoreReference
                            {
                                ProjectPath       = projectB.FullPath,
                                ProjectUniqueName = projectB.FullPath
                            }
                        }
                    },
                    new ProjectRestoreMetadataFrameworkInfo(FrameworkConstants.CommonFrameworks.NetStandard20)
                    {
                        ProjectReferences = new List <ProjectRestoreReference>
                        {
                            new ProjectRestoreReference
                            {
                                ProjectPath       = projectA.FullPath,
                                ProjectUniqueName = projectA.FullPath
                            }
                        }
                    }
                });
            }
        }
        public void GetProjectRestoreMetadataFrameworkInfos_WhenProjectReferenceSpecified_UsesFrameworkFromTargetFrameworkInformation()
        {
            using (var testDirectory = TestDirectory.Create())
            {
                var projectA           = new MockMSBuildProject(Path.Combine(testDirectory, "ProjectA", "ProjectA.csproj"));
                var projectB           = new MockMSBuildProject(Path.Combine(testDirectory, "ProjectB", "ProjectB.csproj"));
                var net45Alias         = "net45";
                var netstandard20Alias = "netstandard2.0";

                var projects = new Dictionary <string, IMSBuildProject>
                {
                    [net45Alias] = new MockMSBuildProject(testDirectory)
                    {
                        Items = new Dictionary <string, IList <IMSBuildItem> >
                        {
                            ["ProjectReference"] = new List <IMSBuildItem>
                            {
                                new MSBuildItem(@"ProjectA\ProjectA.csproj", new Dictionary <string, string> {
                                    ["FullPath"] = projectA.FullPath
                                }),
                                new MSBuildItem(@"ProjectB\ProjectB.csproj", new Dictionary <string, string> {
                                    ["FullPath"] = projectB.FullPath
                                }),
                            }
                        }
                    },
                    [netstandard20Alias] = new MockMSBuildProject(testDirectory)
                    {
                        Items = new Dictionary <string, IList <IMSBuildItem> >
                        {
                            ["ProjectReference"] = new List <IMSBuildItem>
                            {
                                new MSBuildItem(@"ProjectA\ProjectA.csproj", new Dictionary <string, string> {
                                    ["FullPath"] = projectA.FullPath
                                }),
                            }
                        }
                    }
                };

                var targetFrameworkInfos = new List <TargetFrameworkInformation>();
                targetFrameworkInfos.Add(new TargetFrameworkInformation {
                    TargetAlias = net45Alias, FrameworkName = FrameworkConstants.CommonFrameworks.Net45
                });
                targetFrameworkInfos.Add(new TargetFrameworkInformation {
                    TargetAlias = netstandard20Alias, FrameworkName = FrameworkConstants.CommonFrameworks.NetStandard20
                });

                var actual = MSBuildStaticGraphRestore.GetProjectRestoreMetadataFrameworkInfos(targetFrameworkInfos, projects);

                actual.ShouldBeEquivalentTo(new[]
                {
                    new ProjectRestoreMetadataFrameworkInfo(FrameworkConstants.CommonFrameworks.Net45)
                    {
                        TargetAlias       = net45Alias,
                        ProjectReferences = new List <ProjectRestoreReference>
                        {
                            new ProjectRestoreReference
                            {
                                ProjectPath       = projectA.FullPath,
                                ProjectUniqueName = projectA.FullPath
                            },
                            new ProjectRestoreReference
                            {
                                ProjectPath       = projectB.FullPath,
                                ProjectUniqueName = projectB.FullPath
                            }
                        }
                    },
                    new ProjectRestoreMetadataFrameworkInfo(FrameworkConstants.CommonFrameworks.NetStandard20)
                    {
                        TargetAlias       = netstandard20Alias,
                        ProjectReferences = new List <ProjectRestoreReference>
                        {
                            new ProjectRestoreReference
                            {
                                ProjectPath       = projectA.FullPath,
                                ProjectUniqueName = projectA.FullPath
                            }
                        }
                    }
                });
            }
        }