Exemple #1
0
    public static void OSID_Name_Formats_Correctly()
    {
        OSID   id        = OSID.Windows_7 | OSID.Ubuntu_14_04;
        string formatted = id.Name();

        Assert.True(formatted.Contains("Windows_7") && formatted.Contains("Ubuntu_14_04"),
                    String.Format("FrameworkID.Name should have contained Windows_7 and Ubuntu_14_04, but actual was \"{0}\"", formatted));
    }
Exemple #2
0
        // Detects the OSID based on the current OS description.
        // Currently this is used only for Windows because the non-Windows
        // descriptions vary widely in format.
        private static OSID OSIDfromOSDescription()
        {
            string osDescription = CurrentOSDescription;

            if (string.IsNullOrEmpty(osDescription))
            {
                return(OSID.None);
            }

            foreach (var pair in _descriptionToOSID)
            {
                string description = pair.Item1;
                if (osDescription.IndexOf(description, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    OSID detectedID = pair.Item2;

                    // A match of "AnyWindows" means we know it was Windows but don't know which version.
                    if (detectedID == OSID.AnyWindows)
                    {
                        // "Microsoft Windows" is hard-coded at compilation time by RuntimeInformation.OSDescription
                        // for win8 and netcore50 builds.  See if we had an exact match (not just prefix-match).
                        if (string.Equals(MicrosoftWindowsName, CurrentOSDescription, StringComparison.OrdinalIgnoreCase))
                        {
                            // Complete match means it is compile-time hard coded for NET Native or Win8.
                            // If this is NET Native, mask out any OSID's where we know UWP cannot execute.
                            // What remains is a bit mask indicating which Windows version it could be.
                            if (FrameworkID.NetNative.MatchesCurrent())
                            {
                                detectedID &= ~(OSID.Windows_Server_2008 |
                                                OSID.Windows_7 | OSID.Windows_Server_2008_R2 |
                                                OSID.Windows_8 | OSID.Windows_Server_2008 | OSID.Windows_Server_2012 |
                                                OSID.WindowsPhone);
                            }
                            else
                            {
                                // If this is not NET Native, Win8 is the only other OS for which
                                // this hard-coded literal is used.
                                detectedID = OSID.Windows_8;
                            }
                        }
                        else
                        {
                            // If the OSDescription is more than the hard-coded literal but we did not
                            // match the version that followed it, it means we have a version of Windows
                            // that did not exist at the time this code was written.  Flag the result as
                            // OSID.None to force infrastructure functional tests to fail for investigation.
                            detectedID = OSID.None;
                        }
                    }

                    return(detectedID);
                }
            }

            return(OSID.None);
        }
Exemple #3
0
    public static void ListAllOSRIDs()
    {
        string testRuntime          = OSHelper.GetRuntimeIdentifier();
        OSID   id                   = OSHelper.OSIDfromRuntimeEnvironment();
        string runtimeOSDescription = RuntimeInformation.OSDescription;

        Assert.True(false, string.Format("Detected the current Runtime Identifier as: '{0}'\n" +
                                         "Which maps to OSID: '{1}'\n" +
                                         "Detected the current runtimeOSDescription as: '{2}'", testRuntime, id.Name(), runtimeOSDescription));
    }
Exemple #4
0
        private static OSID DetectCurrentOS()
        {
            // First attempt to map from the test runtime.
            // All the non-Windows OSes are mapped this way.
            OSID osid = OSIDfromRuntimeEnvironment();

            if (osid == OSID.None)
            {
                // The Windows OSes are mapped based on description
                // because they all share the same runtime
                osid = OSIDfromOSDescription();
            }

            return(osid);
        }
Exemple #5
0
 // Extension method for OSID to provide name.
 // "G" formatting will expand to enum's name or collection if multiple.
 public static string Name(this OSID id)
 {
     return(id.ToString("G"));
 }
Exemple #6
0
 // Extension method that returns 'true' if the given OSID
 // includes the OSID on which this is currently executing.
 public static bool MatchesCurrent(this OSID id)
 {
     return((Current & id) != 0);
 }