diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs index 2f904413af..2e648067c8 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Configuration/HttpCapabilitiesBase.cs @@ -23,4 +23,6 @@ private protected HttpCapabilitiesBase(BrowserCapabilitiesFactory factory, strin public string? Platform => _data["platform"]; public bool Crawler => _data.GetBoolean("crawler"); + + public bool IsMobileDevice => _data.GetBoolean("isMobileDevice"); } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs index 3b861f2a54..dac1dab660 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs @@ -27,6 +27,7 @@ public partial class HttpBrowserCapabilitiesBase public HttpBrowserCapabilitiesBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual string Browser { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual bool Crawler { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual bool IsMobileDevice { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual int MajorVersion { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual double MinorVersion { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual string Platform { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -37,6 +38,7 @@ public partial class HttpBrowserCapabilitiesWrapper : System.Web.HttpBrowserCapa public HttpBrowserCapabilitiesWrapper(System.Web.HttpBrowserCapabilities capabilities) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public override string Browser { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override bool Crawler { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override bool IsMobileDevice { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override int MajorVersion { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override double MinorVersion { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override string Platform { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -511,6 +513,7 @@ public partial class HttpCapabilitiesBase internal HttpCapabilitiesBase() { } public string Browser { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public bool Crawler { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public bool IsMobileDevice { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public int MajorVersion { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public double MinorVersion { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public string Platform { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesBase.cs index d1678390bc..d62362e745 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesBase.cs @@ -17,4 +17,6 @@ public class HttpBrowserCapabilitiesBase public virtual string? Platform => throw new NotImplementedException(); public virtual bool Crawler => throw new NotImplementedException(); + + public virtual bool IsMobileDevice => throw new NotImplementedException(); } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesWrapper.cs index 3e268f4038..9f95c47a7c 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpBrowserCapabilitiesWrapper.cs @@ -23,4 +23,6 @@ public HttpBrowserCapabilitiesWrapper(HttpBrowserCapabilities capabilities) public override string? Version => _capabilities.Version; public override bool Crawler => _capabilities.Crawler; + + public override bool IsMobileDevice => _capabilities.IsMobileDevice; } diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Configuration/BrowserCapabilitiesFactoryTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Configuration/BrowserCapabilitiesFactoryTests.cs index e17664c443..81415e9493 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Configuration/BrowserCapabilitiesFactoryTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Configuration/BrowserCapabilitiesFactoryTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; using System.Web.Configuration; using Xunit; @@ -26,6 +27,7 @@ public void VerifyCapabilities(TestData data) Assert.Equal(data.MajorVersion, result["majorversion"]); Assert.Equal(data.MinorVersion, result["minorversion"]); Assert.Equal(data.Platform, result["platform"]); + Assert.Equal(data.IsMobileDevice, Convert.ToBoolean(result["isMobileDevice"])); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Used for tests")] @@ -43,6 +45,8 @@ public record TestData(string UserAgent) public string? Crawler { get; init; } + public bool IsMobileDevice { get; init; } + public override string ToString() => UserAgent; } @@ -59,6 +63,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "102", MinorVersion = "0", Platform = "WinNT", + IsMobileDevice = false } }; @@ -71,6 +76,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "102", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = false } }; @@ -83,6 +89,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "0", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = true } }; @@ -95,6 +102,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "0", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = true } }; @@ -107,6 +115,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "0", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = true } }; @@ -119,6 +128,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "102", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = true } }; @@ -131,6 +141,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "102", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = true } }; @@ -144,6 +155,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "53", MinorVersion = "0", Platform = "WinNT", + IsMobileDevice = false } }; @@ -156,6 +168,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "101", MinorVersion = "0", Platform = "Unknown", + IsMobileDevice = false } }; @@ -168,6 +181,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "9", MinorVersion = "0", Platform = "WinNT", + IsMobileDevice = false } }; yield return new object[] @@ -179,6 +193,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "10", MinorVersion = "0", Platform = "WinNT", + IsMobileDevice = false } }; @@ -191,6 +206,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "51", MinorVersion = "0", Platform = "WinNT", + IsMobileDevice = false } }; @@ -203,6 +219,7 @@ public static IEnumerable UserAgentTestData MajorVersion = "102", MinorVersion = "0", Platform = "WinNT", + IsMobileDevice = false } }; }