예제 #1
0
        public void TestParseWithStandardProfileString()
        {
            // Arrange & Act
            var profileCollection = new NetPortableProfileCollection();
            var profile1          = new NetPortableProfile(
                "Profile1",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            });

            var profile2 = new NetPortableProfile(
                "Profile2",
                new[] {
                new FrameworkName(".NetCore, Version=4.5"),
                new FrameworkName("Silverlight, Version=3.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            });

            profileCollection.Add(profile1);
            profileCollection.Add(profile2);

            NetPortableProfileTable.Profiles = profileCollection;

            var profile = NetPortableProfile.Parse("Profile2");

            // Assert
            Assert.Equal(3, profile.SupportedFrameworks.Count);
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName(".NetCore, Version=4.5")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("Silverlight, Version=3.0")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("WindowsPhone, Version=7.1")));
        }
        private static NetPortableProfileCollection BuildPortableProfileCollection()
        {
            var profileCollection = new NetPortableProfileCollection();
            profileCollection.AddRange(LoadProfilesFromFramework("v4.0"));
            profileCollection.AddRange(LoadProfilesFromFramework("v4.5"));

            return profileCollection;
        }
예제 #3
0
        public NetPortableProfileTable(IEnumerable<NetPortableProfile> profiles)
        {
            Profiles = new NetPortableProfileCollection();
            Profiles.AddRange(profiles);

            // Index profiles
            _portableProfilesByCustomProfileString = Profiles.ToDictionary(p => p.CustomProfileString);
            CreateOptionalFrameworksDictionary();
        }
예제 #4
0
            public TestContext(params NetPortableProfile[] portableProfiles)
            {
                Collection = new NetPortableProfileCollection();
                Collection.AddRange(portableProfiles);

                Table = new NetPortableProfileTable(Collection);

                CompatibilityProvider = new ReferenceAssemblyCompatibilityProvider(Collection);

                NameProvider = new ReferenceAssemblyFrameworkNameProvider(Collection);
            }
예제 #5
0
        public void TestParseWithCustomProfileString5WithOptionalFrameworkAndTreatedAsOptional()
        {
            // Arrange
            var collection = new NetPortableProfileCollection();
            var profile1   = new NetPortableProfile(
                "Profile1",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            },
                new[] {
                new FrameworkName("MonoTouch, Version=0.0"),
                new FrameworkName("MonoAndroid, Version=2.0"),
            });

            var profile2 = new NetPortableProfile(
                "Profile2",
                new[] {
                new FrameworkName(".NetCore, Version=4.5"),
                new FrameworkName("Silverlight, Version=3.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            });

            collection.Add(profile1);
            collection.Add(profile2);

            var table = new NetPortableProfileTable(collection);

            // Act
            // Default value of second parameter treatOptionalFrameworksAsSupportedFrameworks is false
            var profile = NetPortableProfile.Parse(
                table,
                "net45+sl40+wp71+MonoTouch+MonoAndroid20");

            // Assert
            Assert.Equal(3, profile.SupportedFrameworks.Count);
            Assert.Equal(2, profile.OptionalFrameworks.Count);
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName(".NETFramework, Version=4.5")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("Silverlight, Version=4.0")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("WindowsPhone, Version=7.1")));
            Assert.True(profile.OptionalFrameworks.Contains(new FrameworkName("MonoTouch, Version=0.0")));
            Assert.True(profile.OptionalFrameworks.Contains(new FrameworkName("MonoAndroid, Version=2.0")));
        }
예제 #6
0
        private static NetPortableProfileCollection BuildPortableProfileCollection()
        {
            var profileCollection = new NetPortableProfileCollection();
            string portableRootDirectory =
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86, Environment.SpecialFolderOption.DoNotVerify),
                        @"Reference Assemblies\Microsoft\Framework\.NETPortable");

            if (Directory.Exists(portableRootDirectory))
            {
                foreach (string versionDir in Directory.EnumerateDirectories(portableRootDirectory, "v*", SearchOption.TopDirectoryOnly))
                {
                    string profileFilesPath = versionDir + @"\Profile\";
                    profileCollection.AddRange(LoadProfilesFromFramework(versionDir, profileFilesPath));
                }
            }

            return profileCollection;
        }
예제 #7
0
        public void AddPackageReferenceThrowsWhenNoTargetFrameworkIsCompatibleWithPortableProject()
        {
            // Arrange
            var portableCollection = new NetPortableProfileCollection();
            portableCollection.Add(new NetPortableProfile("Profile104", new [] { VersionUtility.ParseFrameworkName("net45"), VersionUtility.ParseFrameworkName("sl5")}));

            NetPortableProfileTable.Profiles = portableCollection;

            var sourceRepository = new MockPackageRepository();
            var projectSystem = new MockProjectSystem(new FrameworkName(".NETPortable, Version=1.0, Profile=Profile104"));
            var projectManager = new ProjectManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, new MockPackageRepository());
            IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "silverlight4\\a.txt"});
            sourceRepository.AddPackage(packageA);

            // Act
            ExceptionAssert.Throws<InvalidOperationException>(
                () => projectManager.AddPackageReference("A"),
                "Could not install package 'A 1.0'. You are trying to install this package into a project that targets 'portable-net45+sl50', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.");
        }
예제 #8
0
        public void TestParseWithCustomProfileString4WithDifferentOrderingOfFrameworks()
        {
            // Arrange
            var collection = new NetPortableProfileCollection();
            var profile1   = new NetPortableProfile(
                "Profile1",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            },
                new[] {
                new FrameworkName("MonoTouch, Version=0.0"),
                new FrameworkName("MonoAndroid, Version=2.0"),
            });

            var profile2 = new NetPortableProfile(
                "Profile2",
                new[] {
                new FrameworkName(".NetCore, Version=4.5"),
                new FrameworkName("Silverlight, Version=3.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            });

            collection.Add(profile1);
            collection.Add(profile2);

            var table = new NetPortableProfileTable(collection);

            // Act
            var profile = NetPortableProfile.Parse(
                table,
                "net45+sl40+MonoTouch+wp71+MonoAndroid20");

            // Assert
            Assert.Equal(5, profile.SupportedFrameworks.Count);
            Assert.Equal(0, profile.OptionalFrameworks.Count);
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName(".NETFramework, Version=4.5")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("Silverlight, Version=4.0")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("WindowsPhone, Version=7.1")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("MonoTouch, Version=0.0")));
        }
예제 #9
0
        public void TestParseWithCustomProfileString6WithOptionalFrameworkAndTreatedAsSupported()
        {
            // Arrange & Act
            var profileCollection = new NetPortableProfileCollection();
            var profile1          = new NetPortableProfile(
                "Profile1",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            },
                new[] {
                new FrameworkName("MonoTouch, Version=0.0"),
                new FrameworkName("MonoAndroid, Version=2.0"),
            });

            var profile2 = new NetPortableProfile(
                "Profile2",
                new[] {
                new FrameworkName(".NetCore, Version=4.5"),
                new FrameworkName("Silverlight, Version=3.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
            });

            profileCollection.Add(profile1);
            profileCollection.Add(profile2);

            NetPortableProfileTable.Profiles = profileCollection;

            var profile = NetPortableProfile.Parse("net45+sl40+wp71+MonoTouch+MonoAndroid20", treatOptionalFrameworksAsSupportedFrameworks: true);

            // Assert
            Assert.Equal(5, profile.SupportedFrameworks.Count);
            Assert.Equal(0, profile.OptionalFrameworks.Count);
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName(".NETFramework, Version=4.5")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("Silverlight, Version=4.0")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("WindowsPhone, Version=7.1")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("MonoTouch, Version=0.0")));
        }
예제 #10
0
        public void TestIsCompatibleWithPortableProfile11WithMonoProjectWithVersionLesserThanInstalledProfile()
        {
            // Arrange
            var profile1 = new NetPortableProfile(
                "Profile1",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
                new FrameworkName("Windows, Version=8.0"),
            },
                new[] {
                new FrameworkName("MonoTouch, Version=1.0"),
                new FrameworkName("MonoAndroid, Version=2.0"),
                new FrameworkName("MonoMac, Version=1.0"),
            });

            NetPortableProfileCollection profileCollection = new NetPortableProfileCollection();

            profileCollection.Add(profile1);

            var packageProfile = new NetPortableProfile(
                "ProfileXXX",
                new[] {
                new FrameworkName(".NETFramework, Version=4.0"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.0"),
                new FrameworkName("Windows, Version=8.0"),
            });

            var projectProfile = new FrameworkName("MonoAndroid, Version=1.0");

            NetPortableProfileTable.Profiles = profileCollection;

            // Act & Assert
            Assert.False(packageProfile.IsCompatibleWith(projectProfile));
        }
예제 #11
0
        public void TestGetCompatibilityBetweenPortableLibraryAndNonPortableLibraryForMono(string projectFrameworkName, string packageTargetFrameworkName, long expectedScore)        
        {
            // Arrange
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"),
                           new FrameworkName("WindowsPhone, Version=7.1"),
                           new FrameworkName("Windows, Version=8.0"),
                      },
               new[] { 
                           new FrameworkName("MonoTouch, Version=1.0"), 
                           new FrameworkName("MonoAndroid, Version=1.0"),
                           new FrameworkName("MonoMac, Version=1.0"),
                      });

            var profile2 = new NetPortableProfile(
               "Profile2",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("WindowsPhone, Version=8.0"),
                           new FrameworkName("Windows, Version=8.0"),
                      },
               new[] { 
                           new FrameworkName("MonoTouch, Version=1.0"), 
                           new FrameworkName("MonoAndroid, Version=1.0"),
                      });

            NetPortableProfileCollection profileCollection = new NetPortableProfileCollection();
            profileCollection.Add(profile1);
            profileCollection.Add(profile2);

            NetPortableProfileTable.Profiles = profileCollection;

            // Arrange
            var framework = VersionUtility.ParseFrameworkName(projectFrameworkName);
            var targetFramework = VersionUtility.ParseFrameworkName(packageTargetFrameworkName);

            // Act
            long score = VersionUtility.GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(framework, targetFramework);

            // Assert
            Assert.Equal(expectedScore, score);
        }
예제 #12
0
        public void TestGetCompatibilityBetweenPortableLibraryAndPortableLibraryWithPreLoadedPackageProfile(string frameworkName, string targetFrameworkName, int expectedScore)
        {
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.0"), 
                           new FrameworkName("Silverlight, Version=4.0"), 
                      },
               new[] { 
                           new FrameworkName("MonoTouch, Version=0.0"), 
                           new FrameworkName("MonoAndroid, Version=0.0"), 
                      });

            NetPortableProfileCollection profileCollection = new NetPortableProfileCollection();
            profileCollection.Add(profile1);

            NetPortableProfileTable.Profiles = profileCollection;

            // Arrange
            var framework = VersionUtility.ParseFrameworkName(frameworkName);
            var targetFramework = VersionUtility.ParseFrameworkName(targetFrameworkName);

            // Act
            int score = VersionUtility.GetCompatibilityBetweenPortableLibraryAndPortableLibrary(framework, targetFramework);

            // Assert
            Assert.Equal(expectedScore, score);
        }
예제 #13
0
        public void TestIsCompatibleWithPortableProfile11WithMonoProjectWithVersionLesserThanInstalledProfile()
        {
            // Arrange
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"),
                           new FrameworkName("WindowsPhone, Version=7.1"),
                           new FrameworkName("Windows, Version=8.0"),
                      },
               new[] { 
                           new FrameworkName("MonoTouch, Version=1.0"), 
                           new FrameworkName("MonoAndroid, Version=2.0"),
                           new FrameworkName("MonoMac, Version=1.0"),
                      });

            NetPortableProfileCollection profileCollection = new NetPortableProfileCollection();
            profileCollection.Add(profile1);

            var packageProfile = new NetPortableProfile(
                "ProfileXXX",
                new[] { 
                           new FrameworkName(".NETFramework, Version=4.0"), 
                           new FrameworkName("Silverlight, Version=4.0"),
                           new FrameworkName("WindowsPhone, Version=7.0"),
                           new FrameworkName("Windows, Version=8.0"),
                      });

            var projectProfile = new FrameworkName("MonoAndroid, Version=1.0");

            NetPortableProfileTable.Profiles = profileCollection;

            // Act & Assert
            Assert.False(packageProfile.IsCompatibleWith(projectProfile));
        }
예제 #14
0
        public void TestIsCompatibleWithPortableProfile12WithMonoProjectWithMultipleInstalledProfileHavingMonoOfDifferentVersions()
        {
            // Arrange
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"),
                           new FrameworkName("WindowsPhone, Version=7.1"),
                           new FrameworkName("Windows, Version=8.0"),
                      },
               new[] { 
                           new FrameworkName("MonoTouch, Version=1.0"), 
                           new FrameworkName("MonoAndroid, Version=3.0"),
                           new FrameworkName("MonoMac, Version=1.0"),
                      });

            var profile2 = new NetPortableProfile(
               "Profile2",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"),
                           new FrameworkName("WindowsPhone, Version=7.1"),
                           new FrameworkName("Windows, Version=8.0"),
                      },
               new[] { 
                           new FrameworkName("MonoAndroid, Version=1.0"),
                           new FrameworkName("MonoMac, Version=1.0"),
                      });

            var profile3 = new NetPortableProfile(
               "Profile3",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.5"),
                      },
               new[] { 
                           new FrameworkName("MonoAndroid, Version=3.0"),
                      });

            NetPortableProfileCollection profileCollection = new NetPortableProfileCollection();
            profileCollection.Add(profile1);
            profileCollection.Add(profile2);
            profileCollection.Add(profile3);

            var packageProfile = new NetPortableProfile(
                "ProfileXXX",
                new[] { 
                           new FrameworkName(".NETFramework, Version=4.0"), 
                           new FrameworkName("Silverlight, Version=4.0"),
                           new FrameworkName("WindowsPhone, Version=7.0"),
                           new FrameworkName("Windows, Version=8.0"),
                      });

            var projectProfile = new FrameworkName("MonoAndroid, Version=2.0");

            NetPortableProfileTable.Profiles = profileCollection;

            // Act & Assert
            Assert.True(packageProfile.IsCompatibleWith(projectProfile));
        }
예제 #15
0
        public void TestGetShortNameForPortableXamarinFrameworks(string frameworkIdentifier, string expectedShortName)
        {
            // Arrange
            var profileCollection = new NetPortableProfileCollection();
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Xamarin.Mac, Version=1.0"), 
                           new FrameworkName("Xamarin.iOS, Version=1.0"), 
                      });

            var profile2 = new NetPortableProfile(
               "Profile2",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.0"), 
                           new FrameworkName(".NetCore, Version=4.5"), 
                           new FrameworkName("Xamarin.PlayStation3, Version=1.0"), 
                           new FrameworkName("Xamarin.PlayStation4, Version=1.0"), 
                           new FrameworkName("Xamarin.PlayStationVita, Version=1.0"), 
                      });

            var profile3 = new NetPortableProfile(
               "Profile3",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.0"), 
                           new FrameworkName("Xamarin.Xbox360, Version=1.0"), 
                           new FrameworkName("Xamarin.XboxOne, Version=1.0"), 
                      });

            profileCollection.Add(profile1);
            profileCollection.Add(profile2);
            profileCollection.Add(profile3);

            var portableProfileTable = new NetPortableProfileTable(profileCollection);

            var framework = new FrameworkName(frameworkIdentifier);

            // Act
            string shortName = VersionUtility.GetShortFrameworkName(framework, portableProfileTable);

            // Assert
            Assert.Equal(expectedShortName, shortName);
        }
예제 #16
0
        public void TestParseWithCustomProfileString6WithOptionalFrameworkAndTreatedAsSupported()
        {
            // Arrange & Act
            var profileCollection = new NetPortableProfileCollection();
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"), 
                           new FrameworkName("WindowsPhone, Version=7.1"), 
                      },
               new[] { 
                           new FrameworkName("MonoTouch, Version=0.0"), 
                           new FrameworkName("MonoAndroid, Version=2.0"), 
                      });

            var profile2 = new NetPortableProfile(
               "Profile2",
               new[] { 
                           new FrameworkName(".NetCore, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=3.0"), 
                           new FrameworkName("WindowsPhone, Version=7.1"), 
                      });
            profileCollection.Add(profile1);
            profileCollection.Add(profile2);

            NetPortableProfileTable.Profiles = profileCollection;

            var profile = NetPortableProfile.Parse("net45+sl40+wp71+MonoTouch+MonoAndroid20", treatOptionalFrameworksAsSupportedFrameworks: true);

            // Assert
            Assert.Equal(5, profile.SupportedFrameworks.Count);
            Assert.Equal(0, profile.OptionalFrameworks.Count);
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName(".NETFramework, Version=4.5")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("Silverlight, Version=4.0")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("WindowsPhone, Version=7.1")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("MonoTouch, Version=0.0")));
        }
예제 #17
0
        public void TestIsCompatibleWithPortableProfile12WithMonoProjectWithMultipleInstalledProfileHavingMonoOfDifferentVersions()
        {
            // Arrange
            var profile1 = new NetPortableProfile(
                "Profile1",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
                new FrameworkName("Windows, Version=8.0"),
            },
                new[] {
                new FrameworkName("MonoTouch, Version=1.0"),
                new FrameworkName("MonoAndroid, Version=3.0"),
                new FrameworkName("MonoMac, Version=1.0"),
            });

            var profile2 = new NetPortableProfile(
                "Profile2",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.1"),
                new FrameworkName("Windows, Version=8.0"),
            },
                new[] {
                new FrameworkName("MonoAndroid, Version=1.0"),
                new FrameworkName("MonoMac, Version=1.0"),
            });

            var profile3 = new NetPortableProfile(
                "Profile3",
                new[] {
                new FrameworkName(".NETFramework, Version=4.5"),
                new FrameworkName("Silverlight, Version=4.5"),
            },
                new[] {
                new FrameworkName("MonoAndroid, Version=3.0"),
            });

            NetPortableProfileCollection profileCollection = new NetPortableProfileCollection();

            profileCollection.Add(profile1);
            profileCollection.Add(profile2);
            profileCollection.Add(profile3);

            var packageProfile = new NetPortableProfile(
                "ProfileXXX",
                new[] {
                new FrameworkName(".NETFramework, Version=4.0"),
                new FrameworkName("Silverlight, Version=4.0"),
                new FrameworkName("WindowsPhone, Version=7.0"),
                new FrameworkName("Windows, Version=8.0"),
            });

            var projectProfile = new FrameworkName("MonoAndroid, Version=2.0");

            NetPortableProfileTable.Profiles = profileCollection;

            // Act & Assert
            Assert.True(packageProfile.IsCompatibleWith(projectProfile));
        }
예제 #18
0
        private NetPortableProfileCollection BuildProfileCollection()
        {
            var profileCollection = new NetPortableProfileCollection();
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"), 
                           new FrameworkName("WindowsPhone, Version=7.1"), 
                      });

            var profile2 = new NetPortableProfile(
               "Profile2",
               new[] { 
                           new FrameworkName(".NetCore, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=3.0"), 
                           new FrameworkName("WindowsPhone, Version=7.1"), 
                      });

            var profile3 = new NetPortableProfile(
               "Profile3",
               new[] { 
                           new FrameworkName(".NetCore, Version=4.5"), 
                           new FrameworkName(".NETFramework, Version=2.0"), 
                      });

            var profile4 = new NetPortableProfile(
               "Profile4",
               new[] { 
                           new FrameworkName("Silverlight, Version=2.0"), 
                           new FrameworkName("Silverlight, Version=3.0, Profile=WindowsPhone"), 
                      });

            profileCollection.Add(profile1);
            profileCollection.Add(profile2);
            profileCollection.Add(profile3);
            profileCollection.Add(profile4);

            return profileCollection;
        }
예제 #19
0
        public void TestParseWithStandardProfileString()
        {
            // Arrange & Act
            var profileCollection = new NetPortableProfileCollection();
            var profile1 = new NetPortableProfile(
               "Profile1",
               new[] { 
                           new FrameworkName(".NETFramework, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=4.0"), 
                           new FrameworkName("WindowsPhone, Version=7.1"), 
                      });

            var profile2 = new NetPortableProfile(
               "Profile2",
               new[] { 
                           new FrameworkName(".NetCore, Version=4.5"), 
                           new FrameworkName("Silverlight, Version=3.0"), 
                           new FrameworkName("WindowsPhone, Version=7.1"), 
                      });
            profileCollection.Add(profile1);
            profileCollection.Add(profile2);

            NetPortableProfileTable.Profiles = profileCollection;

            var profile = NetPortableProfile.Parse("Profile2");

            // Assert
            Assert.Equal(3, profile.SupportedFrameworks.Count);
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName(".NetCore, Version=4.5")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("Silverlight, Version=3.0")));
            Assert.True(profile.SupportedFrameworks.Contains(new FrameworkName("WindowsPhone, Version=7.1")));
        }
        private static NetPortableProfileCollection BuildPortableProfileCollection()
        {
            var profileCollection = new NetPortableProfileCollection();
            
            string portableRootDirectory;

            string portableReferencePathOverride = Environment.GetEnvironmentVariable(PortableReferenceAssemblyPathEnvironmentVariableName);
            if (!string.IsNullOrEmpty(portableReferencePathOverride))
            {
                portableRootDirectory = portableReferencePathOverride;
            }
            else
            {
                portableRootDirectory = GetPortableRootDirectory();
            }

            if (Directory.Exists(portableRootDirectory))
            {
                foreach (string versionDir in Directory.EnumerateDirectories(portableRootDirectory, "v*", SearchOption.TopDirectoryOnly))
                {
                    string profileFilesPath = Path.Combine(versionDir, "Profile");
                    profileCollection.AddRange(LoadProfilesFromFramework(versionDir, profileFilesPath));
                }
            }

            return profileCollection;
        }