Skip to content

Commit 9246d56

Browse files
committed
NH-3807 - More test assembly config file fixes for .NET Core.
1 parent 29f8c71 commit 9246d56

File tree

9 files changed

+62
-17
lines changed

9 files changed

+62
-17
lines changed

src/NHibernate.Test/CfgTest/ConfigurationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void InvalidXmlInHbmFile()
236236
Configuration cfg = new Configuration();
237237
try
238238
{
239-
cfg.Configure();
239+
cfg.Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
240240
cfg.AddXmlFile("invalid.hbm.xml");
241241
}
242242
catch (HibernateException)

src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void InvalidConfig()
2424
Assert.Throws<HibernateConfigException>(()=>new HibernateConfiguration(xtr));
2525
}
2626

27+
#if !NETCOREAPP2_0
2728
[Test]
2829
public void FromAppConfigTest()
2930
{
@@ -32,11 +33,21 @@ public void FromAppConfigTest()
3233
Assert.IsTrue(hc.UseReflectionOptimizer);
3334
Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name);
3435
}
36+
#endif
37+
38+
[Test]
39+
public void FromConfigForExePathTest()
40+
{
41+
IHibernateConfiguration hc = TestsContext.GetTestAssemblyHibernateConfiguration();
42+
Assert.That(hc.ByteCodeProviderType, Is.EqualTo("lcg"));
43+
Assert.IsTrue(hc.UseReflectionOptimizer);
44+
Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name);
45+
}
3546

3647
[Test]
3748
public void IgnoreSystemOutOfAppConfig()
3849
{
39-
IHibernateConfiguration hc = ConfigurationManager.GetSection("hibernate-configuration") as IHibernateConfiguration;
50+
IHibernateConfiguration hc = TestsContext.GetTestAssemblyHibernateConfiguration();
4051
string xml =
4152
@"<?xml version='1.0' encoding='utf-8' ?>
4253
<hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'>

src/NHibernate.Test/CfgTest/DefaultFlushModeFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void CanSetDefaultFlushModeThroughXmlConfiguration()
3434
[Test]
3535
public void CanSetDefaultFlushModeThroughStandardConfiguration()
3636
{
37-
var cfg = new Configuration().Configure();
37+
var cfg = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
3838
cfg.Properties[Environment.DefaultFlushMode] = FlushMode.Always.ToString();
3939

4040
using (var sessionFactory = cfg.BuildSessionFactory())
@@ -60,7 +60,7 @@ public void CanSetDefaultFlushModeThroughStandardConfiguration()
6060
public void CanSetDefaultFlushModeThroughLoquaciousConfiguration()
6161
{
6262
var cfg = new Configuration()
63-
.Configure();
63+
.Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
6464

6565
cfg
6666
.SessionFactory()
@@ -74,7 +74,7 @@ public void CanSetDefaultFlushModeThroughLoquaciousConfiguration()
7474
}
7575
}
7676

77-
cfg.Configure()
77+
cfg.Configure(TestsContext.GetTestAssemblyHibernateConfiguration())
7878
.SessionFactory()
7979
.DefaultFlushMode(FlushMode.Commit);
8080

src/NHibernate.Test/CfgTest/Loquacious/EntityCacheConfigurationFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class EntityCacheConfigurationFixture
1212
[Test]
1313
public void ConfigureCacheOfClass()
1414
{
15-
Configuration configure = new Configuration().Configure();
15+
Configuration configure = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
1616
configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
1717

1818
configure.EntityCache<EntityToCache>(ce =>
@@ -30,7 +30,7 @@ public void ConfigureCacheOfClass()
3030
[Test]
3131
public void ConfigureCacheOfCollection()
3232
{
33-
Configuration configure = new Configuration().Configure();
33+
Configuration configure = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
3434
configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
3535

3636
configure.EntityCache<EntityToCache>(ce =>
@@ -54,7 +54,7 @@ public void ConfigureCacheOfCollection()
5454
[Test]
5555
public void ConfigureCacheOfCollectionWithOutEntity()
5656
{
57-
Configuration configure = new Configuration().Configure();
57+
Configuration configure = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
5858
configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
5959

6060
configure.EntityCache<EntityToCache>(ce => ce.Collection(e => e.Elements, cc =>
@@ -71,7 +71,7 @@ public void ConfigureCacheOfCollectionWithOutEntity()
7171
[Test]
7272
public void NotAllowRelatedCollections()
7373
{
74-
Configuration configure = new Configuration().Configure();
74+
Configuration configure = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
7575
configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly);
7676

7777
var exception =

src/NHibernate.Test/MappingByCode/IntegrationTests/NH3667/MapFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void TestMapElementElement()
4444
[Test]
4545
public void TestMapEntityEntity()
4646
{
47-
var cfg = new Configuration().Configure();
47+
var cfg = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
4848
var mapper = new ModelMapper();
4949

5050
mapper.Class<ClassWithMapEntityEntity>(
@@ -123,7 +123,7 @@ public void TestMapEntityElement()
123123
[Test]
124124
public void TestMapElementEntity()
125125
{
126-
var cfg = new Configuration().Configure();
126+
var cfg = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
127127
var mapper = new ModelMapper();
128128

129129
mapper.Class<ClassWithMapElementEntity>(

src/NHibernate.Test/NHSpecificTest/NH1587/Fixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Bug()
1717
if (TestConfigurationHelper.hibernateConfigFile != null)
1818
cfg.Configure(TestConfigurationHelper.hibernateConfigFile);
1919
cfg.AddResource("NHibernate.Test.NHSpecificTest.NH1587.Mappings.hbm.xml", GetType().Assembly);
20-
cfg.Configure();
20+
cfg.Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
2121

2222
bool useOptimizer= false;
2323
using (var ls = new LogSpy("NHibernate.Tuple.Entity.PocoEntityTuplizer"))
@@ -35,4 +35,4 @@ public void Bug()
3535
Assert.That(useOptimizer);
3636
}
3737
}
38-
}
38+
}

src/NHibernate.Test/NHSpecificTest/NH1867/AddMappingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public class B
4242
[Test]
4343
public void NestedWithinNonGeneric()
4444
{
45-
var configuration = new Configuration().Configure();
45+
var configuration = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
4646
configuration.AddXml(string.Format(mappingTemplate, typeof(A).FullName, typeof(A.B).FullName));
4747
}
4848

4949
[Test]
5050
public void NestedWithinGeneric()
5151
{
52-
var configuration = new Configuration().Configure();
52+
var configuration = new Configuration().Configure(TestsContext.GetTestAssemblyHibernateConfiguration());
5353
configuration.AddXml(string.Format(mappingTemplate, typeof(A<int>).FullName, typeof(A<int>.B).FullName));
5454
}
5555
}

src/NHibernate.Test/TestsContext.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using NHibernate.Cfg.ConfigurationSchema;
66
using NUnit.Framework;
7+
using log4net.Repository.Hierarchy;
78

89
namespace NHibernate.Test
910
{
@@ -13,15 +14,43 @@ public class TestsContext
1314
[OneTimeSetUp]
1415
public void RunBeforeAnyTests()
1516
{
17+
HibernateConfiguration config = GetTestAssemblyHibernateConfiguration();
18+
NHibernate.Cfg.Environment.InitializeGlobalProperties(config);
19+
20+
ConfigureLog4Net();
21+
}
22+
23+
public static HibernateConfiguration GetTestAssemblyHibernateConfiguration()
24+
{
25+
HibernateConfiguration config;
1626
string assemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"NHibernate.Test.dll");
1727
var configuration = ConfigurationManager.OpenExeConfiguration(assemblyPath);
1828
ConfigurationSection configSection = configuration.GetSection(CfgXmlHelper.CfgSectionName);
1929

2030
using (XmlTextReader reader = new XmlTextReader(configSection.SectionInformation.GetRawXml(), XmlNodeType.Document, null))
2131
{
22-
HibernateConfiguration config = new HibernateConfiguration(reader);
23-
NHibernate.Cfg.Environment.InitializeGlobalProperties(config);
32+
config = new HibernateConfiguration(reader);
2433
}
34+
35+
return config;
36+
}
37+
38+
private static void ConfigureLog4Net()
39+
{
40+
var hierarchy = (Hierarchy)log4net.LogManager.GetRepository(typeof(TestsContext).Assembly);
41+
42+
var consoleAppender = new log4net.Appender.ConsoleAppender()
43+
{
44+
Layout = new log4net.Layout.PatternLayout("%d{ABSOLUTE} %-5p %c{1}:%L - %m%n"),
45+
};
46+
47+
((Logger)hierarchy.GetLogger("NHibernate.Hql.Ast.ANTLR")).Level = log4net.Core.Level.Off;
48+
((Logger)hierarchy.GetLogger("NHibernate.SQL")).Level = log4net.Core.Level.Off;
49+
((Logger)hierarchy.GetLogger("NHibernate.AdoNet.AbstractBatcher")).Level = log4net.Core.Level.Off;
50+
((Logger)hierarchy.GetLogger("NHibernate.Tool.hbm2ddl.SchemaExport")).Level = log4net.Core.Level.Error;
51+
hierarchy.Root.Level = log4net.Core.Level.Warn;
52+
hierarchy.Root.AddAppender(consoleAppender);
53+
hierarchy.Configured = true;
2554
}
2655
}
2756
}

src/NHibernate/Cfg/Configuration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,11 @@ private void AddProperties(ISessionFactoryConfiguration factoryConfiguration)
14281428
public Configuration Configure()
14291429
{
14301430
var hc = ConfigurationManager.GetSection(CfgXmlHelper.CfgSectionName) as IHibernateConfiguration;
1431+
return Configure(hc);
1432+
}
1433+
1434+
public Configuration Configure(IHibernateConfiguration hc)
1435+
{
14311436
if (hc != null && hc.SessionFactory != null)
14321437
{
14331438
return DoConfigure(hc.SessionFactory);

0 commit comments

Comments
 (0)