public void CanCreateUsingFrameworkVersion(FrameworkData data)
 {
     RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);
     Assert.AreEqual(data.runtime, framework.Runtime);
     Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion);
     Assert.AreEqual(data.clrVersion, framework.ClrVersion);
 }
		private void CheckRuntimePlatforms( RuntimeFramework runtimeFramework, 
			string expectedPlatforms )
		{
			CheckPlatforms(
				new PlatformHelper( OSPlatform.CurrentPlatform, runtimeFramework ),
				expectedPlatforms,
				PlatformHelper.RuntimePlatforms + ",NET-1.0,NET-1.1,NET-2.0,NET-3.0,NET-3.5,NET-4.0,NET-4.5,MONO-1.0,MONO-2.0,MONO-3.0,MONO-3.5,MONO-4.0,MONOTOUCH,NETCF-2.0,NETCF-3.5,SL-3.0,SL-4.0,SL-5.0" );
		}
        public void CanCreateUsingClrVersion(FrameworkData data)
        {
            Assume.That(data.frameworkVersion.Major != 3);

            RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);
            Assert.AreEqual(data.runtime, framework.Runtime);
            Assert.AreEqual(data.frameworkVersion, framework.FrameworkVersion);
            Assert.AreEqual(data.clrVersion, framework.ClrVersion);
        }
        public void CanGetCurrentFramework()
        {
            Version expectedClrVersion = Environment.Version;
            Version expectedFrameworkVersion = new Version(expectedClrVersion.Major, expectedClrVersion.Minor);

#if SILVERLIGHT
            RuntimeType expectedRuntime = RuntimeType.Silverlight;
            expectedClrVersion = new RuntimeFramework(expectedRuntime, expectedFrameworkVersion).ClrVersion;
#else
             RuntimeType expectedRuntime = Type.GetType("Mono.Runtime", false) != null 
                ? RuntimeType.Mono 
                : Environment.OSVersion.Platform == PlatformID.WinCE
                    ? RuntimeType.NetCF
                    : RuntimeType.Net;

            // TODO: Remove duplication of RuntimeFramework code
            switch (expectedRuntime)
            {
                case RuntimeType.Mono:
                    if (expectedFrameworkVersion.Major == 1)
                        expectedFrameworkVersion = new Version(1,0);
                    else if (expectedFrameworkVersion.Major == 2)
                        expectedFrameworkVersion = new Version(3,5);
                    break;

                case RuntimeType.Net:
                case RuntimeType.NetCF:
#if !__MOBILE__
                    if (expectedFrameworkVersion.Major == 2)
                    {
                        RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");
                        if (key != null)
                        {
                            string installRoot = key.GetValue("InstallRoot") as string;
                            if (installRoot != null)
                            {
                                if (Directory.Exists(Path.Combine(installRoot, "v3.5")))
                                    expectedFrameworkVersion = new Version(3,5);
                                else if (Directory.Exists(Path.Combine(installRoot, "v3.0")))
                                    expectedFrameworkVersion = new Version(3,0);
                            }
                        }
                    }
#endif
                    break;
            }
#endif

            RuntimeFramework framework = RuntimeFramework.CurrentFramework;

            Assert.That(framework.Runtime, Is.EqualTo(expectedRuntime));
            Assert.That(framework.ClrVersion, Is.EqualTo(expectedClrVersion));
            Assert.That(framework.FrameworkVersion, Is.EqualTo(expectedFrameworkVersion));
        }
Example #5
0
 /// <summary>
 /// Default constructor uses the operating system and
 /// common language runtime of the system.
 /// </summary>
 public PlatformHelper()
 {
     this.os = OSPlatform.CurrentPlatform;
     this.rt = RuntimeFramework.CurrentFramework;
 }
 public void CanDisplayFrameworkAsString(FrameworkData data)
 {
     RuntimeFramework framework = new RuntimeFramework(data.runtime, data.frameworkVersion);
     Assert.AreEqual(data.representation, framework.ToString());
     Assert.AreEqual(data.displayName, framework.DisplayName);
 }
 public bool CanMatchRuntimes(RuntimeFramework f1, RuntimeFramework f2)
 {
     return f1.Supports(f2);
 }
 /// <summary>
 /// Default constructor uses the operating system and
 /// common language runtime of the system.
 /// </summary>
 public PlatformHelper()
 {
     this.os = OSPlatform.CurrentPlatform;
     this.rt = RuntimeFramework.CurrentFramework;
 }
 /// <summary>
 /// Contruct a PlatformHelper for a particular operating
 /// system and common language runtime. Used in testing.
 /// </summary>
 /// <param name="os">OperatingSystem to be used</param>
 /// <param name="rt">RuntimeFramework to be used</param>
 public PlatformHelper( OSPlatform os, RuntimeFramework rt )
 {
     this.os = os;
     this.rt = rt;
 }
Example #10
0
        /// <summary>
        /// Returns true if the current framework matches the
        /// one supplied as an argument. Two frameworks match
        /// if their runtime types are the same or either one
        /// is RuntimeType.Any and all specified version components
        /// are equal. Negative (i.e. unspecified) version
        /// components are ignored.
        /// </summary>
        /// <param name="target">The RuntimeFramework to be matched.</param>
        /// <returns>True on match, otherwise false</returns>
        public bool Supports(RuntimeFramework target)
        {
            if (Runtime != RuntimeType.Any
                && target.Runtime != RuntimeType.Any
                && Runtime != target.Runtime)
                return false;

            if (AllowAnyVersion || target.AllowAnyVersion)
                return true;

            if (!VersionsMatch(ClrVersion, target.ClrVersion))
                return false;

            return Runtime == RuntimeType.Silverlight
                ? FrameworkVersion.Major == target.FrameworkVersion.Major && FrameworkVersion.Minor == target.FrameworkVersion.Minor
                : FrameworkVersion.Major >= target.FrameworkVersion.Major && FrameworkVersion.Minor >= target.FrameworkVersion.Minor;
        }
        private bool IsRuntimeSupported(RuntimeType runtime, string versionSpecification)
        {
            Version version = versionSpecification == null
                ? RuntimeFramework.DefaultVersion
                : new Version(versionSpecification);

            RuntimeFramework target = new RuntimeFramework(runtime, version);

            return rt.Supports(target);
        }
Example #12
0
 /// <summary>
 /// Construct a PlatformHelper for a particular operating
 /// system and common language runtime. Used in testing.
 /// </summary>
 /// <param name="os">OperatingSystem to be used</param>
 /// <param name="rt">RuntimeFramework to be used</param>
 public PlatformHelper(OSPlatform os, RuntimeFramework rt)
 {
     this.os = os;
     this.rt = rt;
 }
Example #13
0
        public void CanGetCurrentFramework()
        {
            Version expectedClrVersion       = Environment.Version;
            Version expectedFrameworkVersion = new Version(expectedClrVersion.Major, expectedClrVersion.Minor);

#if SILVERLIGHT
            RuntimeType expectedRuntime = RuntimeType.Silverlight;
            expectedClrVersion = new RuntimeFramework(expectedRuntime, expectedFrameworkVersion).ClrVersion;
#else
            RuntimeType expectedRuntime = Type.GetType("Mono.Runtime", false) != null
                ? RuntimeType.Mono
                : Environment.OSVersion.Platform == PlatformID.WinCE
                    ? RuntimeType.NetCF
                    : RuntimeType.Net;

            // TODO: Remove duplication of RuntimeFramework code
            switch (expectedRuntime)
            {
            case RuntimeType.Mono:
                if (expectedFrameworkVersion.Major == 1)
                {
                    expectedFrameworkVersion = new Version(1, 0);
                }
                else if (expectedFrameworkVersion.Major == 2)
                {
                    expectedFrameworkVersion = new Version(3, 5);
                }
                break;

            case RuntimeType.Net:
            case RuntimeType.NetCF:
#if !__MOBILE__
                if (expectedFrameworkVersion.Major == 2)
                {
                    RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");
                    if (key != null)
                    {
                        string installRoot = key.GetValue("InstallRoot") as string;
                        if (installRoot != null)
                        {
                            if (Directory.Exists(Path.Combine(installRoot, "v3.5")))
                            {
                                expectedFrameworkVersion = new Version(3, 5);
                            }
                            else if (Directory.Exists(Path.Combine(installRoot, "v3.0")))
                            {
                                expectedFrameworkVersion = new Version(3, 0);
                            }
                        }
                    }
                }
#endif
                break;
            }
#endif

            RuntimeFramework framework = RuntimeFramework.CurrentFramework;

            Assert.That(framework.Runtime, Is.EqualTo(expectedRuntime));
            Assert.That(framework.ClrVersion, Is.EqualTo(expectedClrVersion));
            Assert.That(framework.FrameworkVersion, Is.EqualTo(expectedFrameworkVersion));
        }
Example #14
0
 /// <summary>
 /// Default constructor uses the operating system and
 /// common language runtime of the system.
 /// </summary>
 public PlatformHelper()
 {
     _os = OSPlatform.CurrentPlatform;
     _rt = RuntimeFramework.CurrentFramework;
 }
Example #15
0
 public bool CanMatchRuntimes(RuntimeFramework f1, RuntimeFramework f2)
 {
     return(f1.Supports(f2));
 }
Example #16
0
 /// <summary>
 /// Construct a PlatformHelper for a particular operating
 /// system and common language runtime. Used in testing.
 /// </summary>
 /// <param name="rt">RuntimeFramework to be used</param>
 /// <param name="os">OperatingSystem to be used</param>
 public PlatformHelper(OSPlatform os, RuntimeFramework rt)
 {
     _os = os;
     _rt = rt;
 }
Example #17
0
 /// <summary>
 /// Default constructor uses the operating system and
 /// common language runtime of the system.
 /// </summary>
 public PlatformHelper()
 {
     _os = OSPlatform.CurrentPlatform;
     _rt = RuntimeFramework.CurrentFramework;
 }
Example #18
0
 /// <summary>
 /// Construct a PlatformHelper for a particular operating
 /// system and common language runtime. Used in testing.
 /// </summary>
 /// <param name="os">OperatingSystem to be used</param>
 /// <param name="rt">RuntimeFramework to be used</param>
 public PlatformHelper( OSPlatform os, RuntimeFramework rt )
 {
     _os = os;
     _rt = rt;
 }