static OsVersionTests() { // invoke the call and populate the backing field that we're going to replace bool _ = OsVersion.IsWindows8_1OrGreater; s_typeOsVersion = typeof(OsVersion); s_fiVersionInfo = s_typeOsVersion.GetField("s_versionInfo", Reflection.BindingFlags.Static | Reflection.BindingFlags.NonPublic); Assert.NotNull(s_fiVersionInfo); s_realVersionInfo = (Interop.NtDll.RTL_OSVERSIONINFOEX)s_fiVersionInfo.GetValue(null); }
private void PerformAssert(uint major, uint minor, uint buildNumber, Action assertion) { try { Interop.NtDll.RTL_OSVERSIONINFOEX verInfo = new Interop.NtDll.RTL_OSVERSIONINFOEX { dwMajorVersion = major, dwMinorVersion = minor, dwBuildNumber = buildNumber }; s_fiVersionInfo.SetValue(null, verInfo); assertion(); } finally { // restore the real OS version s_fiVersionInfo.SetValue(null, s_realVersionInfo); } }