Skip to content

Commit 09898a2

Browse files
authored
Fix possible issue with logging for Linq Readonly tests (#2965)
1 parent a7a0ebb commit 09898a2

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace NHibernate.Test.Linq
1313
{
1414
[SetUpFixture]
15-
public class LinqReadonlyTestsContext
15+
public class LinqReadonlyTestsContext : TestsContextBase
1616
{
1717
/// <summary>
1818
/// Assembly to load mapping files from

src/NHibernate.Test/TestsContext.cs

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
using NUnit.Framework;
2-
using System.Configuration;
3-
using System.Reflection;
4-
using log4net;
5-
using log4net.Config;
6-
using NHibernate.Cfg;
72

83
namespace NHibernate.Test
94
{
105
[SetUpFixture]
11-
public class TestsContext
6+
public class TestsContext : TestsContextBase
127
{
13-
private static readonly Assembly TestAssembly = typeof(TestsContext).Assembly;
14-
158
[OneTimeSetUp]
169
public void RunBeforeAnyTests()
1710
{
18-
ConfigureLog4Net();
19-
20-
//When .NET Core App 2.0 tests run from VS/VSTest the entry assembly is "testhost.dll"
21-
//so we need to explicitly load the configuration
22-
if (Assembly.GetEntryAssembly() != null)
23-
{
24-
ConfigurationProvider.Current = new SystemConfigurationProvider(ConfigurationManager.OpenExeConfiguration(TestAssembly.Location));
25-
}
26-
}
27-
28-
private static void ConfigureLog4Net()
29-
{
30-
using (var log4NetXml = TestAssembly.GetManifestResourceStream("NHibernate.Test.log4net.xml"))
31-
XmlConfigurator.Configure(LogManager.GetRepository(TestAssembly), log4NetXml);
11+
//Everything is done in TestsContextBase static ctor
3212
}
3313
}
3414
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Configuration;
2+
using System.Reflection;
3+
using log4net;
4+
using log4net.Config;
5+
using NHibernate.Cfg;
6+
7+
namespace NHibernate.Test
8+
{
9+
public abstract class TestsContextBase
10+
{
11+
private static readonly Assembly TestAssembly = typeof(TestsContextBase).Assembly;
12+
13+
static TestsContextBase()
14+
{
15+
ConfigureLog4Net();
16+
17+
//When .NET Core App 2.0 tests run from VS/VSTest the entry assembly is "testhost.dll"
18+
//so we need to explicitly load the configuration
19+
if (Assembly.GetEntryAssembly() != null)
20+
{
21+
ConfigurationProvider.Current = new SystemConfigurationProvider(ConfigurationManager.OpenExeConfiguration(TestAssembly.Location));
22+
}
23+
}
24+
25+
private static void ConfigureLog4Net()
26+
{
27+
using (var log4NetXml = TestAssembly.GetManifestResourceStream("NHibernate.Test.log4net.xml"))
28+
XmlConfigurator.Configure(LogManager.GetRepository(TestAssembly), log4NetXml);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)