string ExpectedHttpUserAgentString() { var version = typeof(DeviceClient).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; string runtime = RuntimeInformation.FrameworkDescription.Trim(); string operatingSystem = RuntimeInformation.OSDescription.Trim(); string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().Trim(); var productType = NativeMethods.GetWindowsProductType(); var productTypeString = (productType != 0) ? $" WindowsProduct:0x{productType:X8}" : string.Empty; var deviceId = TelemetryMethods.GetSqmMachineId() ?? string.Empty; return($".NET/{version} ({runtime}; {operatingSystem + productTypeString}; {processorArchitecture})"); }
private string ExpectedUserAgentString() { string version = typeof(DeviceClient).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; string runtime = RuntimeInformation.FrameworkDescription.Trim(); string operatingSystem = RuntimeInformation.OSDescription.Trim(); string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().Trim(); int productType = NativeMethods.GetWindowsProductType(); string productTypeString = (productType != 0) ? $" WindowsProduct:0x{productType:X8}" : string.Empty; string deviceId = TelemetryMethods.GetSqmMachineId() ?? string.Empty; string[] agentInfoParts = { runtime, operatingSystem + productTypeString, processorArchitecture, deviceId, }; return($".NET/{version} ({string.Join("; ", agentInfoParts.Where(x => !string.IsNullOrEmpty(x)))})"); }
public void GetSqmMachineId_ReturnsExpectedValue() { string actualValue = TelemetryMethods.GetSqmMachineId(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { string expectedValue = null; // Get SQM ID from Registry if exists RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\SQMClient"); if (key != null) { expectedValue = key.GetValue("MachineId") as string; } Assert.AreEqual(expectedValue, actualValue); } else { // GetSqmMachineId() should always return null for all other platforms Assert.IsNull(actualValue); } }