Created
April 28, 2017 20:26
-
-
Save jermdavis/964180ed93e9519f1eb6004e5454c4b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using Moq; | |
using Sitecore.FiftyOneDegrees.CloudDeviceDetection.Services; | |
using Sitecore.FiftyOneDegrees.CloudDeviceDetection.Settings; | |
using Sitecore.FiftyOneDegrees.CloudDeviceDetection.System.Wrappers; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Web; | |
namespace IntegrationTests | |
{ | |
public class FakeWebRequestWrapper : IWebRequestWrapper | |
{ | |
public T GetJson<T>(string requestUrl) | |
{ | |
var serialiser = new JsonSerializer(); | |
var device = serialiser.Deserialize<T>("{\"MatchMethod\":\"Exact\",\"Difference\":0,\"DetectionTime\":0.0,\"Values\":{\"BrowserName\":[\"Chrome\"],\"BrowserVersion\":[\"57\"],\"DeviceType\":[\"Desktop\"],\"IsConsole\":[\"False\"],\"IsEReader\":[\"False\"],\"IsMediaHub\":[\"False\"],\"IsMobile\":[\"False\"],\"IsSmallScreen\":[\"False\"],\"IsSmartPhone\":[\"False\"],\"IsTablet\":[\"False\"],\"IsTv\":[\"False\"],\"PlatformName\":[\"Windows\"],\"PlatformVersion\":[\"8.1\"],\"ScreenPixelsHeight\":[\"Unknown\"],\"ScreenPixelsWidth\":[\"Unknown\"]},\"DataSetName\":\"PremiumV3\",\"Published\":\"2017-04-19T00:00:00Z\",\"SignaturesCompared\":0,\"ProfileIds\":{\"1\":15364,\"2\":21460,\"3\":69850,\"4\":18092},\"Useragent\":\"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko Chrome/57 Safari/537\",\"TargetUseragent\":\"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36\"}"); | |
return device; | |
} | |
} | |
[TestClass] | |
public class IntegrationTests | |
{ | |
[TestMethod] | |
public void DesktopBrowserShouldNotCrashOnCallToScreenPixelsWidth() | |
{ | |
// Arrange | |
var setting = new Mock<ISitecoreSettingsWrapper>(); | |
setting.Setup(i => i.GetSetting(It.IsAny<string>())).Returns(string.Empty); | |
var request = new HttpRequest("", "http://test.com", ""); | |
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter())); | |
var capsdictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); | |
HttpContext.Current.Request.Browser = new HttpBrowserCapabilities() { Capabilities = capsdictionary }; | |
var httpcontextWrapper = new Sitecore.FiftyOneDegrees.CloudDeviceDetection.System.Wrappers.HttpContextWrapper(HttpContext.Current); | |
var httpruntimeCache = new Mock<IHttpRuntimeCacheWrapper>(); | |
var httpWebRequest = new FakeWebRequestWrapper(); | |
// Act | |
var sut = new FiftyOneDegreesService(setting.Object, httpcontextWrapper, httpruntimeCache.Object, httpWebRequest); | |
sut.SetBrowserCapabilities(); | |
// Assert | |
Assert.AreEqual(0, request.Browser.ScreenPixelsWidth); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment