You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/09/09 23:55:29 UTC

cvs commit: logging-log4net/tests/src/Layout PatternLayoutTest.cs

nicko       2004/09/09 14:55:29

  Modified:    tests/src/Layout PatternLayoutTest.cs
  Log:
  Updated PatternLayoutTest to test Thread and Global Context properties
  
  Revision  Changes    Path
  1.3       +35 -8     logging-log4net/tests/src/Layout/PatternLayoutTest.cs
  
  Index: PatternLayoutTest.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/tests/src/Layout/PatternLayoutTest.cs,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PatternLayoutTest.cs	30 Jul 2004 14:19:11 -0000	1.2
  +++ PatternLayoutTest.cs	9 Sep 2004 21:55:29 -0000	1.3
  @@ -41,30 +41,57 @@
   	/// </remarks>
   	[TestFixture] public class PatternLayoutTest
   	{
  -		[Test] public void TestMdcPattern()
  +		[Test] public void TestThreadPropertiesPattern()
   		{
   			StringAppender stringAppender = new StringAppender();
  -			stringAppender.Layout = new PatternLayout("%mdc{prop1}");
  +			stringAppender.Layout = new PatternLayout("%property{prop1}");
   
   			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
   			BasicConfigurator.Configure(rep, stringAppender);
   
  -			ILog log1 = LogManager.GetLogger(rep.Name, "TestMdcPattern");
  +			ILog log1 = LogManager.GetLogger(rep.Name, "TestThreadProperiesPattern");
   
   			log1.Info("TestMessage");
  -			Assertion.AssertEquals("Test no mdc value set", "(null)", stringAppender.GetString());
  +			Assertion.AssertEquals("Test no thread properties value set", "(null)", stringAppender.GetString());
   			stringAppender.Reset();
   
  -			MDC.Set("prop1", "val1");
  +			ThreadContext.Properties["prop1"] = "val1";
   
   			log1.Info("TestMessage");
  -			Assertion.AssertEquals("Test thread mdc value set", "val1", stringAppender.GetString());
  +			Assertion.AssertEquals("Test thread properties value set", "val1", stringAppender.GetString());
   			stringAppender.Reset();
   
  -			MDC.Remove("prop1");
  +			ThreadContext.Properties.Remove("prop1");
   
   			log1.Info("TestMessage");
  -			Assertion.AssertEquals("Test mdc value removed", "(null)", stringAppender.GetString());
  +			Assertion.AssertEquals("Test thread properties value removed", "(null)", stringAppender.GetString());
  +			stringAppender.Reset();
  +		}
  +
  +		[Test] public void TestGlobalPropertiesPattern()
  +		{
  +			StringAppender stringAppender = new StringAppender();
  +			stringAppender.Layout = new PatternLayout("%property{prop1}");
  +
  +			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
  +			BasicConfigurator.Configure(rep, stringAppender);
  +
  +			ILog log1 = LogManager.GetLogger(rep.Name, "TestGlobalProperiesPattern");
  +
  +			log1.Info("TestMessage");
  +			Assertion.AssertEquals("Test no global properties value set", "(null)", stringAppender.GetString());
  +			stringAppender.Reset();
  +
  +			GlobalContext.Properties["prop1"] = "val1";
  +
  +			log1.Info("TestMessage");
  +			Assertion.AssertEquals("Test global properties value set", "val1", stringAppender.GetString());
  +			stringAppender.Reset();
  +
  +			GlobalContext.Properties.Remove("prop1");
  +
  +			log1.Info("TestMessage");
  +			Assertion.AssertEquals("Test global properties value removed", "(null)", stringAppender.GetString());
   			stringAppender.Reset();
   		}