diff --git a/src/log4net.Tests/Core/LevelMapTest.cs b/src/log4net.Tests/Core/LevelMapTest.cs
index 234550d7..1b3e5910 100644
--- a/src/log4net.Tests/Core/LevelMapTest.cs
+++ b/src/log4net.Tests/Core/LevelMapTest.cs
@@ -21,48 +21,47 @@
using NUnit.Framework;
-namespace log4net.Tests.Core
+namespace log4net.Tests.Core;
+
+///
+/// Used for internal unit testing the class.
+///
+[TestFixture]
+public sealed class LevelMapTest
{
///
- /// Used for internal unit testing the class.
+ /// Tests the creation of a and calling its method
///
- [TestFixture]
- public sealed class LevelMapTest
+ [Test]
+ public void LevelMapCreateClear()
{
- ///
- /// Tests the creation of a and calling its method
- ///
- [Test]
- public void LevelMapCreateClear()
- {
- var map = new LevelMap();
- LevelCollection allLevels = map.AllLevels;
- Assert.AreEqual(0, allLevels.Count);
- Assert.IsNull(map["nonexistent"]);
+ var map = new LevelMap();
+ LevelCollection allLevels = map.AllLevels;
+ Assert.AreEqual(0, allLevels.Count);
+ Assert.IsNull(map["nonexistent"]);
- map.Add("level1234", 1234, "displayName");
- allLevels = map.AllLevels;
- Assert.AreEqual(1, allLevels.Count);
- Assert.AreEqual("level1234", allLevels[0].Name);
- Assert.AreEqual("displayName", allLevels[0].DisplayName);
- Assert.AreEqual(1234, allLevels[0].Value);
- Level? level1234 = map["level1234"];
- Assert.IsNotNull(level1234);
- Assert.AreSame(level1234, allLevels[0]);
+ map.Add("level1234", 1234, "displayName");
+ allLevels = map.AllLevels;
+ Assert.AreEqual(1, allLevels.Count);
+ Assert.AreEqual("level1234", allLevels[0].Name);
+ Assert.AreEqual("displayName", allLevels[0].DisplayName);
+ Assert.AreEqual(1234, allLevels[0].Value);
+ Level? level1234 = map["level1234"];
+ Assert.IsNotNull(level1234);
+ Assert.AreSame(level1234, allLevels[0]);
- Level lookupLevel = map.LookupWithDefault(level1234!);
- Assert.AreSame(level1234, lookupLevel);
+ Level lookupLevel = map.LookupWithDefault(level1234!);
+ Assert.AreSame(level1234, lookupLevel);
- var otherLevel = new Level(5678, "level5678", "display");
- lookupLevel = map.LookupWithDefault(otherLevel);
- Assert.AreSame(otherLevel, lookupLevel);
- Assert.AreSame(otherLevel, map["LEVEL5678"]);
+ var otherLevel = new Level(5678, "level5678", "display");
+ lookupLevel = map.LookupWithDefault(otherLevel);
+ Assert.AreSame(otherLevel, lookupLevel);
+ Assert.AreSame(otherLevel, map["LEVEL5678"]);
- map.Clear();
- allLevels = map.AllLevels;
- Assert.AreEqual(0, allLevels.Count);
- Assert.IsNull(map["level1234"]);
- Assert.IsNull(map["LEVEL5678"]);
- }
+ map.Clear();
+ allLevels = map.AllLevels;
+ Assert.AreEqual(0, allLevels.Count);
+ Assert.IsNull(map["level1234"]);
+ Assert.IsNull(map["LEVEL5678"]);
}
}
\ No newline at end of file
diff --git a/src/log4net.Tests/Core/LevelMappingTest.cs b/src/log4net.Tests/Core/LevelMappingTest.cs
new file mode 100644
index 00000000..6a6dec62
--- /dev/null
+++ b/src/log4net.Tests/Core/LevelMappingTest.cs
@@ -0,0 +1,124 @@
+#region Apache License
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to you under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using log4net.Core;
+using log4net.Util;
+using NUnit.Framework;
+
+namespace log4net.Tests.Core;
+
+///
+/// Used for internal unit testing the class.
+///
+[TestFixture]
+public sealed class LevelMappingTest
+{
+ ///
+ private sealed class MappingEntry : LevelMappingEntry
+ {
+ ///
+ internal MappingEntry(Level level) => Level = level;
+
+ ///
+ public override string ToString() => $"{Level?.Value} - {Level?.Name}";
+ }
+
+ ///
+ /// Tests the sorting of the entries
+ ///
+ [Test]
+ public void SortEntriesTest()
+ {
+ MappingEntry[] unsorted = [
+ new(Level.Info),
+ new(Level.Off),
+ new(Level.Emergency),
+ new(Level.Error),
+ new(Level.Alert),
+ new(Level.All),
+ new(Level.Critical),
+ new(Level.Debug),
+ new(Level.Fatal),
+ new(Level.Fine),
+ new(Level.Finer),
+ new(Level.Finest),
+ new(Level.Log4Net_Debug),
+ new(Level.Notice),
+ new(Level.Severe),
+ new(Level.Trace),
+ new(Level.Verbose),
+ new(Level.Warn)
+ ];
+ LevelMapping mapping = new();
+ foreach (MappingEntry entry in unsorted)
+ {
+ mapping.Add(entry);
+ }
+
+ List withoutDuplicates = unsorted.GroupBy(entry => entry.Level!.Value)
+ .Select(group => group.Last()).ToList();
+
+ List sorted = (List)typeof(LevelMapping)
+ .GetMethod("SortEntries", BindingFlags.NonPublic | BindingFlags.Instance)!
+ .Invoke(mapping, Array.Empty