Author: nicko
Date: Sun Feb 25 08:14:29 2007
New Revision: 511537
URL: http://svn.apache.org/viewvc?view=rev&rev=511537
Log:
Cleaned up tests source code a bit, fixed incorrect capitalisation of methods,
made methods static where possible.
Fixed obsolete warnings in MONO_2_0 build.
Modified:
logging/log4net/trunk/tests/src/Appender/BufferingAppenderTest.cs
logging/log4net/trunk/tests/src/Appender/CountingAppender.cs
logging/log4net/trunk/tests/src/Appender/EventLogAppenderTest.cs
logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs
logging/log4net/trunk/tests/src/Appender/RollingFileAppenderTest.cs
logging/log4net/trunk/tests/src/Appender/StringAppender.cs
logging/log4net/trunk/tests/src/AssemblyInfo.cs
logging/log4net/trunk/tests/src/Context/ThreadContextTest.cs
logging/log4net/trunk/tests/src/Core/FixingTest.cs
logging/log4net/trunk/tests/src/Core/ShutdownTest.cs
logging/log4net/trunk/tests/src/Core/StringFormatTest.cs
logging/log4net/trunk/tests/src/Hierarchy/Logger.cs
logging/log4net/trunk/tests/src/Layout/PatternLayoutTest.cs
logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs
logging/log4net/trunk/tests/src/Util/CyclicBufferTest.cs
logging/log4net/trunk/tests/src/Util/PropertiesDictionaryTest.cs
logging/log4net/trunk/tests/src/Util/RandomStringPatternConverterTest.cs
logging/log4net/trunk/tests/src/Util/SystemInfoTest.cs
logging/log4net/trunk/tests/src/Utils.cs
Modified: logging/log4net/trunk/tests/src/Appender/BufferingAppenderTest.cs
URL:
http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/BufferingAppenderTest.cs?view=diff&rev=511537&r1=511536&r2=511537
==============================================================================
--- logging/log4net/trunk/tests/src/Appender/BufferingAppenderTest.cs (original)
+++ logging/log4net/trunk/tests/src/Appender/BufferingAppenderTest.cs Sun Feb
25 08:14:29 2007
@@ -17,8 +17,9 @@
//
#endregion
-using log4net.Core;
using log4net.Appender;
+using log4net.Config;
+using log4net.Core;
using NUnit.Framework;
@@ -30,11 +31,12 @@
/// <remarks>
/// Used for internal unit testing the <see
cref="BufferingAppenderSkeleton"/> class.
/// </remarks>
- [TestFixture] public class BufferingAppenderTest
+ [TestFixture]
+ public class BufferingAppenderTest
{
private BufferingForwardingAppender
m_bufferingForwardingAppender;
private CountingAppender m_countingAppender;
- private log4net.Repository.Hierarchy.Hierarchy m_hierarchy;
+ private Repository.Hierarchy.Hierarchy m_hierarchy;
private void SetupRepository()
@@ -57,12 +59,13 @@
m_bufferingForwardingAppender.ActivateOptions();
- log4net.Config.BasicConfigurator.Configure(m_hierarchy,
m_bufferingForwardingAppender);
+ BasicConfigurator.Configure(m_hierarchy,
m_bufferingForwardingAppender);
}
/// <summary>
/// </summary>
- [Test] public void TestSetupAppender()
+ [Test]
+ public void TestSetupAppender()
{
SetupRepository();
@@ -76,7 +79,8 @@
/// <summary>
/// </summary>
- [Test] public void TestBufferSize5()
+ [Test]
+ public void TestBufferSize5()
{
SetupRepository();
@@ -105,4 +109,4 @@
Assert.AreEqual(6, m_countingAppender.Counter, "Test 2
event in buffer. 6 event sent");
}
}
-}
+}
\ No newline at end of file
Modified: logging/log4net/trunk/tests/src/Appender/CountingAppender.cs
URL:
http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/CountingAppender.cs?view=diff&rev=511537&r1=511536&r2=511537
==============================================================================
--- logging/log4net/trunk/tests/src/Appender/CountingAppender.cs (original)
+++ logging/log4net/trunk/tests/src/Appender/CountingAppender.cs Sun Feb 25
08:14:29 2007
@@ -17,8 +17,8 @@
//
#endregion
-using log4net.Core;
using log4net.Appender;
+using log4net.Core;
namespace log4net.Tests.Appender
{
@@ -34,7 +34,6 @@
public class CountingAppender : AppenderSkeleton
{
#region Public Instance Constructors
-
/// <summary>
/// Initializes a new instance of the <see
cref="CountingAppender" /> class.
/// </summary>
@@ -42,11 +41,9 @@
{
m_counter = 0;
}
-
#endregion Public Instance Constructors
#region Public Instance Properties
-
/// <summary>
/// Returns the number of times <see cref="Append" /> has been
called.
/// </summary>
@@ -57,7 +54,6 @@
{
get { return m_counter; }
}
-
#endregion Public Instance Properties
/// <summary>
@@ -69,25 +65,21 @@
}
#region Override implementation of AppenderSkeleton
-
/// <summary>
/// Registers how many times the method has been called.
/// </summary>
/// <param name="logEvent">The logging event.</param>
- override protected void Append(LoggingEvent logEvent)
+ protected override void Append(LoggingEvent logEvent)
{
m_counter++;
}
-
#endregion Override implementation of AppenderSkeleton
#region Private Instance Fields
-
/// <summary>
/// The number of times <see cref="Append" /> has been called.
/// </summary>
private int m_counter;
-
#endregion Private Instance Fields
}
-}
+}
\ No newline at end of file
Modified: logging/log4net/trunk/tests/src/Appender/EventLogAppenderTest.cs
URL:
http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/EventLogAppenderTest.cs?view=diff&rev=511537&r1=511536&r2=511537
==============================================================================
--- logging/log4net/trunk/tests/src/Appender/EventLogAppenderTest.cs (original)
+++ logging/log4net/trunk/tests/src/Appender/EventLogAppenderTest.cs Sun Feb 25
08:14:29 2007
@@ -17,8 +17,10 @@
//
#endregion
-using log4net.Core;
+using System.Diagnostics;
+
using log4net.Appender;
+using log4net.Core;
using NUnit.Framework;
@@ -30,54 +32,55 @@
/// <remarks>
/// Used for internal unit testing the <see cref="EventLogAppender"/>
class.
/// </remarks>
- [TestFixture] public class EventLogAppenderTest
+ [TestFixture]
+ public class EventLogAppenderTest
{
/// <summary>
/// Verifies that for each event log level, the correct system
/// event log enumeration is returned
/// </summary>
- [Test] public void TestGetEntryType()
+ [Test]
+ public void TestGetEntryType()
{
EventLogAppender eventAppender = new EventLogAppender();
eventAppender.ActivateOptions();
Assert.AreEqual(
-
System.Diagnostics.EventLogEntryType.Information,
- GetEntryType( eventAppender, Level.All ) );
+ EventLogEntryType.Information,
+ GetEntryType(eventAppender, Level.All));
Assert.AreEqual(
-
System.Diagnostics.EventLogEntryType.Information,
- GetEntryType( eventAppender, Level.Debug ) );
+ EventLogEntryType.Information,
+ GetEntryType(eventAppender, Level.Debug));
Assert.AreEqual(
-
System.Diagnostics.EventLogEntryType.Information,
- GetEntryType( eventAppender, Level.Info ) );
+ EventLogEntryType.Information,
+ GetEntryType(eventAppender, Level.Info));
Assert.AreEqual(
- System.Diagnostics.EventLogEntryType.Warning,
- GetEntryType( eventAppender, Level.Warn ) );
+ EventLogEntryType.Warning,
+ GetEntryType(eventAppender, Level.Warn));
Assert.AreEqual(
- System.Diagnostics.EventLogEntryType.Error,
- GetEntryType( eventAppender, Level.Error ) );
+ EventLogEntryType.Error,
+ GetEntryType(eventAppender, Level.Error));
Assert.AreEqual(
- System.Diagnostics.EventLogEntryType.Error,
- GetEntryType( eventAppender, Level.Fatal ) );
+ EventLogEntryType.Error,
+ GetEntryType(eventAppender, Level.Fatal));
Assert.AreEqual(
- System.Diagnostics.EventLogEntryType.Error,
- GetEntryType( eventAppender, Level.Off ) );
-
+ EventLogEntryType.Error,
+ GetEntryType(eventAppender, Level.Off));
}
//
// Helper functions to dig into the appender
//
- private static System.Diagnostics.EventLogEntryType
GetEntryType(EventLogAppender appender, Level level)
+ private static EventLogEntryType GetEntryType(EventLogAppender
appender, Level level)
{
- return
(System.Diagnostics.EventLogEntryType)Utils.InvokeMethod(appender,
"GetEntryType", level);
+ return (EventLogEntryType)Utils.InvokeMethod(appender,
"GetEntryType", level);
}
}
-}
+}
\ No newline at end of file
Modified: logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs
URL:
http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs?view=diff&rev=511537&r1=511536&r2=511537
==============================================================================
--- logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs (original)
+++ logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs Sun Feb 25
08:14:29 2007
@@ -19,13 +19,17 @@
using System;
using System.Collections;
+using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
+using System.Threading;
-using log4net.Core;
using log4net.Appender;
-using IRemoteLoggingSink =
log4net.Appender.RemotingAppender.IRemoteLoggingSink;
+using log4net.Core;
+using log4net.Repository.Hierarchy;
+using log4net.Tests.Appender.Remoting.Data;
+using log4net.Tests.Appender.Remoting.UserInterfaces;
using NUnit.Framework;
@@ -37,22 +41,24 @@
/// <remarks>
/// Used for internal unit testing the <see cref="RemotingAppender"/>
class.
/// </remarks>
- [TestFixture] public class RemotingAppenderTest
+ [TestFixture]
+ public class RemotingAppenderTest
{
private IChannel m_remotingChannel = null;
/// <summary>
/// Test that the Message property is correctly remoted
/// </summary>
- [Test] public void TestRemotedMessage()
+ [Test]
+ public void TestRemotedMessage()
{
// Setup the remoting appender
ConfigureRootAppender(FixFlags.Partial);
RemoteLoggingSinkImpl.Instance.Reset();
- log4net.Repository.Hierarchy.Logger root = null;
- root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
+ Logger root;
+ root =
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
string testMessage = string.Format("test message [ {0}
]", (new Random()).Next());
@@ -60,7 +66,7 @@
root.Log(Level.Debug, testMessage, null);
// Wait for the remoted object to be delivered
- System.Threading.Thread.Sleep(1000);
+ Thread.Sleep(1000);
LoggingEvent[] events =
RemoteLoggingSinkImpl.Instance.Events;
Assert.AreEqual(1, events.Length, "Expect to receive 1
remoted event");
@@ -71,21 +77,22 @@
/// <summary>
/// Test that the UserName property is not remoted when doing a
Fix.Partial
/// </summary>
- [Test] public void TestPartialFix()
+ [Test]
+ public void TestPartialFix()
{
// Setup the remoting appender
ConfigureRootAppender(FixFlags.Partial);
RemoteLoggingSinkImpl.Instance.Reset();
- log4net.Repository.Hierarchy.Logger root = null;
- root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
+ Logger root;
+ root =
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
// Log a message that will be remoted
root.Log(Level.Debug, "test message", null);
// Wait for the remoted object to be delivered
- System.Threading.Thread.Sleep(1000);
+ Thread.Sleep(1000);
LoggingEvent[] events =
RemoteLoggingSinkImpl.Instance.Events;
Assert.AreEqual(1, events.Length, "Expect to receive 1
remoted event");
@@ -99,21 +106,22 @@
/// <summary>
/// Test that the UserName property is remoted when doing a
Fix.All
/// </summary>
- [Test] public void TestFullFix()
+ [Test]
+ public void TestFullFix()
{
// Setup the remoting appender
ConfigureRootAppender(FixFlags.All);
RemoteLoggingSinkImpl.Instance.Reset();
- log4net.Repository.Hierarchy.Logger root = null;
- root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
+ Logger root;
+ root =
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
// Log a message that will be remoted
root.Log(Level.Debug, "test message", null);
// Wait for the remoted object to be delivered
- System.Threading.Thread.Sleep(1000);
+ Thread.Sleep(1000);
LoggingEvent[] events =
RemoteLoggingSinkImpl.Instance.Events;
Assert.AreEqual(1, events.Length, "Expect to receive 1
remoted event");
@@ -127,25 +135,28 @@
/// <summary>
/// Test that the Message property is correctly remoted
/// </summary>
- [Test] public void TestRemotedMessageNdcPushPop()
+ [Test]
+ public void TestRemotedMessageNdcPushPop()
{
// Setup the remoting appender
ConfigureRootAppender(FixFlags.Partial);
RemoteLoggingSinkImpl.Instance.Reset();
- log4net.Repository.Hierarchy.Logger root = null;
- root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
+ Logger root;
+ root =
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
string testMessage = string.Format("test message [ {0}
]", (new Random()).Next());
- using(NDC.Push("value")) {}
+ using(NDC.Push("value"))
+ {
+ }
// Log a message that will be remoted
root.Log(Level.Debug, testMessage, null);
// Wait for the remoted object to be delivered
- System.Threading.Thread.Sleep(1000);
+ Thread.Sleep(1000);
LoggingEvent[] events =
RemoteLoggingSinkImpl.Instance.Events;
Assert.AreEqual(1, events.Length, "Expect to receive 1
remoted event");
@@ -153,7 +164,8 @@
Assert.AreEqual(testMessage, events[0].RenderedMessage,
"Expect Message match after remoting event");
}
- [Test] public void TestNestedNdc()
+ [Test]
+ public void TestNestedNdc()
{
// This test can suffer from timing and ordering issues
as the RemotingAppender does dispatch events asynchronously
@@ -162,12 +174,12 @@
RemoteLoggingSinkImpl.Instance.Reset();
-
log4net.Tests.Appender.Remoting.UserInterfaces.TestService t;
- t = new
log4net.Tests.Appender.Remoting.UserInterfaces.TestService();
+ TestService t;
+ t = new TestService();
t.Test();
// Wait for the remoted objects to be delivered
- System.Threading.Thread.Sleep(3000);
+ Thread.Sleep(3000);
LoggingEvent[] events =
RemoteLoggingSinkImpl.Instance.Events;
Assert.AreEqual(5, events.Length, "Expect to receive 5
remoted event");
@@ -186,7 +198,6 @@
}
-
private void RegisterRemotingServerChannel()
{
if (m_remotingChannel == null)
@@ -196,7 +207,7 @@
// Setup remoting server
try
{
-#if NET_2_0
+#if NET_2_0 || MONO_2_0
ChannelServices.RegisterChannel(m_remotingChannel, false);
#else
ChannelServices.RegisterChannel(m_remotingChannel);
@@ -207,7 +218,7 @@
}
// Marshal the sink object
-
RemotingServices.Marshal(RemoteLoggingSinkImpl.Instance, "LoggingSink",
typeof(IRemoteLoggingSink));
+
RemotingServices.Marshal(RemoteLoggingSinkImpl.Instance, "LoggingSink",
typeof(RemotingAppender.IRemoteLoggingSink));
}
}
@@ -215,19 +226,20 @@
/// Shuts down any loggers in the hierarchy, along
/// with all appenders.
/// </summary>
- private void ResetRepository()
+ private static void ResetRepository()
{
// Regular users should not use the clear method
lightly!
LogManager.GetRepository().ResetConfiguration();
LogManager.GetRepository().Shutdown();
-
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Clear();
+
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Clear();
}
/// <summary>
/// Any initialization that happens before each test can
/// go here
/// </summary>
- [SetUp] public void SetUp()
+ [SetUp]
+ public void SetUp()
{
ResetRepository();
RegisterRemotingServerChannel();
@@ -236,7 +248,8 @@
/// <summary>
/// Any steps that happen after each test go here
/// </summary>
- [TearDown] public void TearDown()
+ [TearDown]
+ public void TearDown()
{
ResetRepository();
}
@@ -244,16 +257,16 @@
/// <summary>
/// Configures the root appender for counting and rolling
/// </summary>
- private void ConfigureRootAppender(FixFlags fixFlags)
+ private static void ConfigureRootAppender(FixFlags fixFlags)
{
- log4net.Repository.Hierarchy.Logger root = null;
- root =
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
+ Logger root;
+ root =
((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root;
root.Level = Level.Debug;
root.AddAppender(CreateAppender(fixFlags));
root.Repository.Configured = true;
}
- private RemotingAppender CreateAppender(FixFlags fixFlags)
+ private static RemotingAppender CreateAppender(FixFlags
fixFlags)
{
RemotingAppender appender = new RemotingAppender();
appender.Sink = "tcp://localhost:8085/LoggingSink";
@@ -266,22 +279,19 @@
return appender;
}
- public class RemoteLoggingSinkImpl : MarshalByRefObject,
IRemoteLoggingSink
+ public class RemoteLoggingSinkImpl : MarshalByRefObject,
RemotingAppender.IRemoteLoggingSink
{
public static readonly RemoteLoggingSinkImpl Instance =
new RemoteLoggingSinkImpl();
private ArrayList m_events = new ArrayList();
#region Public Instance Constructors
-
private RemoteLoggingSinkImpl()
{
}
-
#endregion Public Instance Constructors
#region Implementation of IRemoteLoggingSink
-
/// <summary>
/// Logs the events to to an internal buffer
/// </summary>
@@ -295,11 +305,9 @@
{
m_events.AddRange(events);
}
-
#endregion Implementation of IRemoteLoggingSink
#region Override implementation of MarshalByRefObject
-
/// <summary>
/// Obtains a lifetime service object to control the
lifetime
/// policy for this instance.
@@ -312,7 +320,6 @@
{
return null;
}
-
#endregion Override implementation of MarshalByRefObject
public void Reset()
@@ -322,10 +329,7 @@
public LoggingEvent[] Events
{
- get
- {
- return
(LoggingEvent[])m_events.ToArray(typeof(LoggingEvent));
- }
+ get { return
(LoggingEvent[])m_events.ToArray(typeof(LoggingEvent)); }
}
}
@@ -341,62 +345,65 @@
}
// helper for TestNestedNdc
-namespace log4net.Tests.Appender.Remoting.UserInterfaces
+
+namespace log4net.Tests.Appender.Remoting.UserInterfaces
{
- public class TestService
+ public class TestService
{
- static ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public void Test()
+ public void Test()
{
log.Info("begin test");
- System.Threading.Thread.Sleep(100);
+ Thread.Sleep(100);
Feature f = new Feature();
f.Test();
log.Info("end test");
- System.Threading.Thread.Sleep(100);
+ Thread.Sleep(100);
}
}
}
+
// helper for TestNestedNdc
-namespace log4net.Tests.Appender.Remoting
+
+namespace log4net.Tests.Appender.Remoting
{
- public class Feature
+ public class Feature
{
- static ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public void Test()
+ public void Test()
{
- using(NDC.Push("test1"))
+ using(NDC.Push("test1"))
{
log.Info("feature");
- System.Threading.Thread.Sleep(100);
+ Thread.Sleep(100);
- log4net.Tests.Appender.Remoting.Data.Dal d =
new log4net.Tests.Appender.Remoting.Data.Dal();
+ Dal d = new Dal();
d.Test();
log.Info("return");
- System.Threading.Thread.Sleep(100);
+ Thread.Sleep(100);
}
}
}
}
+
// helper for TestNestedNdc
-namespace log4net.Tests.Appender.Remoting.Data
+
+namespace log4net.Tests.Appender.Remoting.Data
{
- public class Dal
+ public class Dal
{
- static ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+ private static ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- public void Test()
+ public void Test()
{
- using(NDC.Push("test2"))
+ using(NDC.Push("test2"))
{
log.Info("return");
- System.Threading.Thread.Sleep(100);
+ Thread.Sleep(100);
}
}
}
-}
-
-
+}
\ No newline at end of file