From 6c3ee828fc682f62f6fed4b7656d0a0d6da552b5 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Tue, 28 Dec 2021 14:17:56 +0200 Subject: [PATCH] Fix possible issue with logging for Linq Readonly tests --- .../Linq/LinqReadonlyTestsContext.cs | 2 +- src/NHibernate.Test/TestsContext.cs | 24 ++------------ src/NHibernate.Test/TestsContextBase.cs | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 src/NHibernate.Test/TestsContextBase.cs diff --git a/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs b/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs index d5d0a6bd71f..aed51a8e15c 100644 --- a/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs +++ b/src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs @@ -12,7 +12,7 @@ namespace NHibernate.Test.Linq { [SetUpFixture] - public class LinqReadonlyTestsContext + public class LinqReadonlyTestsContext : TestsContextBase { /// /// Assembly to load mapping files from diff --git a/src/NHibernate.Test/TestsContext.cs b/src/NHibernate.Test/TestsContext.cs index e80cca726aa..236759acb5c 100644 --- a/src/NHibernate.Test/TestsContext.cs +++ b/src/NHibernate.Test/TestsContext.cs @@ -1,34 +1,14 @@ using NUnit.Framework; -using System.Configuration; -using System.Reflection; -using log4net; -using log4net.Config; -using NHibernate.Cfg; namespace NHibernate.Test { [SetUpFixture] - public class TestsContext + public class TestsContext : TestsContextBase { - private static readonly Assembly TestAssembly = typeof(TestsContext).Assembly; - [OneTimeSetUp] public void RunBeforeAnyTests() { - ConfigureLog4Net(); - - //When .NET Core App 2.0 tests run from VS/VSTest the entry assembly is "testhost.dll" - //so we need to explicitly load the configuration - if (Assembly.GetEntryAssembly() != null) - { - ConfigurationProvider.Current = new SystemConfigurationProvider(ConfigurationManager.OpenExeConfiguration(TestAssembly.Location)); - } - } - - private static void ConfigureLog4Net() - { - using (var log4NetXml = TestAssembly.GetManifestResourceStream("NHibernate.Test.log4net.xml")) - XmlConfigurator.Configure(LogManager.GetRepository(TestAssembly), log4NetXml); + //Everything is done in TestsContextBase static ctor } } } diff --git a/src/NHibernate.Test/TestsContextBase.cs b/src/NHibernate.Test/TestsContextBase.cs new file mode 100644 index 00000000000..15953fea8f0 --- /dev/null +++ b/src/NHibernate.Test/TestsContextBase.cs @@ -0,0 +1,31 @@ +using System.Configuration; +using System.Reflection; +using log4net; +using log4net.Config; +using NHibernate.Cfg; + +namespace NHibernate.Test +{ + public abstract class TestsContextBase + { + private static readonly Assembly TestAssembly = typeof(TestsContextBase).Assembly; + + static TestsContextBase() + { + ConfigureLog4Net(); + + //When .NET Core App 2.0 tests run from VS/VSTest the entry assembly is "testhost.dll" + //so we need to explicitly load the configuration + if (Assembly.GetEntryAssembly() != null) + { + ConfigurationProvider.Current = new SystemConfigurationProvider(ConfigurationManager.OpenExeConfiguration(TestAssembly.Location)); + } + } + + private static void ConfigureLog4Net() + { + using (var log4NetXml = TestAssembly.GetManifestResourceStream("NHibernate.Test.log4net.xml")) + XmlConfigurator.Configure(LogManager.GetRepository(TestAssembly), log4NetXml); + } + } +}