public void RemoveSkipsNonExistingSources() { // --- Arrange InstallWorksAsExpected(); const string LOG1 = "_myLog1"; const string LOG2 = "_myLog2"; var data = new EventLogCreationData(); data.Add(LOG1, "Source1"); data.Add(LOG1, "Source2"); data.Add(LOG2, "Source3"); data.Add(LOG2, "Source4"); WindowsEventLogManager.InstallEventLogSources(data); EventLog.DeleteEventSource("Source1"); // --- Act data.Clear(); data.Add(LOG1, "Source1"); data.Add(LOG1, "Source2"); data.Add(LOG2, "Source3"); data.Add(LOG1, "Source4"); // --- Original owner is LOG2 var result = WindowsEventLogManager.RemoveEventLogSources(data); // --- Assert result.Errors.ShouldHaveCountOf(0); result.AffectedSources.ShouldHaveCountOf(2); result.AffectedSources[LOG1].ShouldHaveCountOf(1); result.AffectedSources[LOG1].ShouldContain("Source2"); result.AffectedSources[LOG2].ShouldHaveCountOf(1); result.AffectedSources[LOG2].ShouldContain("Source3"); EventLog.SourceExists("Source1", ".").ShouldBeFalse(); EventLog.SourceExists("Source2", ".").ShouldBeFalse(); EventLog.SourceExists("Source3", ".").ShouldBeFalse(); EventLog.SourceExists("Source4", ".").ShouldBeTrue(); }
public void InstallWorksFromAssemblyExpected() { // --- Arrange if (EventLog.Exists(SEEMPLEST_LOG)) EventLog.Delete(SEEMPLEST_LOG); if (EventLog.Exists(SEEMPLEST_LOG2)) EventLog.Delete(SEEMPLEST_LOG2); var data = new EventLogCreationData(); data.Clear(); data.MergeSourcesFromAssembly(Assembly.GetExecutingAssembly()); // --- Act var result = WindowsEventLogManager.InstallEventLogSources(data); // --- Assert result.Errors.ShouldHaveCountOf(0); result.AffectedSources.ShouldHaveCountOf(2); result.AffectedSources[SEEMPLEST_LOG].ShouldHaveCountOf(2); result.AffectedSources[SEEMPLEST_LOG].ShouldContain("Source1"); result.AffectedSources[SEEMPLEST_LOG].ShouldContain("Source2"); result.AffectedSources[SEEMPLEST_LOG2].ShouldHaveCountOf(1); result.AffectedSources[SEEMPLEST_LOG2].ShouldContain("Source3"); EventLog.LogNameFromSourceName("Source1", ".").ShouldEqual(SEEMPLEST_LOG); EventLog.LogNameFromSourceName("Source2", ".").ShouldEqual(SEEMPLEST_LOG); EventLog.LogNameFromSourceName("Source3", ".").ShouldEqual(SEEMPLEST_LOG2); }