Skip to content

Commit 4cd2e50

Browse files
committed
Fixing bugs in the CustomPrinter unit tests
1 parent 0622333 commit 4cd2e50

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/ResourceManager/Insights/Commands.Insights.Test/CustomPrinterTests.cs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,22 @@ public void CustomPrinterTest_SimpleTypes()
4242
DateTime dt = DateTime.Now;
4343
DateTime dtUtc = DateTime.UtcNow;
4444

45-
Assert.Equal("1", OutputClasses.CustomPrinter.Print(x));
46-
Assert.Equal("1.2", OutputClasses.CustomPrinter.Print(y));
47-
Assert.Equal("hello", OutputClasses.CustomPrinter.Print(s));
48-
Assert.Equal("True", OutputClasses.CustomPrinter.Print(b));
49-
Assert.Equal(XmlConvert.ToString(ts), OutputClasses.CustomPrinter.Print(ts));
50-
Assert.Equal(dt.ToUniversalTime().ToString("O"), OutputClasses.CustomPrinter.Print(dt));
51-
Assert.Equal(dtUtc.ToString("O"), OutputClasses.CustomPrinter.Print(dtUtc));
52-
53-
Assert.Equal(string.Empty, OutputClasses.CustomPrinter.Print(null));
54-
Assert.Equal(string.Empty, OutputClasses.CustomPrinter.Print(""));
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(""));
5561
}
5662

5763
[Fact]
@@ -63,33 +69,43 @@ public void CustomPrinterTest_ComplexTypes()
6369
var dictionarySO = new Dictionary<string, object>();
6470
var eventData = Test.Utilities.CreateFakeEvent(id: null, newDates: false);
6571

66-
Assert.Equal("{}", OutputClasses.CustomPrinter.Print(stringList));
67-
Assert.Equal("{}", OutputClasses.CustomPrinter.Print(dictionarySS));
68-
Assert.Equal("{}", OutputClasses.CustomPrinter.Print(dictionarySO));
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));
6980

7081
string result = OutputClasses.CustomPrinter.Print(eventData);
7182
Debug.WriteLine("EventData: ");
7283
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
7386
Assert.Equal(
74-
expected: "[\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]",
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",
7588
actual: result);
7689

7790
dictionarySS.Add("k1", "v1");
7891
dictionarySS.Add("k2", "v2");
7992
result = OutputClasses.CustomPrinter.Print(dictionarySS);
8093
Debug.WriteLine("Dictionary<string, string>: ");
8194
Debug.WriteLine(result);
95+
96+
// Must be "{\r\n[k1, v1]\r\n[k2, v2]\r\n}" in the future
8297
Assert.Equal(
83-
expected: "{\r\n[k1, v1]\r\n[k2, v2]\r\n}",
98+
expected: " : [k1, v1]\r\n : [k2, v2]\r\n",
8499
actual: result);
85100

86101
dictionarySO.Add("k1", eventData);
87102
dictionarySO.Add("k2", Test.Utilities.CreateFakeEvent(id: "secondId", newDates: false));
88103
result = OutputClasses.CustomPrinter.Print(dictionarySO);
89104
Debug.WriteLine("Dictionary<string, object>: ");
90105
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
91107
Assert.Equal(
92-
expected: "{\r\n[k1, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n[k2, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n}",
108+
expected: " : [k1, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n : [k2, Microsoft.Azure.Management.Monitor.Models.EventData]\r\n",
93109
actual: result);
94110
}
95111
}

src/ResourceManager/Insights/Commands.Insights.Test/Utilities.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public static class Utilities
4343

4444
#region Events
4545

46-
public static EventData CreateFakeEvent(string id = null)
46+
public static EventData CreateFakeEvent(string id = null, bool newDates = true)
4747
{
48+
var fixedDate = new DateTime(2017, 06, 07, 22, 54, 0, DateTimeKind.Utc);
4849
return new EventData(
4950
id: id ?? "ac7d2ab5-698a-4c33-9c19-0a93d3d7f527",
5051
eventName: new LocalizableString(
@@ -67,7 +68,7 @@ public static EventData CreateFakeEvent(string id = null)
6768
correlationId: Correlation,
6869
description: "fake event",
6970
level: EventLevel.Informational,
70-
eventTimestamp: DateTime.Now,
71+
eventTimestamp: newDates ? DateTime.Now : fixedDate,
7172
operationId: "c0f2e85f-efb0-47d0-bf90-f983ec8be91d",
7273
operationName: new LocalizableString(
7374
localizedValue: "Microsoft.Resources/subscriptions/resourcegroups/deployments/write",
@@ -89,7 +90,7 @@ public static EventData CreateFakeEvent(string id = null)
8990
clientRequestId: "1234",
9091
clientIpAddress: "123.123.123.123"),
9192
properties: new Dictionary<string, string>(),
92-
submissionTimestamp: DateTime.Now);
93+
submissionTimestamp: newDates ? DateTime.Now : fixedDate);
9394
}
9495

9596
public static List<EventData> CreateListOfFakeEvents(int numEvents = 1)

0 commit comments

Comments
 (0)