You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by bo...@apache.org on 2018/05/29 19:56:54 UTC

logging-log4net git commit: LOG4NET-586 initial unit test

Repository: logging-log4net
Updated Branches:
  refs/heads/feature/LOG4NET-586 48dfe2864 -> 4d702b7e4


LOG4NET-586 initial unit test


Project: http://git-wip-us.apache.org/repos/asf/logging-log4net/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4net/commit/4d702b7e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4net/tree/4d702b7e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4net/diff/4d702b7e

Branch: refs/heads/feature/LOG4NET-586
Commit: 4d702b7e4856879fb17ff61bbe75741bab70081a
Parents: 48dfe28
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue May 29 21:56:28 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue May 29 21:56:28 2018 +0200

----------------------------------------------------------------------
 tests/src/Layout/XmlLayoutSchemaLog4jNSTest.cs | 90 +++++++++++++++++++++
 tests/src/log4net.Tests.csproj                 |  3 +
 2 files changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/4d702b7e/tests/src/Layout/XmlLayoutSchemaLog4jNSTest.cs
----------------------------------------------------------------------
diff --git a/tests/src/Layout/XmlLayoutSchemaLog4jNSTest.cs b/tests/src/Layout/XmlLayoutSchemaLog4jNSTest.cs
new file mode 100644
index 0000000..c491378
--- /dev/null
+++ b/tests/src/Layout/XmlLayoutSchemaLog4jNSTest.cs
@@ -0,0 +1,90 @@
+#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.IO;
+using System.Xml;
+
+using log4net.Config;
+using log4net.Core;
+using log4net.Layout;
+using log4net.Repository;
+using log4net.Tests.Appender;
+using log4net.Util;
+
+using NUnit.Framework;
+using System.Globalization;
+
+namespace log4net.Tests.Layout
+{
+	[TestFixture]
+	public class XmlLayoutSchemaLog4jNSTest
+	{
+
+		/// <summary>
+		/// Build a basic <see cref="LoggingEventData"/> object with some default values.
+		/// </summary>
+		/// <returns>A useful LoggingEventData object</returns>
+		private LoggingEventData CreateBaseEvent()
+		{
+			LoggingEventData ed = new LoggingEventData();
+			ed.Domain = "Tests";
+			ed.ExceptionString = "";
+			ed.Identity = "TestRunner";
+			ed.Level = Level.Info;
+			ed.LocationInfo = new LocationInfo(GetType());
+			ed.LoggerName = "TestLogger";
+			ed.Message = "Test message";
+			ed.ThreadName = "TestThread";
+			ed.TimeStampUtc = DateTime.Today.ToUniversalTime();
+			ed.UserName = "TestRunner";
+			ed.Properties = new PropertiesDictionary();
+
+			return ed;
+		}
+
+		private static string CreateEventNode(string message, string prefix, string ns)
+		{
+			TimeSpan timeSince1970 = DateTime.Today.ToUniversalTime() - new DateTime(1970, 1, 1);
+			return String.Format("<{2}:event logger=\"TestLogger\" timestamp=\"{0}\" level=\"INFO\" thread=\"TestThread\" xmlns:{2}=\"{3}\"><{2}:message>{1}</{2}:message><{2}:properties><{2}:data name=\"log4japp\" value=\"Tests\" /><{2}:data name=\"log4net:Identity\" value=\"TestRunner\" /><{2}:data name=\"log4net:UserName\" value=\"TestRunner\" /></{2}:properties></{2}:event>" + Environment.NewLine,
+								 XmlConvert.ToString((long)timeSince1970.TotalMilliseconds),
+								 message, prefix, ns);
+		}
+
+		private static string CreateEventNode(string message)
+		{
+			return CreateEventNode(message, "log4j", "http://logging.apache.org/log4j");
+		}
+
+		[Test]
+		public void TestBasicEventLogging()
+		{
+			ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
+			TextWriter writer = new StringWriter();
+			XmlLayoutSchemaLog4jNS layout = new XmlLayoutSchemaLog4jNS();
+			LoggingEventData evt = CreateBaseEvent();
+
+			layout.Format(writer, new LoggingEvent(null, rep, evt));
+
+			string expected = CreateEventNode("Test message");
+
+			Assert.AreEqual(expected, writer.ToString());
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/logging-log4net/blob/4d702b7e/tests/src/log4net.Tests.csproj
----------------------------------------------------------------------
diff --git a/tests/src/log4net.Tests.csproj b/tests/src/log4net.Tests.csproj
index f1768cc..7cb8eda 100644
--- a/tests/src/log4net.Tests.csproj
+++ b/tests/src/log4net.Tests.csproj
@@ -201,6 +201,9 @@
     <Compile Include="Layout\XmlLayoutTest.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="Layout\XmlLayoutSchemaLog4jNSTest">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="LoggerRepository\ConfigurationMessages.cs" />
     <Compile Include="Filter\FilterTest.cs" />
     <Compile Include="Utils.cs">