Skip to content
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
72 changes: 72 additions & 0 deletions src/NHibernate.Test/Async/CollectionTest/IdBagRelaxedFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

namespace NHibernate.Test.CollectionTest
{
using System.Threading.Tasks;
[TestFixture]
public class IdBagRelaxedFixtureAsync : TestCase
{
protected override string[] Mappings
{
get { return new string[] { "CollectionTest.IdBagRelaxedFixture.hbm.xml" }; }
}

protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}

protected override void OnTearDown()
{
using( ISession s = OpenSession() )
{
s.Delete( "from A" );
s.Flush();
}
}

[Test]
public async Task SimpleAsync()
{
A a = new A();
a.Name = "first generic type";
a.Items = new List<string>();
a.Items.Add( "first string" );
a.Items.Add( "second string" );

ISession s = OpenSession();
await (s.SaveOrUpdateAsync( a ));
// this flush should test how NH wraps a generic collection with its
// own persistent collection
await (s.FlushAsync());
s.Close();
Assert.IsNotNull( a.Id );
Assert.AreEqual( "first string", ( string ) a.Items[ 0 ] );

s = OpenSession();
a = ( A ) await (s.LoadAsync( typeof( A ), a.Id ));
Assert.AreEqual( "first string", ( string ) a.Items[ 0 ], "first item should be 'first string'" );
Assert.AreEqual( "second string", ( string ) a.Items[ 1 ], "second item should be 'second string'" );
// ensuring the correct generic type was constructed
a.Items.Add( "third string" );
Assert.AreEqual( 3, a.Items.Count, "3 items in the list now" );

a.Items[ 1 ] = "new second string";
await (s.FlushAsync());
s.Close();
}
}
}
16 changes: 9 additions & 7 deletions src/NHibernate.Test/CollectionTest/IdBagFixture.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
<generator class="native" />
</id>
<property name="Name" column="aname" />
<idbag name="Items" cascade="all-delete-orphan">
<collection-id type="Int32" column="item_id">
<generator class="increment" />
</collection-id>
<key column="a_id" />
<element type="string" />
</idbag>
<idbag name="Items" cascade="all-delete-orphan">
<collection-id>
<column name="item_id" />
<generator class="increment" />
<type name="Int64" />
</collection-id>
<key column="a_id" />
<element type="string" />
</idbag>
</class>
</hibernate-mapping>
61 changes: 61 additions & 0 deletions src/NHibernate.Test/CollectionTest/IdBagRelaxedFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

namespace NHibernate.Test.CollectionTest
{
[TestFixture]
public class IdBagRelaxedFixture : TestCase
{
protected override string[] Mappings
{
get { return new string[] { "CollectionTest.IdBagRelaxedFixture.hbm.xml" }; }
}

protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}

protected override void OnTearDown()
{
using( ISession s = OpenSession() )
{
s.Delete( "from A" );
s.Flush();
}
}

[Test]
public void Simple()
{
A a = new A();
a.Name = "first generic type";
a.Items = new List<string>();
a.Items.Add( "first string" );
a.Items.Add( "second string" );

ISession s = OpenSession();
s.SaveOrUpdate( a );
// this flush should test how NH wraps a generic collection with its
// own persistent collection
s.Flush();
s.Close();
Assert.IsNotNull( a.Id );
Assert.AreEqual( "first string", ( string ) a.Items[ 0 ] );

s = OpenSession();
a = ( A ) s.Load( typeof( A ), a.Id );
Assert.AreEqual( "first string", ( string ) a.Items[ 0 ], "first item should be 'first string'" );
Assert.AreEqual( "second string", ( string ) a.Items[ 1 ], "second item should be 'second string'" );
// ensuring the correct generic type was constructed
a.Items.Add( "third string" );
Assert.AreEqual( 3, a.Items.Count, "3 items in the list now" );

a.Items[ 1 ] = "new second string";
s.Flush();
s.Close();
}
}
}
14 changes: 14 additions & 0 deletions src/NHibernate.Test/CollectionTest/IdBagRelaxedFixture.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.CollectionTest">
<class name="A" table="a" lazy="false">
<id name="Id" column="id" unsaved-value="null">
<generator class="native" />
</id>
<property name="Name" column="aname" />
<idbag name="Items" cascade="all-delete-orphan">
<collection-id column="item_id" generator="increment" />
<key column="a_id" />
<element type="string" />
</idbag>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public void WhenCreateThenHasDefaultTypeAndGenerator()
var hbmId = new HbmCollectionId();
new CollectionIdMapper(hbmId);
Assert.That(hbmId.generator.@class, Is.Not.Null.And.Not.Empty);
Assert.That(hbmId.type, Is.Not.Null.And.Not.Empty);
Assert.That(hbmId.type1, Is.Not.Null.And.Not.Empty);
Assert.That(hbmId.type, Is.Null);
}

[Test]
Expand All @@ -27,19 +28,21 @@ public void WhenSetGeneratorThenChangeType()
new CollectionIdMapper(hbmId).Generator(Generators.HighLow);

Assert.That(hbmId.generator.@class, Is.EqualTo("hilo"));
Assert.That(hbmId.type.ToLowerInvariant(), Does.Contain("int"));
Assert.That(hbmId.type1.ToLowerInvariant(), Does.Contain("int"));
Assert.That(hbmId.type, Is.Null);
}

[Test]
public void WhenForceTypeThenNotChangeType()
{
var hbmId = new HbmCollectionId();
var collectionIdMapper = new CollectionIdMapper(hbmId);
collectionIdMapper.Type((IIdentifierType) NHibernateUtil.Int64);
collectionIdMapper.Type(NHibernateUtil.Int64);
collectionIdMapper.Generator(Generators.HighLow);

Assert.That(hbmId.generator.@class, Is.EqualTo("hilo"));
Assert.That(hbmId.type, Is.EqualTo("Int64"));
Assert.That(hbmId.type1, Is.EqualTo("Int64"));
Assert.That(hbmId.type, Is.Null);
}

[Test]
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate.Tool.HbmXsd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Program
private static void Main(string[] args)
{
string outFile = Path.GetFullPath(args.Length == 0
? @"..\..\..\..\NHibernate\Cfg\MappingSchema\Hbm.generated.cs"
? Path.Combine("..", "..", "..", "..", "NHibernate", "Cfg", "MappingSchema", "Hbm.generated.cs")
: args[0]);
if (!Directory.Exists(Path.GetDirectoryName(outFile)))
{
Expand All @@ -19,11 +19,12 @@ private static void Main(string[] args)
Environment.ExitCode = -1;
return;
}

var currentUiCulture = new CultureInfo("en-us");
Thread.CurrentThread.CurrentCulture = currentUiCulture;
Thread.CurrentThread.CurrentUICulture = currentUiCulture;
new HbmCodeGenerator().Execute(outFile);
Console.WriteLine("Done");
}
}
}
}
Loading
Loading