|
| 1 | +// ---------------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// Copyright Microsoft Corporation |
| 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 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +// ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.Collections.Generic; |
| 17 | +using System.Diagnostics; |
| 18 | +using System.Xml; |
| 19 | +using Microsoft.Azure.ServiceManagemenet.Common.Models; |
| 20 | +using Microsoft.WindowsAzure.Commands.ScenarioTest; |
| 21 | +using Xunit; |
| 22 | +using Xunit.Abstractions; |
| 23 | + |
| 24 | +namespace Microsoft.Azure.Commands.Insights.Test |
| 25 | +{ |
| 26 | + public class CustomPrinterTests |
| 27 | + { |
| 28 | + public CustomPrinterTests(ITestOutputHelper output) |
| 29 | + { |
| 30 | + XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); |
| 31 | + } |
| 32 | + |
| 33 | + [Fact] |
| 34 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 35 | + public void CustomPrinterTest_SimpleTypes() |
| 36 | + { |
| 37 | + const int x = 1; |
| 38 | + const double y = 1.2; |
| 39 | + const string s = "hello"; |
| 40 | + const bool b = true; |
| 41 | + TimeSpan ts = TimeSpan.FromHours(13); |
| 42 | + DateTime dt = DateTime.Now; |
| 43 | + DateTime dtUtc = DateTime.UtcNow; |
| 44 | + |
| 45 | + // The following should remove the " : " and the "\r\n" in the future |
| 46 | + Assert.Equal(" : 1\r\n", OutputClasses.CustomPrinter.Print(x)); |
| 47 | + Assert.Equal(" : 1.2\r\n", OutputClasses.CustomPrinter.Print(y)); |
| 48 | + Assert.Equal(" : hello\r\n", OutputClasses.CustomPrinter.Print(s)); |
| 49 | + Assert.Equal(" : True\r\n", OutputClasses.CustomPrinter.Print(b)); |
| 50 | + Assert.Equal(" : " + XmlConvert.ToString(ts) + "\r\n", OutputClasses.CustomPrinter.Print(ts)); |
| 51 | + |
| 52 | + // Must be dt.ToUniversalTime().ToString("O") in the future |
| 53 | + Assert.Equal(" : " + dt + "\r\n", OutputClasses.CustomPrinter.Print(dt)); |
| 54 | + |
| 55 | + // Must be dtUtc.ToString("O") in the future |
| 56 | + Assert.Equal(" : " + dtUtc + "\r\n", OutputClasses.CustomPrinter.Print(dtUtc)); |
| 57 | + |
| 58 | + // Both must be string.Empty in the future |
| 59 | + Assert.Equal(" :\r\n", OutputClasses.CustomPrinter.Print(null)); |
| 60 | + Assert.Equal(" : \r\n", OutputClasses.CustomPrinter.Print("")); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 65 | + public void CustomPrinterTest_ComplexTypes() |
| 66 | + { |
| 67 | + var stringList = new List<string>(); |
| 68 | + var dictionarySS = new Dictionary<string, string>(); |
| 69 | + var dictionarySO = new Dictionary<string, object>(); |
| 70 | + var eventData = Test.Utilities.CreateFakeEvent(id: null, newDates: false); |
| 71 | + |
| 72 | + // Must be {} in the future |
| 73 | + Assert.Equal("", OutputClasses.CustomPrinter.Print(stringList)); |
| 74 | + |
| 75 | + // Must be {} in the future |
| 76 | + Assert.Equal("", OutputClasses.CustomPrinter.Print(dictionarySS)); |
| 77 | + |
| 78 | + // Must be {} in the future |
| 79 | + Assert.Equal("", OutputClasses.CustomPrinter.Print(dictionarySO)); |
| 80 | + |
| 81 | + string result = OutputClasses.CustomPrinter.Print(eventData); |
| 82 | + Debug.WriteLine("EventData: "); |
| 83 | + Debug.WriteLine(result); |
| 84 | + |
| 85 | + // Must be [\r\nAuthorization : [\r\n Action : PUT\r\n Role : Sender\r\n Scope : None\r\n ]\r\nClaims : {\r\n [aud, https://management.core.windows.net/]\r\n [iss, https://sts.windows.net/123456/]\r\n [iat, h123445]\r\n }\r\nCaller : caller\r\nDescription : fake event\r\nId : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527\r\nEventDataId : \r\nCorrelationId : correlation\r\nEventName : [\r\n Value : Start request\r\n LocalizedValue : Start request\r\n ]\r\nCategory : [\r\n Value : Microsoft Resources\r\n LocalizedValue : Microsoft Resources\r\n ]\r\nHttpRequest : [\r\n ClientRequestId : 1234\r\n ClientIpAddress : 123.123.123.123\r\n Method : PUT\r\n Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy\r\n ]\r\nLevel : Informational\r\nResourceGroupName : Default-Web-EastUS\r\nResourceProviderName : [\r\n Value : Microsoft Resources\r\n LocalizedValue : Microsoft Resources\r\n ]\r\nResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1\r\nResourceType : \r\nOperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d\r\nOperationName : [\r\n Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n ]\r\nProperties : {}\r\nStatus : [\r\n Value : Succeeded\r\n LocalizedValue : Succeeded\r\n ]\r\nSubStatus : [\r\n Value : Created\r\n LocalizedValue : Created\r\n ]\r\nEventTimestamp : 2017-06-07T22:54:00.0000000Z\r\nSubmissionTimestamp : 2017-06-07T22:54:00.0000000Z\r\nSubscriptionId : \r\nTenantId : \r\n] in the future |
| 86 | + Assert.Equal( |
| 87 | + expected: "Authorization \r\nAction : PUT\r\nRole : Sender\r\nScope : None\r\n\r\nClaims \r\n : [aud, https://management.core.windows.net/]\r\n : [iss, https://sts.windows.net/123456/]\r\n : [iat, h123445]\r\nCaller : caller\r\nDescription : fake event\r\nId : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527\r\nEventDataId :\r\nCorrelationId : correlation\r\nEventName \r\nValue : Start request\r\nLocalizedValue : Start request\r\n\r\nCategory \r\nValue : Microsoft Resources\r\nLocalizedValue : Microsoft Resources\r\n\r\nHttpRequest \r\nClientRequestId : 1234\r\nClientIpAddress : 123.123.123.123\r\nMethod : PUT\r\nUri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy\r\n\r\nLevel : Informational\r\nResourceGroupName : Default-Web-EastUS\r\nResourceProviderName\r\nValue : Microsoft Resources\r\nLocalizedValue : Microsoft Resources\r\n\r\nResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1\r\nResourceType :\r\nOperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d\r\nOperationName \r\nValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\nLocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n\r\nProperties \r\nStatus \r\nValue : Succeeded\r\nLocalizedValue : Succeeded\r\n\r\nSubStatus \r\nValue : Created\r\nLocalizedValue : Created\r\n\r\nEventTimestamp : 6/7/2017 10:54:00 PM\r\nSubmissionTimestamp : 6/7/2017 10:54:00 PM\r\nSubscriptionId :\r\nTenantId :\r\n\r\n", |
| 88 | + actual: result); |
| 89 | + |
| 90 | + dictionarySS.Add("k1", "v1"); |
| 91 | + dictionarySS.Add("k2", "v2"); |
| 92 | + result = OutputClasses.CustomPrinter.Print(dictionarySS); |
| 93 | + Debug.WriteLine("Dictionary<string, string>: "); |
| 94 | + Debug.WriteLine(result); |
| 95 | + |
| 96 | + // Must be "{\r\n[k1, v1]\r\n[k2, v2]\r\n}" in the future |
| 97 | + Assert.Equal( |
| 98 | + expected: " : [k1, v1]\r\n : [k2, v2]\r\n", |
| 99 | + actual: result); |
| 100 | + |
| 101 | + dictionarySO.Add("k1", eventData); |
| 102 | + dictionarySO.Add("k2", Test.Utilities.CreateFakeEvent(id: "secondId", newDates: false)); |
| 103 | + result = OutputClasses.CustomPrinter.Print(dictionarySO); |
| 104 | + Debug.WriteLine("Dictionary<string, object>: "); |
| 105 | + Debug.WriteLine(result); |
| 106 | + // Must be "{\r\n[k1, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n[k2, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n}" in the future |
| 107 | + Assert.Equal( |
| 108 | + expected: " : [k1, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n : [k2, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n", |
| 109 | + actual: result); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
0 commit comments