Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CustomPrinter Test Case Failure in MacOs for Monitor #26261

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Monitor/Monitor.Test/CustomPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// ----------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Xml;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
Expand Down Expand Up @@ -51,10 +51,10 @@ public void CustomPrinterTest_SimpleTypes()
Assert.Equal(" : " + XmlConvert.ToString(ts) + Environment.NewLine, OutputClasses.CustomPrinter.Print(ts));

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

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

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

// 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
Assert.Equal(
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}",
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}",
actual: result);

dictionarySS.Add("k1", "v1");
Expand Down
9 changes: 8 additions & 1 deletion src/Monitor/Monitor/OutputClasses/CustomPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ private static void Print(object obj, string name, string currentIndent, StringB
sb.Append(currentIndent);
sb.Append(name);
sb.Append(" : ");
sb.AppendLine(obj.ToString());
if (obj is DateTime dateTime)
{
sb.AppendLine(dateTime.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
else
{
sb.AppendLine(obj.ToString());
}
return;
}

Expand Down