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
57 changes: 57 additions & 0 deletions src/NHibernate.Test/MappingByCode/GeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Linq;
using NHibernate.Id;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Impl;
using NUnit.Framework;
using SharpTestsEx;

namespace NHibernate.Test.MappingByCode
{
public class A { public int Id { get; set; } }

public class B { public int Id { get; set; } }

public class C { public int Id { get; set; } }

public class D { public int Id { get; set; } }

public class E { public int Id { get; set; } }

public class F { public int Id { get; set; } }

public class G { public int Id { get; set; } }

public class H { public int Id { get; set; } }

public class I { public int Id { get; set; } }

public class GeneratorTests
{
[Test]
public void TestGenerators()
{
var mapper = new ModelMapper();

mapper.Class<A>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Counter)); });
mapper.Class<B>(e => { e.Id(c => c.Id, c => c.Generator(Generators.UUIDHex)); });
mapper.Class<C>(e => { e.Id(c => c.Id, c => c.Generator(Generators.UUIDString)); });
mapper.Class<D>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Increment)); });
mapper.Class<E>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Select)); });
mapper.Class<F>(e => { e.Id(c => c.Id, c => c.Generator(Generators.SequenceHiLo)); });
mapper.Class<G>(e => { e.Id(c => c.Id, c => c.Generator(Generators.SequenceIdentity)); });
mapper.Class<H>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Table)); });
mapper.Class<I>(e => { e.Id(c => c.Id, c => c.Generator(Generators.TriggerIdentity)); });

var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(A).Name).Id.generator.@class, Generators.Counter.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(B).Name).Id.generator.@class, Generators.UUIDHex.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(C).Name).Id.generator.@class, Generators.UUIDString.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(D).Name).Id.generator.@class, Generators.Increment.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(E).Name).Id.generator.@class, Generators.Select.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(F).Name).Id.generator.@class, Generators.SequenceHiLo.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(G).Name).Id.generator.@class, Generators.SequenceIdentity.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(H).Name).Id.generator.@class, Generators.Table.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(I).Name).Id.generator.@class, Generators.TriggerIdentity.Class);
}
}
}
1 change: 1 addition & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@
<Compile Include="MappingByCode\ExplicitMappingTests\SubclassPropertiesSplitsTests.cs" />
<Compile Include="MappingByCode\ExplicitMappingTests\VersionTests.cs" />
<Compile Include="MappingByCode\For.cs" />
<Compile Include="MappingByCode\GeneratorTests.cs" />
<Compile Include="MappingByCode\ImportTests.cs" />
<Compile Include="MappingByCode\IntegrationTests\NH3041\Domain.cs" />
<Compile Include="MappingByCode\IntegrationTests\NH3657\OneToOneToPropertyReferenceWithExplicitClassSet.cs" />
Expand Down
Loading