-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ByCode OneToOne XML serialization
fix #3607
- Loading branch information
1 parent
ac2ff3a
commit 87c72bb
Showing
8 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/NHibernate.Test/NHSpecificTest/GH3607/FixtureByCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using NHibernate.Cfg; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
/// <summary> | ||
/// By code mapping serialization failure since v5.4.1. Adapted from <see href="https://github.com/craigfowler/NHibernate.XmlConversionBug" />. | ||
/// </summary> | ||
[TestFixture] | ||
public class FixtureByCode : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.AddMappings(new[] { typeof(OrderMapping), typeof(LineItemMapping), typeof(LineItemDataMapping) }); | ||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
[Test] | ||
public void SerializeMappingToXml() | ||
{ | ||
var mapping = GetMappings(); | ||
string serialized = ""; | ||
Assert.That(() => serialized = mapping.AsString(), Throws.Nothing, "Mapping serialization failure"); | ||
var config = new Configuration(); | ||
Assert.That(() => config.AddXml(serialized), Throws.Nothing, "Configuration with serialized mapping has failed"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
public class LineItem | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual Order ParentOrder { get; set; } | ||
|
||
public virtual string ItemName { get; set; } | ||
|
||
public virtual decimal Amount { get; set; } | ||
|
||
public virtual LineItemData Data { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
public class LineItemData | ||
{ | ||
public virtual LineItem LineItem { get; set; } | ||
|
||
public virtual string Data { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/NHibernate.Test/NHSpecificTest/GH3607/LineItemDataMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using NHibernate.Mapping.ByCode.Conformist; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
public class LineItemDataMapping : ClassMapping<LineItemData> | ||
{ | ||
public LineItemDataMapping() | ||
{ | ||
OneToOne(x => x.LineItem, m => m.Constrained(true)); | ||
|
||
Property(x => x.Data); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/NHibernate.Test/NHSpecificTest/GH3607/LineItemMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Mapping.ByCode.Conformist; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
public class LineItemMapping : ClassMapping<LineItem> | ||
{ | ||
public LineItemMapping() | ||
{ | ||
Id(x => x.Id, m => m.Generator(new IdentityGeneratorDef())); | ||
|
||
Property(x => x.ItemName); | ||
|
||
Property(x => x.Amount); | ||
|
||
ManyToOne(x => x.ParentOrder); | ||
|
||
ManyToOne(x => x.Data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
public class Order | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual DateTime CreatedDate { get; set; } | ||
|
||
public virtual ISet<LineItem> Items { get; protected set; } = new HashSet<LineItem>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using NHibernate.Mapping.ByCode; | ||
using NHibernate.Mapping.ByCode.Conformist; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3607 | ||
{ | ||
public class OrderMapping : ClassMapping<Order> | ||
{ | ||
public OrderMapping() | ||
{ | ||
Table("`Order`"); | ||
Id(x => x.Id, m => m.Generator(new IdentityGeneratorDef())); | ||
|
||
Property(x => x.CreatedDate); | ||
|
||
Set(x => x.Items, m => | ||
{ | ||
m.Inverse(true); | ||
m.OptimisticLock(true); | ||
}, a => a.OneToMany()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters