Corrected some reviews
authorAnirudh Agnihotry <anagniho@microsoft.com>
Wed, 18 Oct 2017 20:02:28 +0000 (13:02 -0700)
committerAnirudh Agnihotry <anagniho@microsoft.com>
Wed, 18 Oct 2017 20:02:28 +0000 (13:02 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/602444f3ecba97dd05cd2468bf26a3d1e87ad3c5

src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogEntry.cs
src/libraries/System.Diagnostics.EventLog/tests/EventInstanceTests.cs
src/libraries/System.Diagnostics.EventLog/tests/EventLogTests/EventLogEntryWrittenTest.cs
src/libraries/System.Diagnostics.EventLog/tests/EventLogTests/EventLogSourceCreationTests.cs
src/libraries/System.Diagnostics.EventLog/tests/EventLogTests/EventLogTests.cs
src/libraries/System.Diagnostics.EventLog/tests/EventLogTests/EventLogWriteEntryTests.cs
src/libraries/System.Diagnostics.EventLog/tests/Helpers.cs

index 24dabc7..a266fd0 100644 (file)
@@ -157,7 +157,7 @@ namespace System.Diagnostics
                     string msg = owner.FormatMessageWrapper(dllNames, (uint)msgId, ReplacementStrings);
                     if (msg == null)
                     {
-                        StringBuilder msgBuf = new StringBuilder(SR.MessageNotFormatted + msgId + Source);
+                        StringBuilder msgBuf = new StringBuilder(SR.Format(SR.MessageNotFormatted, msgId, Source));
                         string[] strings = ReplacementStrings;
                         for (int i = 0; i < strings.Length; i++)
                         {
index 2179d45..69093bf 100644 (file)
@@ -8,7 +8,7 @@ namespace System.Diagnostics.Tests
 {
     public class EventInstanceTests
     {
-        //These ids can be any non-negative numbers
+        // These ids can be any non-negative numbers
         private const long instanceId = 57;
         private const int categoryId = 657;
 
index 6d5b3a0..1812071 100644 (file)
@@ -53,7 +53,6 @@ namespace System.Diagnostics.Tests
         [ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
         public void EntryWrittenEventRaiseDisable()
         {
-            eventCounter = 0;
             RaisingEvent("DisableEvent", nameof(EntryWrittenEventRaiseDisable), waitOnEvent: false);
             Assert.Equal(0, eventCounter);
         }
index dc2c60a..97e39b3 100644 (file)
@@ -48,7 +48,7 @@ namespace System.Diagnostics.Tests
             {
                 EventLog.CreateEventSource(source, null);
                 Assert.True(EventLog.SourceExists(source));
-                Assert.Equal(EventLog.LogNameFromSourceName(source, "."), "Application");
+                Assert.Equal("Application", EventLog.LogNameFromSourceName(source, "."));
             }
             finally
             {
@@ -134,7 +134,7 @@ namespace System.Diagnostics.Tests
         public void CategoryResourceFile_Set()
         {
             string messageFile = "ResourceFile";
-            string source = "Source" + nameof(MessageResourceFile_Set);
+            string source = "Source" + nameof(CategoryResourceFile_Set);
             string log = "MessageResourceFile";
             EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
             sourceData.CategoryResourceFile = messageFile;
@@ -145,7 +145,7 @@ namespace System.Diagnostics.Tests
         public void ParameterResourceFile_Set()
         {
             string messageFile = "ResourceFile";
-            string source = "Source" + nameof(MessageResourceFile_Set);
+            string source = "Source" + nameof(ParameterResourceFile_Set);
             string log = "MessageResourceFile";
             EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
             sourceData.ParameterResourceFile = messageFile;
@@ -155,7 +155,7 @@ namespace System.Diagnostics.Tests
         [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
         public void CategoryCount_Set()
         {
-            string source = "Source" + nameof(MessageResourceFile_Set);
+            string source = "Source" + nameof(CategoryCount_Set);
             string log = "MessageResourceFile";
             EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
             sourceData.CategoryCount = 2;
index f5a1614..d6904bc 100644 (file)
@@ -35,7 +35,7 @@ namespace System.Diagnostics.Tests
                     eventLog.Clear();
                     Assert.Equal(0, eventLog.Entries.Count);
                     eventLog.WriteEntry("Writing to event log.");
-                    Assert.Equal(eventLog.Entries.Count, 1);
+                    Assert.Equal(1,eventLog.Entries.Count);
                 }
             }
             finally
@@ -142,7 +142,6 @@ namespace System.Diagnostics.Tests
                 EventLog.DeleteEventSource(source);
                 EventLog.Delete(log);
             }
-
         }
 
         [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
@@ -169,11 +168,11 @@ namespace System.Diagnostics.Tests
                 {
                     eventLog.Source = source;
 
-                    //The second argument is only used when the overflow policy is set to OverWrite Older
+                    // The second argument is only used when the overflow policy is set to OverWrite Older
                     eventLog.ModifyOverflowPolicy(OverflowAction.DoNotOverwrite, 1);
                     Assert.Equal(OverflowAction.DoNotOverwrite, eventLog.OverflowAction);
 
-                    // -1 means overflow action is donot overrite
+                    // -1 means overflow action is donot OverWrite
                     Assert.Equal(-1, eventLog.MinimumRetentionDays);
                 }
             }
@@ -189,7 +188,7 @@ namespace System.Diagnostics.Tests
         {
             string source = "Source_" + nameof(OverflowAndRetention_Set);
             string log = "Overflow_Set";
-            int retentionDays = 30; //A number between 0 and 365 should work
+            int retentionDays = 30; // A number between 0 and 365 should work
 
             try
             {
@@ -198,7 +197,7 @@ namespace System.Diagnostics.Tests
                 {
                     eventLog.Source = source;
 
-                    //The second argument is only used when the overflow policy is set to OverWrite Older
+                    // The second argument is only used when the overflow policy is set to OverWrite Older
                     eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteOlder, retentionDays);
                     Assert.Equal(OverflowAction.OverwriteOlder, eventLog.OverflowAction);
                     Assert.Equal(retentionDays, eventLog.MinimumRetentionDays);
@@ -247,7 +246,7 @@ namespace System.Diagnostics.Tests
             string log = "DisplayName";
             string source = "Source_" + nameof(RegisterDisplayLogName);
             string messageFile = GetTestFilePath();
-            long DisplayNameMsgId = 45;
+            long DisplayNameMsgId = 42; // It could be any number
             EventSourceCreationData sourceData = new EventSourceCreationData(source, log);
 
             try
@@ -268,7 +267,6 @@ namespace System.Diagnostics.Tests
                 EventLog.DeleteEventSource(source);
                 EventLog.Delete(log);
             }
-
         }
 
         [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
@@ -281,7 +279,10 @@ namespace System.Diagnostics.Tests
         [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
         public void EventLog_EnableRaisingEvents_DefaultFalse()
         {
-            Assert.False(new EventLog("log").EnableRaisingEvents);
+            using (EventLog eventLog = new EventLog("log"))
+            {
+                Assert.False(eventLog.EnableRaisingEvents);
+            }        
         }
 
         [ConditionalFact(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
index 728c9e2..2600b1a 100644 (file)
@@ -101,7 +101,6 @@ namespace System.Diagnostics.Tests
                 eventLog.Source = source;
                 return eventLog.Entries[eventLog.Entries.Count - 1];
             }
-
         }
 
         private EventLogEntry WriteLogEntryEvent(string source, bool data = false)
@@ -137,7 +136,7 @@ namespace System.Diagnostics.Tests
 
                 Assert.Contains(message, eventLogEntry.Message);
                 Assert.Equal(source, eventLogEntry.Source);
-                Assert.StartsWith(Environment.MachineName.ToLower(), eventLogEntry.MachineName.ToLower());
+                Assert.StartsWith(Environment.MachineName.ToLowerInvariant(), eventLogEntry.MachineName.ToLowerInvariant());
                 Assert.Equal(eventLogEntry.TimeWritten, eventLogEntry.TimeGenerated);
             }
             finally
@@ -218,7 +217,7 @@ namespace System.Diagnostics.Tests
                 else
                     eventLogEntry = WriteLogEntryWithSource(source, type: true, instance: true, category: true);
 
-                //There is some prefix string already attached to the message passed
+                // There is some prefix string already attached to the message passed
                 Assert.Contains(message, eventLogEntry.Message);
                 Assert.Equal((short)eventInstance.CategoryId, eventLogEntry.CategoryNumber);
                 Assert.Equal("(" + eventLogEntry.CategoryNumber + ")", eventLogEntry.Category);
@@ -263,7 +262,6 @@ namespace System.Diagnostics.Tests
             {
                 Assert.Throws<ArgumentException>(() => eventLog.WriteEntry(message));
             }
-
         }
 
         [ConditionalTheory(typeof(Helpers), nameof(Helpers.IsElevatedAndSupportsEventLogs))]
@@ -273,7 +271,7 @@ namespace System.Diagnostics.Tests
             {
                 string source = "Source_" + nameof(WriteEntryWithInvalidType);
                 eventLog.Source = source;
-                Assert.Throws<InvalidEnumArgumentException>(() => eventLog.WriteEntry(message, (EventLogEntryType)7));
+                Assert.Throws<InvalidEnumArgumentException>(() => eventLog.WriteEntry(message, (EventLogEntryType)7)); // 7 is a random number which is not associated with any type in EventLogEntryType
             }
         }
 
@@ -357,7 +355,7 @@ namespace System.Diagnostics.Tests
             try
             {
                 EventLog.WriteEvent(source, eventInstance, rawData, null);
-                Assert.Equal(EventLog.LogNameFromSourceName(source, "."), "Application");
+                Assert.Equal("Application", EventLog.LogNameFromSourceName(source, "."));
             }
             finally
             {
index 0f499bb..1d3dc81 100644 (file)
@@ -7,5 +7,6 @@ namespace System.Diagnostics.Tests
     internal class Helpers
     {
         public static bool IsElevatedAndSupportsEventLogs { get => AdminHelpers.IsProcessElevated() && PlatformDetection.IsNotWindowsNanoServer; }
+        public static bool SupportsEventLogs { get => PlatformDetection.IsNotWindowsNanoServer; }
     }
 }