1+ #region Apache License
2+ //
3+ // Licensed to the Apache Software Foundation (ASF) under one or more
4+ // contributor license agreements. See the NOTICE file distributed with
5+ // this work for additional information regarding copyright ownership.
6+ // The ASF licenses this file to you under the Apache License, Version 2.0
7+ // (the "License"); you may not use this file except in compliance with
8+ // the License. You may obtain a copy of the License at
9+ //
10+ // http://www.apache.org/licenses/LICENSE-2.0
11+ //
12+ // Unless required by applicable law or agreed to in writing, software
13+ // distributed under the License is distributed on an "AS IS" BASIS,
14+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ // See the License for the specific language governing permissions and
16+ // limitations under the License.
17+ //
18+ #endregion
19+
20+ using System ;
21+ using System . Runtime . CompilerServices ;
22+ using log4net . Core ;
23+
24+ using NUnit . Framework ;
25+
26+ namespace log4net . Tests . Core
27+ {
28+ /// <summary>
29+ /// Used for internal unit testing the <see cref="Level"/> class.
30+ /// </summary>
31+ [ TestFixture ]
32+ public sealed class LevelTest
33+ {
34+ /// <summary>
35+ /// Tests the comparison between two <see cref="Level"/>s
36+ /// </summary>
37+ [ Test ]
38+ public void LevelCompare ( )
39+ {
40+ Level ? nullLevel = null ;
41+ int ? nullInt = null ;
42+ Compare ( nullInt , nullInt , nullLevel , nullLevel ) ;
43+ Compare ( nullInt , Level . Verbose . Value , nullLevel , Level . Verbose ) ;
44+ Compare ( Level . Verbose . Value , nullInt , Level . Verbose , nullLevel ) ;
45+ Compare ( Level . Verbose . Value , Level . Verbose . Value , Level . Verbose , Level . Verbose ) ;
46+ Compare ( Level . Debug . Value , Level . Verbose . Value , Level . Debug , Level . Verbose ) ;
47+ }
48+
49+ private static void Compare ( int ? leftInt , int ? rightInt , Level ? left , Level ? right ,
50+ [ CallerArgumentExpression ( nameof ( left ) ) ] string leftName = "" ,
51+ [ CallerArgumentExpression ( nameof ( right ) ) ] string rightName = "" )
52+ {
53+ Assert . AreEqual ( leftInt < rightInt , left < right , "{0} < {1}" , leftName , rightName ) ;
54+ Assert . AreEqual ( leftInt > rightInt , left > right , "{0} > {1}" , leftName , rightName ) ;
55+ Assert . AreEqual ( leftInt <= rightInt , left <= right , "{0} <= {1}" , leftName , rightName ) ;
56+ Assert . AreEqual ( leftInt >= rightInt , left >= right , "{0} >= {1}" , leftName , rightName ) ;
57+ Assert . AreEqual ( leftInt == rightInt , left == right , "{0} == {1}" , leftName , rightName ) ;
58+ Assert . AreEqual ( leftInt != rightInt , left != right , "{0} != {1}" , leftName , rightName ) ;
59+ Assert . AreEqual ( leftInt ? . Equals ( rightInt ) , left ? . Equals ( right ) , "{0}?.Equals({1})" , leftName , rightName ) ;
60+ if ( leftInt is not null )
61+ {
62+ if ( rightInt is not null )
63+ {
64+ Assert . AreEqual ( leftInt ? . CompareTo ( rightInt ) , left ? . CompareTo ( right ! ) , "{0}?.CompareTo({1})" , leftName , rightName ) ;
65+ }
66+ else
67+ {
68+ Assert . Throws < ArgumentNullException > ( ( ) => left ! . CompareTo ( right ! ) ) ;
69+ }
70+ }
71+ }
72+ }
73+ }
0 commit comments