Skip to content

Commit

Permalink
remove obsolete #ifdefs from unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeAndNil committed Mar 5, 2024
1 parent a88c5a5 commit af15cf8
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net8.0</TargetFrameworks>
<RootNamespace>log4net_611_main</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion src/integration-testing/log4net-672/log4net-672.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>log4net_672</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion src/integration-testing/log4net-673/log4net-673.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>log4net_673</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
Expand Down
2 changes: 1 addition & 1 deletion src/integration-testing/log4net-681/log4net-681.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>log4net_681</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
27 changes: 4 additions & 23 deletions src/log4net.Tests/Appender/AdoNetAppenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@

using System;
using System.Data;
#if NETSTANDARD1_3
using System.Reflection;
#endif
using System.Xml;
using log4net.Appender;
using log4net.Config;
#if !NETSTANDARD1_3
using log4net.Core;
#endif
using log4net.Layout;
using log4net.Repository;
using log4net.Tests.Appender.AdoNet;
Expand All @@ -48,11 +43,7 @@ public void NoBufferingTest()

AdoNetAppender adoNetAppender = new AdoNetAppender();
adoNetAppender.BufferSize = -1;
#if NETSTANDARD1_3
adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
#else
adoNetAppender.ConnectionType = "log4net.Tests.Appender.AdoNet.Log4NetConnection";
#endif
adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
adoNetAppender.ActivateOptions();

BasicConfigurator.Configure(rep, adoNetAppender);
Expand All @@ -72,11 +63,7 @@ public void BufferingTest()

AdoNetAppender adoNetAppender = new AdoNetAppender();
adoNetAppender.BufferSize = bufferSize;
#if NETSTANDARD1_3
adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
#else
adoNetAppender.ConnectionType = "log4net.Tests.Appender.AdoNet.Log4NetConnection";
#endif
adoNetAppender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
adoNetAppender.ActivateOptions();

BasicConfigurator.Configure(rep, adoNetAppender);
Expand All @@ -92,7 +79,6 @@ public void BufferingTest()
Assert.AreEqual(bufferSize + 1, Log4NetCommand.MostRecentInstance.ExecuteNonQueryCount);
}

#if !NETSTANDARD1_3
[Test]
public void WebsiteExample()
{
Expand Down Expand Up @@ -276,7 +262,6 @@ public void BufferingWebsiteExample()
param = (IDbDataParameter)command.Parameters["@exception"];
Assert.IsEmpty((string)param.Value);
}
#endif

[Test]
public void NullPropertyXmlConfig()
Expand Down Expand Up @@ -331,11 +316,7 @@ public void NullPropertyProgmaticConfig()
productIdParam.Layout = rawPropertyLayout;

AdoNetAppender appender = new AdoNetAppender();
#if NETSTANDARD1_3
appender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
#else
appender.ConnectionType = typeof(Log4NetConnection).FullName;
#endif
appender.ConnectionType = typeof(Log4NetConnection).AssemblyQualifiedName;
appender.BufferSize = -1;
appender.CommandText = "INSERT INTO Log ([productId]) VALUES (@productId)";
appender.AddParameter(productIdParam);
Expand All @@ -354,4 +335,4 @@ public void NullPropertyProgmaticConfig()
Assert.AreEqual(DBNull.Value, param.Value);
}
}
}
}
14 changes: 4 additions & 10 deletions src/log4net.Tests/Appender/DebugAppenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*
*/

#if NET_2_0

#if NET462_OR_GREATER
using System;
using System.Diagnostics;
using log4net.Appender;
Expand Down Expand Up @@ -56,9 +55,7 @@ public void NullCategoryTest()
ILog log = LogManager.GetLogger(rep.Name, GetType());
log.Debug("Message");

Assert.AreEqual(
null,
categoryTraceListener.Category);
Assert.IsNull(categoryTraceListener.Category);

Assert.IsFalse(testErrHandler.ErrorOccured);

Expand All @@ -84,9 +81,7 @@ public void EmptyStringCategoryTest()
ILog log = LogManager.GetLogger(rep.Name, GetType());
log.Debug("Message");

Assert.AreEqual(
null,
categoryTraceListener.Category);
Assert.IsNull(categoryTraceListener.Category);

Debug.Listeners.Remove(categoryTraceListener);
}
Expand Down Expand Up @@ -171,5 +166,4 @@ public void Error(string message)
}
}
}

#endif
#endif
4 changes: 2 additions & 2 deletions src/log4net.Tests/Appender/EventLogAppenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#endregion

// netstandard doesn't support EventLog
#if NET_2_0
#if NET462_OR_GREATER

using System.Diagnostics;

Expand Down Expand Up @@ -102,4 +102,4 @@ private static EventLogEntryType GetEntryType(EventLogAppender appender, Level l
}
}

#endif // NET_2_0
#endif // NET462_OR_GREATER
87 changes: 42 additions & 45 deletions src/log4net.Tests/Appender/EventRaisingAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,57 @@
*
*/

#if !NET_2_0 && !MONO_2_0

using System;

namespace log4net.Tests.Appender
{
/// <summary>
/// Provides data for the <see cref="EventRaisingAppender.LoggingEventAppended"/> event.
/// </summary>
/// <seealso cref="System.EventArgs" />
public class LoggingEventEventArgs : EventArgs
{
public log4net.Core.LoggingEvent LoggingEvent { get; private set; }
/// <summary>
/// Provides data for the <see cref="EventRaisingAppender.LoggingEventAppended"/> event.
/// </summary>
/// <seealso cref="System.EventArgs" />
public class LoggingEventEventArgs : EventArgs
{
public log4net.Core.LoggingEvent LoggingEvent { get; private set; }

public LoggingEventEventArgs(log4net.Core.LoggingEvent loggingEvent)
{
if (loggingEvent == null) throw new ArgumentNullException("loggingEvent");
LoggingEvent = loggingEvent;
}
public LoggingEventEventArgs(log4net.Core.LoggingEvent loggingEvent)
{
if (loggingEvent == null) throw new ArgumentNullException("loggingEvent");
LoggingEvent = loggingEvent;
}
}

/// <summary>
/// A log4net appender that raises an event each time a logging event is appended
/// </summary>
/// <remarks>
/// This class is intended to provide a way for test code to inspect logging
/// events as they are generated.
/// </remarks>
public class EventRaisingAppender : log4net.Appender.IAppender
{
public event EventHandler<LoggingEventEventArgs> LoggingEventAppended;
/// <summary>
/// A log4net appender that raises an event each time a logging event is appended
/// </summary>
/// <remarks>
/// This class is intended to provide a way for test code to inspect logging
/// events as they are generated.
/// </remarks>
public class EventRaisingAppender : log4net.Appender.IAppender
{
public event EventHandler<LoggingEventEventArgs> LoggingEventAppended;

protected void OnLoggingEventAppended(LoggingEventEventArgs e)
{
var loggingEventAppended = LoggingEventAppended;
if (loggingEventAppended != null)
{
loggingEventAppended(this, e);
}
}
protected void OnLoggingEventAppended(LoggingEventEventArgs e)
{
var loggingEventAppended = LoggingEventAppended;
if (loggingEventAppended != null)
{
loggingEventAppended(this, e);
}
}

public void Close()
{
}
public void Close()
{
}

public void DoAppend(log4net.Core.LoggingEvent loggingEvent)
{
OnLoggingEventAppended(new LoggingEventEventArgs(loggingEvent));
}
public void DoAppend(log4net.Core.LoggingEvent loggingEvent)
{
OnLoggingEventAppended(new LoggingEventEventArgs(loggingEvent));
}

public string Name
{
get; set;
}
public string Name
{
get; set;
}
}
#endif
}
}
5 changes: 1 addition & 4 deletions src/log4net.Tests/Appender/MemoryAppenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*
*/

#if NET_4_0 || MONO_3_5 || MONO_4_0 || NETSTANDARD

using System;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -87,5 +85,4 @@ private static ThreadStart LogMessages(string repository)
};
}
}
}
#endif
}
78 changes: 38 additions & 40 deletions src/log4net.Tests/Appender/RecursiveLoggingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
*/

#if !NET_2_0 && !MONO_2_0
using System;
using System.Globalization;
using log4net.Config;
Expand All @@ -28,53 +27,52 @@

namespace log4net.Tests.Appender
{
[TestFixture]
public class RecursiveLoggingTest
{
private EventRaisingAppender m_eventRaisingAppender;
private Repository.Hierarchy.Hierarchy m_hierarchy;
private int m_eventCount;
private ILogger m_logger;
private const int MaxRecursion = 3;

private void SetupRepository()
{
m_hierarchy = new Repository.Hierarchy.Hierarchy();
[TestFixture]
public class RecursiveLoggingTest
{
private EventRaisingAppender m_eventRaisingAppender;
private Repository.Hierarchy.Hierarchy m_hierarchy;
private int m_eventCount;
private ILogger m_logger;
private const int MaxRecursion = 3;

m_eventRaisingAppender = new EventRaisingAppender();
m_eventRaisingAppender.LoggingEventAppended += eventRaisingAppender_LoggingEventAppended;
private void SetupRepository()
{
m_hierarchy = new Repository.Hierarchy.Hierarchy();

m_hierarchy.Root.Level = Level.All;
m_hierarchy.Root.AddAppender(m_eventRaisingAppender);
m_eventRaisingAppender = new EventRaisingAppender();
m_eventRaisingAppender.LoggingEventAppended += eventRaisingAppender_LoggingEventAppended;

BasicConfigurator.Configure(m_hierarchy, m_eventRaisingAppender);
m_hierarchy.Root.Level = Level.All;
m_hierarchy.Root.AddAppender(m_eventRaisingAppender);

m_logger = m_hierarchy.GetLogger("test");
BasicConfigurator.Configure(m_hierarchy, m_eventRaisingAppender);

}
m_logger = m_hierarchy.GetLogger("test");

void eventRaisingAppender_LoggingEventAppended(object sender, LoggingEventEventArgs e)
{
if (m_eventCount < MaxRecursion && m_logger != null)
{
m_eventCount++;
string message = String.Format(CultureInfo.CurrentCulture, "Log event {0} from EventRaisingAppender", m_eventCount);
Console.WriteLine("Logging message: " + message);
m_logger.Log(typeof(RecursiveLoggingTest), Level.Warn, message, null);
}
}
}

[Test]
public void TestAllowRecursiveLoggingFromAppender()
{
SetupRepository();
void eventRaisingAppender_LoggingEventAppended(object sender, LoggingEventEventArgs e)
{
if (m_eventCount < MaxRecursion && m_logger != null)
{
m_eventCount++;
string message = String.Format(CultureInfo.CurrentCulture, "Log event {0} from EventRaisingAppender", m_eventCount);
Console.WriteLine("Logging message: " + message);
m_logger.Log(typeof(RecursiveLoggingTest), Level.Warn, message, null);
}
}

m_eventCount = 0;
m_logger.Log(typeof(RecursiveLoggingTest), Level.Warn, "Message logged", null);
[Test]
public void TestAllowRecursiveLoggingFromAppender()
{
SetupRepository();

Assert.AreEqual(MaxRecursion, m_eventCount, "Expected MaxRecursion recursive calls");
}
m_eventCount = 0;
m_logger.Log(typeof(RecursiveLoggingTest), Level.Warn, "Message logged", null);

Assert.AreEqual(MaxRecursion, m_eventCount, "Expected MaxRecursion recursive calls");
}
}
#endif

}
}
Loading

0 comments on commit af15cf8

Please sign in to comment.