public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { // Determine whether to accept the route for this request. var browser = BrowserDetector.Parse(httpContext.Request.UserAgent); if (browser == BrowserPlatform.Mobile) { return(true); } return(false); }
public void Safari_In_IPad() { var headers = new Dictionary <string, StringValues>(); headers.Add(Headers.UserAgent, UserAgents.SafariIPad); var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); var actual = detector.Browser; Assert.Equal(BrowserNames.Safari, actual.Name); }
public void Edge_In_IPad() { var headers = new Dictionary <string, StringValues> { { Headers.UserAgent, UserAgents.Edge_IPad } }; var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); var actual = detector.Browser; Assert.Equal(BrowserNames.Edge, actual.Name); }
public void Handles_Gracefully_When_UserAgent_Header_Missing() { var headers = new Dictionary <string, StringValues> { { "UA-Header-Missing", UserAgents.OperaWindows } }; var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); var actual = detector.Browser; Assert.Null(actual); }
public void Opera_Windows() { var headers = new Dictionary <string, StringValues> { { Headers.UserAgent, UserAgents.Opera_Windows } }; var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); var actual = detector.Browser; Assert.Equal(BrowserNames.Opera, actual.Name); Assert.Equal(DeviceTypes.Desktop, actual.DeviceType); }
public void OperaTouch_iPhone() { // Arrange var headers = new Dictionary <string, StringValues> { { Headers.UserAgent, UserAgents.OperaTouchIPhone }, }; var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); // Act IBrowser actual = detector.Browser; // Assert Assert.Equal(BrowserNames.Opera, actual.Name); Assert.Equal(DeviceTypes.Mobile, actual.DeviceType); }
public void Edge18_Windows() { // Arrange var headers = new Dictionary <string, StringValues> { { Headers.UserAgent, UserAgents.Edge18Windows }, }; var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); // Act var actual = detector.Browser; // Assert Assert.Equal(BrowserNames.Edge, actual.Name); Assert.Equal(DeviceTypes.Desktop, actual.DeviceType); }
public void IE11_Windows() { // Arrange var headers = new Dictionary <string, StringValues> { { Headers.UserAgent, UserAgents.IE11_Windows } }; var httpContextAccessor = this.GetMockedHttpContextAccessor(headers); var detector = new BrowserDetector(httpContextAccessor); // Act var actual = detector.Browser; // Assert Assert.Equal(BrowserNames.InternetExplorer, actual.Name); Assert.Equal(DeviceTypes.Desktop, actual.DeviceType); Assert.Equal(OperatingSystems.Windows, actual.OS); }