@@ -974,5 +974,82 @@ private static void VerifyTaskFinished(TaskFinishedEventArgs genericEvent, TaskF
974
974
newGenericEvent . TaskFile . ShouldBe ( genericEvent . TaskFile , StringCompareShould . IgnoreCase ) ; // "Expected TaskFile to Match"
975
975
newGenericEvent . TaskName . ShouldBe ( genericEvent . TaskName , StringCompareShould . IgnoreCase ) ; // "Expected TaskName to Match"
976
976
}
977
+
978
+
979
+ [ Fact ]
980
+ public void TestTelemetryEventArgs_AllProperties ( )
981
+ {
982
+ // Test using reasonable values
983
+ TelemetryEventArgs genericEvent = new TelemetryEventArgs { EventName = "Good" , Properties = new Dictionary < string , string > { { "Key" , "Value" } } } ;
984
+ genericEvent . BuildEventContext = new BuildEventContext ( 5 , 4 , 3 , 2 ) ;
985
+
986
+ TelemetryEventArgs newGenericEvent = RoundTrip ( genericEvent ) ;
987
+
988
+ VerifyGenericEventArg ( genericEvent , newGenericEvent ) ;
989
+ VerifyTelemetryEvent ( genericEvent , newGenericEvent ) ;
990
+ }
991
+
992
+ [ Fact ]
993
+ public void TestTelemetryEventArgs_NullProperties ( )
994
+ {
995
+ // Test using reasonable values
996
+ TelemetryEventArgs genericEvent = new TelemetryEventArgs { EventName = "Good" , Properties = null } ;
997
+ genericEvent . BuildEventContext = new BuildEventContext ( 5 , 4 , 3 , 2 ) ;
998
+
999
+ TelemetryEventArgs newGenericEvent = RoundTrip ( genericEvent ) ;
1000
+
1001
+ // quirk - the properties dict is initialized to an empty dictionary by the default constructor, so it's not _really_ round-trippable.
1002
+ // so we modify the source event for easier comparison here.
1003
+ genericEvent . Properties = new Dictionary < string , string > ( ) ;
1004
+
1005
+ VerifyGenericEventArg ( genericEvent , newGenericEvent ) ;
1006
+ VerifyTelemetryEvent ( genericEvent , newGenericEvent ) ;
1007
+ }
1008
+
1009
+ [ Fact ]
1010
+ public void TestTelemetryEventArgs_NullEventName ( )
1011
+ {
1012
+ // Test using null event name
1013
+ TelemetryEventArgs genericEvent = new TelemetryEventArgs { EventName = null , Properties = new Dictionary < string , string > { { "Key" , "Value" } } } ;
1014
+ genericEvent . BuildEventContext = new BuildEventContext ( 5 , 4 , 3 , 2 ) ;
1015
+
1016
+ TelemetryEventArgs newGenericEvent = RoundTrip ( genericEvent ) ;
1017
+
1018
+ VerifyGenericEventArg ( genericEvent , newGenericEvent ) ;
1019
+ VerifyTelemetryEvent ( genericEvent , newGenericEvent ) ;
1020
+ }
1021
+
1022
+ [ Fact ]
1023
+ public void TestTelemetryEventArgs_NullPropertyValue ( )
1024
+ {
1025
+ // Test using null property value name
1026
+ TelemetryEventArgs genericEvent = new TelemetryEventArgs { EventName = "Good" , Properties = new Dictionary < string , string > { { "Key" , null } } } ;
1027
+ genericEvent . BuildEventContext = new BuildEventContext ( 5 , 4 , 3 , 2 ) ;
1028
+
1029
+ TelemetryEventArgs newGenericEvent = RoundTrip ( genericEvent ) ;
1030
+
1031
+ VerifyGenericEventArg ( genericEvent , newGenericEvent ) ;
1032
+ VerifyTelemetryEvent ( genericEvent , newGenericEvent ) ;
1033
+ }
1034
+
1035
+ private T RoundTrip < T > ( T original )
1036
+ where T : BuildEventArgs , new ( )
1037
+ {
1038
+ _stream . Position = 0 ;
1039
+ original . WriteToStream ( _writer ) ;
1040
+ long streamWriteEndPosition = _stream . Position ;
1041
+
1042
+ _stream . Position = 0 ;
1043
+ var actual = new T ( ) ;
1044
+ actual . CreateFromStream ( _reader , _eventArgVersion ) ;
1045
+ _stream . Position . ShouldBe ( streamWriteEndPosition ) ; // "Stream End Positions Should Match"
1046
+ return actual ;
1047
+ }
1048
+
1049
+ private static void VerifyTelemetryEvent ( TelemetryEventArgs expected , TelemetryEventArgs actual )
1050
+ {
1051
+ actual . EventName . ShouldBe ( expected . EventName ) ;
1052
+ actual . Properties . ShouldBe ( expected . Properties ) ;
1053
+ }
977
1054
}
978
1055
}
0 commit comments