public void InstallOverrridesExistingSource()
        {
            // --- Arrange
            const string LOG1 = "_myLog1";
            const string LOG2 = "_myLog2";
            if (EventLog.Exists(LOG1)) EventLog.Delete(LOG1);
            if (EventLog.Exists(LOG2)) EventLog.Delete(LOG2);
            var data = new EventLogCreationData();
            data.Add(LOG1, "Source1");
            data.Add(LOG1, "Source2");
            data.Add(LOG2, "Source3");
            data.Add(LOG2, "Source1"); // --- Overrides LOG1

            // --- Act
            var result = WindowsEventLogManager.InstallEventLogSources(data);

            // --- Assert
            result.Errors.ShouldHaveCountOf(0);
            result.AffectedSources.ShouldHaveCountOf(2);
            result.AffectedSources[LOG1].ShouldHaveCountOf(2);
            result.AffectedSources[LOG1].ShouldContain("Source1");
            result.AffectedSources[LOG1].ShouldContain("Source2");
            result.AffectedSources[LOG2].ShouldHaveCountOf(2);
            result.AffectedSources[LOG2].ShouldContain("Source3");
            result.AffectedSources[LOG2].ShouldContain("Source1");

            EventLog.LogNameFromSourceName("Source1", ".").ShouldEqual(LOG2);
            EventLog.LogNameFromSourceName("Source2", ".").ShouldEqual(LOG1);
            EventLog.LogNameFromSourceName("Source3", ".").ShouldEqual(LOG2);
        }
        public void EventLogCreationDataAddFailesWithWrongType()
        {
            // --- Arrange
            var data = new EventLogCreationData();

            // --- Act
            data.Add(typeof(int));
        }
        public void InstallSignsSourceIssues()
        {
            // --- Arrange
            const string LOG1 = "My very long name 1";
            const string LOG2 = "My very long name 2";
            if (EventLog.Exists(LOG1)) EventLog.Delete(LOG1);
            var data = new EventLogCreationData();
            data.Add(LOG1, "Source1");
            data.Add(LOG2, "Source2");

            // --- Act
            var result = WindowsEventLogManager.InstallEventLogSources(data);
            if (EventLog.Exists(LOG1)) EventLog.Delete(LOG1);
            if (EventLog.Exists(LOG2)) EventLog.Delete(LOG2);

            // --- Assert
            result.Errors.ShouldHaveCountOf(1);
        }
        public void InstallSignsSourceIssues2()
        {
            // --- Arrange
            const string LOG1 = null;
            // ReSharper disable AssignNullToNotNullAttribute
            if (EventLog.Exists(LOG1)) EventLog.Delete(LOG1);
            // ReSharper restore AssignNullToNotNullAttribute
            var data = new EventLogCreationData();
            data.Add(LOG1, "Source1");

            // --- Act
            var result = WindowsEventLogManager.InstallEventLogSources(data);
            // ReSharper disable AssignNullToNotNullAttribute
            if (EventLog.Exists(LOG1)) EventLog.Delete(LOG1);
            // ReSharper restore AssignNullToNotNullAttribute

            // --- Assert
            result.Errors.ShouldHaveCountOf(1);
            Console.WriteLine(result.Errors.First().Value.Message);
        }
        public void RemoveWorksAsExpected()
        {
            // --- 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");

            // --- Act
            var result = WindowsEventLogManager.RemoveEventLogSources(data);

            // --- Assert
            result.Errors.ShouldHaveCountOf(0);
            result.AffectedSources.ShouldHaveCountOf(2);
            result.AffectedSources[LOG1].ShouldHaveCountOf(2);
            result.AffectedSources[LOG1].ShouldContain("Source1");
            result.AffectedSources[LOG1].ShouldContain("Source2");
            result.AffectedSources[LOG2].ShouldHaveCountOf(2);
            result.AffectedSources[LOG2].ShouldContain("Source3");
            result.AffectedSources[LOG2].ShouldContain("Source4");

            EventLog.SourceExists("Source1", ".").ShouldBeFalse();
            EventLog.SourceExists("Source2", ".").ShouldBeFalse();
            EventLog.SourceExists("Source3", ".").ShouldBeFalse();
            EventLog.SourceExists("Source4", ".").ShouldBeFalse();
        }
        public void InstallWorksAsExpectedWithMappers()
        {
            // --- Arrange
            const string LOG1 = "_myLog1";
            const string LOG2 = "_myLog2";
            if (EventLog.Exists(LOG1 + "L")) EventLog.Delete(LOG1);
            if (EventLog.Exists(LOG2 + "L")) EventLog.Delete(LOG2);
            var data = new EventLogCreationData();
            var mapper = new DummyNameMapper();
            data.Add(LOG1, "Source1", mapper, mapper);
            data.Add(LOG1, "Source2", mapper, mapper);
            data.Add(LOG2, "Source3", mapper, mapper);
            data.Add(LOG2, "Source4", mapper, mapper);

            // --- Act
            var result = WindowsEventLogManager.InstallEventLogSources(data);

            // --- Assert
            result.Errors.ShouldHaveCountOf(0);
            result.AffectedSources.ShouldHaveCountOf(2);
            result.AffectedSources[LOG1 + "L"].ShouldHaveCountOf(2);
            result.AffectedSources[LOG1 + "L"].ShouldContain("Source1L");
            result.AffectedSources[LOG1 + "L"].ShouldContain("Source2L");
            result.AffectedSources[LOG2 + "L"].ShouldHaveCountOf(2);
            result.AffectedSources[LOG2 + "L"].ShouldContain("Source3L");
            result.AffectedSources[LOG2 + "L"].ShouldContain("Source4L");

            EventLog.LogNameFromSourceName("Source1L", ".").ShouldEqual(LOG1 + "L");
            EventLog.LogNameFromSourceName("Source2L", ".").ShouldEqual(LOG1 + "L");
            EventLog.LogNameFromSourceName("Source3L", ".").ShouldEqual(LOG2 + "L");
            EventLog.LogNameFromSourceName("Source4L", ".").ShouldEqual(LOG2 + "L");
        }