Created
March 19, 2010 13:22
-
-
Save jfromaniello/337490 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System.Linq; | |
using ConfOrm; | |
using ConfOrm.NH; | |
using NHibernate.Cfg.MappingSchema; | |
using NUnit.Framework; | |
using SharpTestsEx; | |
namespace ConfOrmTests.TestCase | |
{ | |
public class Foo<T> | |
{ | |
public virtual int Id { get; set; } | |
public virtual T AProperty { get; set; } | |
} | |
//public class Bar : Foo<int>{} | |
[TestFixture] | |
public class GenericInheritanceCaseAFixture | |
{ | |
[Test(Description = "Conform is generating a mapping for generic property, look the value IsGenericParameter.")] | |
public void Test1() | |
{ | |
var orm = new ObjectRelationalMapper(); | |
var closedGenericProperty = typeof(Foo<int>).GetProperty("AProperty"); | |
orm.IsPersistentProperty(closedGenericProperty) | |
.Should("This property should be mapped because the generic type was closed.").Be.True(); | |
var openGenericProperty = typeof (Foo<>).GetProperty("AProperty"); | |
orm.IsPersistentProperty(openGenericProperty ) | |
.Should("This property should not be mapped because IsGenericParameter.").Be.False(); | |
} | |
[Test(Description = "Conform is generating a mapping with class name = Foo`1 (the open type), instead the closed type Foo`1[System.Int32]")] | |
public void Test2() | |
{ | |
var orm = new ObjectRelationalMapper(); | |
var mapper = new Mapper(orm); | |
orm.TablePerClass<Foo<int>>(); | |
var mappings = mapper.CompileMappingForEach(new[]{typeof(Foo<int>)}); | |
((HbmClass) (mappings.First().Items[0])).Name | |
.Should().Be.EqualTo("Foo`1[System.Int32]"); | |
//explained on http://ayende.com/Blog/archive/2007/11/14/NHibernate-and-Generic-Entities.aspx | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment