Skip to content

Fix configuration schema forbidding custom bytecode provider #1764

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

Merged
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
23 changes: 19 additions & 4 deletions src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Configuration;
using System.Reflection;
using NHibernate.Event;
using NUnit.Framework;
using NHibernate.Cfg;
Expand All @@ -13,7 +11,7 @@ namespace NHibernate.Test.CfgTest
public class ConfigurationSchemaFixture
{
[Test]
public void InvalidConfig()
public void SessionFactoryIsRequiredWhenConfigurationIsNotLoadedFromAppConfig()
{
string xml =
@"<?xml version='1.0' encoding='utf-8' ?>
Expand All @@ -22,7 +20,7 @@ public void InvalidConfig()
</hibernate-configuration>";

XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null);
Assert.Throws<HibernateConfigException>(()=>new HibernateConfiguration(xtr));
Assert.Throws<HibernateConfigException>(() => new HibernateConfiguration(xtr));
}

[Test]
Expand All @@ -35,6 +33,23 @@ public void FromAppConfigTest()
Assert.IsTrue(hc.UseReflectionOptimizer);
Assert.AreEqual("NHibernate.Test", hc.SessionFactory.Name);
}

[Test]
public void ByteCodeProvider()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test one above will fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand...

Copy link
Member Author

@fredericDelaporte fredericDelaporte Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first test of the fixture still succeeds because the configuration is invalid by lack of session-factory node. That is not a schema validation error, but a hard-coded check in the parsing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood that later, but did not report it here. Can you rename that test to something more meaningful than InvalidConfig?

{
Assume.That(TestsContext.ExecutingWithVsTest, Is.False);

var xml =
@"<?xml version='1.0' encoding='utf-8' ?>
<hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'>
<bytecode-provider type='test'/>
<session-factory>
</session-factory>
</hibernate-configuration>";

var hc = HibernateConfiguration.FromAppConfig(xml);
Assert.That(hc.ByteCodeProviderType, Is.EqualTo("test"));
}

[Test]
public void IgnoreSystemOutOfAppConfig()
Expand Down
15 changes: 11 additions & 4 deletions src/NHibernate/nhibernate-configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,17 @@
</xs:sequence>
<xs:attribute name="type" default="lcg">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="lcg" />
<xs:enumeration value="null" />
</xs:restriction>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="lcg" />
<xs:enumeration value="null" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
Expand Down