diff --git a/Examples/Cloud/Framework-Web/App_Data/51Degrees.json b/Examples/Cloud/Framework-Web/App_Data/51Degrees.json index 58ffa45c..a3fa750e 100644 --- a/Examples/Cloud/Framework-Web/App_Data/51Degrees.json +++ b/Examples/Cloud/Framework-Web/App_Data/51Degrees.json @@ -20,6 +20,8 @@ } } ], - "ClientSideEnabled": true + "BuildParameters": { + "ClientSideEnabled": true + } } } diff --git a/Examples/OnPremise/Framework-Web/App_Data/51Degrees.json b/Examples/OnPremise/Framework-Web/App_Data/51Degrees.json index 01e4e5ac..99719e97 100644 --- a/Examples/OnPremise/Framework-Web/App_Data/51Degrees.json +++ b/Examples/OnPremise/Framework-Web/App_Data/51Degrees.json @@ -19,6 +19,8 @@ } } ], - "ClientSideEnabled": true + "BuildParameters": { + "ClientSideEnabled": true + } } } diff --git a/FiftyOne.DeviceDetection/FiftyOne.DeviceDetection/Uach/UachJsConversionElement.cs b/FiftyOne.DeviceDetection/FiftyOne.DeviceDetection/Uach/UachJsConversionElement.cs index 8d42e7ff..84729826 100644 --- a/FiftyOne.DeviceDetection/FiftyOne.DeviceDetection/Uach/UachJsConversionElement.cs +++ b/FiftyOne.DeviceDetection/FiftyOne.DeviceDetection/Uach/UachJsConversionElement.cs @@ -99,39 +99,39 @@ protected override void ProcessInternal(IFlowData data) var brandsString = SerializeBrands(uachData.Brands); if (brandsString != null) { - data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_QUERY_KEY, brandsString); + data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_HEADER_KEY, brandsString); evidenceAdded = true; } var brandsFullVersionString = SerializeBrands(uachData.FullVersionList); if (brandsFullVersionString != null) { - data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_QUERY_KEY, + data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_HEADER_KEY, brandsFullVersionString); evidenceAdded = true; } if (uachData.Mobile.HasValue) { - data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MOBILE_QUERY_KEY, + data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MOBILE_HEADER_KEY, uachData.Mobile.Value ? "?1" : "?0"); evidenceAdded = true; } if (uachData.Model != null) { - data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MODEL_QUERY_KEY, + data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_MODEL_HEADER_KEY, ConvertText(uachData.Model)); evidenceAdded = true; } if (uachData.Platform != null) { - data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY, + data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY, ConvertText(uachData.Platform)); evidenceAdded = true; } if (uachData.PlatformVersion != null) { - data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_QUERY_KEY, + data.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_HEADER_KEY, ConvertText(uachData.PlatformVersion)); evidenceAdded = true; } diff --git a/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/DeviceDetectionTests.cs b/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/DeviceDetectionTests.cs index ac5ed1d8..f6695123 100644 --- a/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/DeviceDetectionTests.cs +++ b/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/DeviceDetectionTests.cs @@ -44,6 +44,15 @@ public class DeviceDetectionTests private static UserAgentGenerator USER_AGENTS = new UserAgentGenerator( TestHelpers.Utils.GetFilePath(Constants.UA_FILE_NAME)); + private static readonly List> UachTestValues = new List>() + { + new Dictionary() + { + { Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY, @"""Windows""" }, + { Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_HEADER_KEY, @"""14.0.0""" } + } + }; + [DataTestMethod] // ******** Hash with a single thread ********* [DataRow(Constants.LITE_HASH_DATA_FILE_NAME, PerformanceProfiles.MaxPerformance, false, false, DisplayName = "Hash-MaxPerformance-NoLazyLoad-SingleThread")] @@ -73,17 +82,46 @@ public void Hash_AllConfigurations_100_UserAgents( bool useLazyLoading, bool multiThreaded) { - TestOnPremise_AllConfigurations_100_UserAgents(datafileName, + TestWithEvidence(datafileName, + performanceProfile, + useLazyLoading, + multiThreaded, + GetEvidenceFromUas(), + // Just access the IsMobile property to ensure we can get data out. + // This will throw an exception if the value was not populated + (dd) => { var result = dd.IsMobile; }); + } + + public void Hash_Uach( + string datafileName, + PerformanceProfiles performanceProfile, + bool useLazyLoading, + bool multiThreaded) + { + TestWithEvidence(datafileName, performanceProfile, useLazyLoading, - multiThreaded); + multiThreaded, + UachTestValues, + (dd) => { Assert.AreEqual("11", dd.PlatformVersion.Value); }); } /// - /// This test will create a device detection pipeline based on the - /// supplied parameters, process 1000 user agents. - /// The various parameters allow the test to be run for many - /// different configurations. + /// Use the 'USER_AGENTS' field to construct a collection of evidence values. + /// + /// + private IEnumerable>> GetEvidenceFromUas() + { + foreach (var ua in USER_AGENTS.GetRandomUserAgents(100)) + { + var key = Pipeline.Core.Constants.EVIDENCE_HTTPHEADER_PREFIX + + Pipeline.Core.Constants.EVIDENCE_SEPERATOR + "User-Agent"; + yield return new KeyValuePair[1] { new KeyValuePair(key, ua) }; + } + } + + /// + /// Test the supplied evidence using the specified device detection settings. /// /// /// The filename of the data file to use for device detection. @@ -98,11 +136,20 @@ public void Hash_AllConfigurations_100_UserAgents( /// Whether to use a single thread or multiple threads when /// passing user agents to the pipeline for processing. /// - public void TestOnPremise_AllConfigurations_100_UserAgents( + /// + /// The evidence values to test with. + /// + /// + /// An action to execute to verify that the result includes the expected values. + /// The action should throw an exception describing the problem if verification fails. + /// + public void TestWithEvidence( string datafileName, PerformanceProfiles performanceProfile, bool useLazyLoading, - bool multiThreaded) + bool multiThreaded, + IEnumerable>> evidence, + Action verifyAction) { var datafile = TestHelpers.Utils.GetFilePath(datafileName); var updateService = new Mock(); @@ -138,19 +185,19 @@ public void TestOnPremise_AllConfigurations_100_UserAgents( // Create a parallel loop to actually process the user agents. - Parallel.ForEach(USER_AGENTS.GetRandomUserAgents(100), options, - (useragent) => + Parallel.ForEach(evidence, options, + (evidenceEntry) => { // Create the flow data instance using (var flowData = pipeline.CreateFlowData()) { - // Add the user agent to the flow data - // and process it - flowData.AddEvidence( - Pipeline.Core.Constants.EVIDENCE_HTTPHEADER_PREFIX + - Pipeline.Core.Constants.EVIDENCE_SEPERATOR + "User-Agent", useragent) - .Process(); + // Add the evidence to the flow data and process it + foreach (var subEntry in evidenceEntry) + { + flowData.AddEvidence(subEntry.Key, subEntry.Value); + } + flowData.Process(); // Make sure no errors occurred. If any did then // cancel the parallel process. @@ -162,16 +209,15 @@ public void TestOnPremise_AllConfigurations_100_UserAgents( cancellationSource.Cancel(); } - // Get the device data instance and access the - // IsMobile property to ensure we can get - // data out. + // Get the device data instance and pass it to the verifyAction. var deviceData = flowData.Get(); - var result = deviceData.IsMobile; + verifyAction(deviceData); } }); } } + /// /// Private method to present the given list of FlowError /// instances as a single string. diff --git a/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/UachJsConversionElementTests.cs b/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/UachJsConversionElementTests.cs index ea2ea02f..c4309a5e 100644 --- a/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/UachJsConversionElementTests.cs +++ b/FiftyOne.DeviceDetection/Tests/FiftyOne.DeviceDetection.Tests.Core/UachJsConversionElementTests.cs @@ -102,12 +102,12 @@ public void VerifyErrorHandling_KeysAlreadyPresent() // Supply evidence flowData.AddEvidence(Constants.EVIDENCE_HIGH_ENTROPY_VALUES_KEY_COOKIE, evidenceValue); // Add an existing evidence value for query.sec-ch-ua-platform. - flowData.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY, + flowData.AddEvidence(Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY, @"""Existing Platform"""); flowData.Process(); // Make sure the pre-existing value has been overwritten. - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY, @"""Windows"""); } } @@ -171,17 +171,17 @@ public void VerifyRealWorldValues( flowData.Process(); // Check that the evidence has been updated as expected. - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_HEADER_KEY, expectedSecChUa); - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_FULLVERSIONLIST_HEADER_KEY, expectedSecChUaFullVersionList); - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MOBILE_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MOBILE_HEADER_KEY, expectedSecChUaMobile); - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MODEL_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_MODEL_HEADER_KEY, expectedSecChUaModel); - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_HEADER_KEY, expectedSecChUaPlatform); - CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_QUERY_KEY, + CheckEvidence(flowData, Shared.Constants.EVIDENCE_SECCHUA_PLATFORM_VERSION_HEADER_KEY, expectedSecChUaPlatformVersion); } } diff --git a/ci/common-ci b/ci/common-ci index 2404d897..a497e679 160000 --- a/ci/common-ci +++ b/ci/common-ci @@ -1 +1 @@ -Subproject commit 2404d897c81ae419e5954b3507182f4e22184573 +Subproject commit a497e6795c9f08a42036725da954ef4993805dec