Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible issue with logging for Linq Readonly tests #2965

Merged
merged 1 commit into from
Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NHibernate.Test/Linq/LinqReadonlyTestsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace NHibernate.Test.Linq
{
[SetUpFixture]
public class LinqReadonlyTestsContext
public class LinqReadonlyTestsContext : TestsContextBase
{
/// <summary>
/// Assembly to load mapping files from
Expand Down
24 changes: 2 additions & 22 deletions src/NHibernate.Test/TestsContext.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
}
31 changes: 31 additions & 0 deletions src/NHibernate.Test/TestsContextBase.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}