Skip to content

Commit 193cb84

Browse files
authored
Fix CustomPrinter Test Case Failure in MacOs for Monitor (#26261)
* Try to fix test case failure in MacOs for Monitor * Use invariant culture
1 parent e39b4a8 commit 193cb84

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Monitor/Monitor.Test/CustomPrinterTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Globalization;
1617
using System.Collections.Generic;
1718
using System.Diagnostics;
18-
using System.Runtime.InteropServices;
1919
using System.Xml;
2020
using Microsoft.Azure.ServiceManagement.Common.Models;
2121
using Microsoft.WindowsAzure.Commands.ScenarioTest;
@@ -51,10 +51,10 @@ public void CustomPrinterTest_SimpleTypes()
5151
Assert.Equal(" : " + XmlConvert.ToString(ts) + Environment.NewLine, OutputClasses.CustomPrinter.Print(ts));
5252

5353
// Must be dt.ToUniversalTime().ToString("O") in the future
54-
Assert.Equal(" : " + dt + Environment.NewLine, OutputClasses.CustomPrinter.Print(dt));
54+
Assert.Equal(" : " + dt.ToString(CultureInfo.InvariantCulture) + Environment.NewLine, OutputClasses.CustomPrinter.Print(dt));
5555

5656
// Must be dtUtc.ToString("O") in the future
57-
Assert.Equal(" : " + dtUtc + Environment.NewLine, OutputClasses.CustomPrinter.Print(dtUtc));
57+
Assert.Equal(" : " + dtUtc.ToString(CultureInfo.InvariantCulture) + Environment.NewLine, OutputClasses.CustomPrinter.Print(dtUtc));
5858

5959
// Both must be string.Empty in the future
6060
Assert.Equal($" :{Environment.NewLine}", OutputClasses.CustomPrinter.Print(null));
@@ -87,7 +87,7 @@ public void CustomPrinterTest_ComplexTypes()
8787

8888
// 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
8989
Assert.Equal(
90-
expected: $"Authorization {Environment.NewLine}Action : PUT{Environment.NewLine}Role : Sender{Environment.NewLine}Scope : None{Environment.NewLine}{Environment.NewLine}Claims {Environment.NewLine} : [aud, https://management.core.windows.net/]{Environment.NewLine} : [iss, https://sts.windows.net/123456/]{Environment.NewLine} : [iat, h123445]{Environment.NewLine}Caller : caller{Environment.NewLine}Description : fake event{Environment.NewLine}Id : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527{Environment.NewLine}EventDataId :{Environment.NewLine}CorrelationId : correlation{Environment.NewLine}EventName {Environment.NewLine}Value : Start request{Environment.NewLine}LocalizedValue : Start request{Environment.NewLine}{Environment.NewLine}Category {Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}HttpRequest {Environment.NewLine}ClientRequestId : 1234{Environment.NewLine}ClientIpAddress : 123.123.123.123{Environment.NewLine}Method : PUT{Environment.NewLine}Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy{Environment.NewLine}{Environment.NewLine}Level : Informational{Environment.NewLine}ResourceGroupName : Default-Web-EastUS{Environment.NewLine}ResourceProviderName{Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}ResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1{Environment.NewLine}ResourceType :{Environment.NewLine}OperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d{Environment.NewLine}OperationName {Environment.NewLine}Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}{Environment.NewLine}Properties {Environment.NewLine}Status {Environment.NewLine}Value : Succeeded{Environment.NewLine}LocalizedValue : Succeeded{Environment.NewLine}{Environment.NewLine}SubStatus {Environment.NewLine}Value : Created{Environment.NewLine}LocalizedValue : Created{Environment.NewLine}{Environment.NewLine}EventTimestamp : 6/7/{year} 10:54:00 PM{Environment.NewLine}SubmissionTimestamp : 6/7/{year} 10:54:00 PM{Environment.NewLine}SubscriptionId :{Environment.NewLine}TenantId :{Environment.NewLine}{Environment.NewLine}",
90+
expected: $"Authorization {Environment.NewLine}Action : PUT{Environment.NewLine}Role : Sender{Environment.NewLine}Scope : None{Environment.NewLine}{Environment.NewLine}Claims {Environment.NewLine} : [aud, https://management.core.windows.net/]{Environment.NewLine} : [iss, https://sts.windows.net/123456/]{Environment.NewLine} : [iat, h123445]{Environment.NewLine}Caller : caller{Environment.NewLine}Description : fake event{Environment.NewLine}Id : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527{Environment.NewLine}EventDataId :{Environment.NewLine}CorrelationId : correlation{Environment.NewLine}EventName {Environment.NewLine}Value : Start request{Environment.NewLine}LocalizedValue : Start request{Environment.NewLine}{Environment.NewLine}Category {Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}HttpRequest {Environment.NewLine}ClientRequestId : 1234{Environment.NewLine}ClientIpAddress : 123.123.123.123{Environment.NewLine}Method : PUT{Environment.NewLine}Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy{Environment.NewLine}{Environment.NewLine}Level : Informational{Environment.NewLine}ResourceGroupName : Default-Web-EastUS{Environment.NewLine}ResourceProviderName{Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}ResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1{Environment.NewLine}ResourceType :{Environment.NewLine}OperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d{Environment.NewLine}OperationName {Environment.NewLine}Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}{Environment.NewLine}Properties {Environment.NewLine}Status {Environment.NewLine}Value : Succeeded{Environment.NewLine}LocalizedValue : Succeeded{Environment.NewLine}{Environment.NewLine}SubStatus {Environment.NewLine}Value : Created{Environment.NewLine}LocalizedValue : Created{Environment.NewLine}{Environment.NewLine}EventTimestamp : 06/07/{year} 22:54:00{Environment.NewLine}SubmissionTimestamp : 06/07/{year} 22:54:00{Environment.NewLine}SubscriptionId :{Environment.NewLine}TenantId :{Environment.NewLine}{Environment.NewLine}",
9191
actual: result);
9292

9393
dictionarySS.Add("k1", "v1");

src/Monitor/Monitor/OutputClasses/CustomPrinter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ private static void Print(object obj, string name, string currentIndent, StringB
7171
sb.Append(currentIndent);
7272
sb.Append(name);
7373
sb.Append(" : ");
74-
sb.AppendLine(obj.ToString());
74+
if (obj is DateTime dateTime)
75+
{
76+
sb.AppendLine(dateTime.ToString(System.Globalization.CultureInfo.InvariantCulture));
77+
}
78+
else
79+
{
80+
sb.AppendLine(obj.ToString());
81+
}
7582
return;
7683
}
7784

0 commit comments

Comments
 (0)