|
| 1 | +/** |
| 2 | +* Copyright 2019 IBM Corp. All Rights Reserved. |
| 3 | +* |
| 4 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +* you may not use this file except in compliance with the License. |
| 6 | +* You may obtain a copy of the License at |
| 7 | +* |
| 8 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +* |
| 10 | +* Unless required by applicable law or agreed to in writing, software |
| 11 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +* See the License for the specific language governing permissions and |
| 14 | +* limitations under the License. |
| 15 | +* |
| 16 | +*/ |
| 17 | + |
| 18 | +using IBM.WatsonDeveloperCloud.Util; |
| 19 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 20 | +using System.Collections.Generic; |
| 21 | +using System.Runtime.InteropServices; |
| 22 | + |
| 23 | +namespace IBM.WatsonDeveloperCloud.Core.IntegrationTests |
| 24 | +{ |
| 25 | + [TestClass] |
| 26 | + public class UserAgentParsingTests |
| 27 | + { |
| 28 | + [TestMethod] |
| 29 | + public void TestGetDefaultHeaders() |
| 30 | + { |
| 31 | + Dictionary<string, string> sdkHeaders = new Dictionary<string, string>(); |
| 32 | + string osInfo = RuntimeInformation.OSDescription; |
| 33 | + string os = Utility.GetOs(osInfo); |
| 34 | + string osVersion = Utility.GetVersion(osInfo); |
| 35 | + string frameworkDescription = RuntimeInformation.FrameworkDescription.Trim(); |
| 36 | + |
| 37 | + sdkHeaders.Add("User-Agent", string.Format( |
| 38 | + "{0} {1} {2} {3}", |
| 39 | + Constants.SDK_VERSION, |
| 40 | + Utility.CleanupUserAgentString(os), |
| 41 | + Utility.CleanupUserAgentString(osVersion), |
| 42 | + Utility.CleanupUserAgentString(frameworkDescription) |
| 43 | + )); |
| 44 | + Assert.IsTrue(sdkHeaders.Count == 1); |
| 45 | + Assert.IsTrue(sdkHeaders.ContainsKey("User-Agent")); |
| 46 | + Assert.IsTrue(sdkHeaders["User-Agent"].Contains(Constants.SDK_VERSION)); |
| 47 | + Assert.IsFalse(sdkHeaders["User-Agent"].Contains("(")); |
| 48 | + Assert.IsFalse(sdkHeaders["User-Agent"].Contains(")")); |
| 49 | + Assert.IsFalse(sdkHeaders["User-Agent"].Contains(":")); |
| 50 | + Assert.IsFalse(sdkHeaders["User-Agent"].Contains(";")); |
| 51 | + Assert.IsFalse(sdkHeaders["User-Agent"].Contains("#")); |
| 52 | + Assert.IsFalse(sdkHeaders["User-Agent"].Contains("~")); |
| 53 | + Assert.IsTrue(sdkHeaders["User-Agent"].Split().Length == 4); |
| 54 | + } |
| 55 | + |
| 56 | + [TestMethod] |
| 57 | + public void GetVersionWindows() |
| 58 | + { |
| 59 | + string osDescription = "Microsoft Windows 10.0.17134 "; |
| 60 | + string osVersion = Utility.GetVersion(osDescription); |
| 61 | + Assert.IsTrue(osVersion == "10.0.17134"); |
| 62 | + } |
| 63 | + |
| 64 | + [TestMethod] |
| 65 | + public void GetVersionOSX() |
| 66 | + { |
| 67 | + string osDescription = "Darwin 17.7.0 Darwin Kernel Version 17.7.0: Fri Nov 2 20:43:16 PDT 2018; root:xnu-4570.71.17~1/RELEASE_X86_64"; |
| 68 | + string osVersion = Utility.GetVersion(osDescription); |
| 69 | + Assert.IsTrue(osVersion == "17.7.0"); |
| 70 | + } |
| 71 | + |
| 72 | + [TestMethod] |
| 73 | + public void GetVersionLinux() |
| 74 | + { |
| 75 | + string osDescription = "Linux 4.19.28-1-MANJARO #1 SMP PREEMPT Sun Mar 10 08:32:42 UTC 2019"; |
| 76 | + string osVersion = Utility.GetVersion(osDescription); |
| 77 | + Assert.IsTrue(osVersion == "4.19.28"); |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments