Skip to content

Commit deef931

Browse files
committed
Tests for proxies interface and class combinations
1 parent 643ede4 commit deef931

File tree

4 files changed

+409
-0
lines changed

4 files changed

+409
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH2067
7+
{
8+
namespace BaseAndDerivedClassProxies
9+
{
10+
//Base [Base] -> Derived1 [Derived1] -> Derived2 [Derived2]
11+
public class NotMappedBase
12+
{
13+
}
14+
15+
public class Base : NotMappedBase
16+
{
17+
public virtual Guid Id { get; set; }
18+
public virtual int BaseName { get; set; }
19+
}
20+
21+
public class Derived1 : Base
22+
{
23+
public virtual string Derived1Name { get; set; }
24+
}
25+
26+
public class Derived2 : Derived1
27+
{
28+
public virtual string Derived2Name { get; set; }
29+
}
30+
31+
[TestFixture]
32+
public class BaseAndDerivedClassProxiesFixture : TestCaseMappingByCode
33+
{
34+
private Guid _id = Guid.NewGuid();
35+
36+
protected override HbmMapping GetMappings()
37+
{
38+
var mapper = new ModelMapper();
39+
mapper.Class<Base>(
40+
rc =>
41+
{
42+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
43+
rc.Property(x => x.BaseName);
44+
});
45+
46+
mapper.JoinedSubclass<Derived1>(
47+
rc => { rc.Property(x => x.Derived1Name); });
48+
49+
mapper.JoinedSubclass<Derived2>(
50+
rc => { rc.Property(x => x.Derived2Name); });
51+
52+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
53+
}
54+
55+
[Test]
56+
public void ProxyForBase()
57+
{
58+
using (var s = OpenSession())
59+
{
60+
var b = s.Load<Base>(_id);
61+
Assert.That(b.Id, Is.EqualTo(_id));
62+
}
63+
}
64+
65+
[Test]
66+
public void ProxyForDerived1()
67+
{
68+
using (var s = OpenSession())
69+
{
70+
var b = s.Load(typeof(Derived1), _id);
71+
72+
Assert.That(b, Is.InstanceOf(typeof(Derived1)));
73+
Assert.That(b, Is.InstanceOf(typeof(Base)));
74+
Assert.That(((Derived1) b).Id, Is.EqualTo(_id));
75+
}
76+
}
77+
78+
[Test]
79+
public void ProxyForDerived2()
80+
{
81+
using (var s = OpenSession())
82+
{
83+
var b = s.Load(typeof(Derived2), _id);
84+
85+
Assert.That(b, Is.InstanceOf(typeof(Derived1)));
86+
Assert.That(b, Is.InstanceOf(typeof(Derived2)));
87+
Assert.That(b, Is.InstanceOf(typeof(Base)));
88+
Assert.That(((Derived2) b).Id, Is.EqualTo(_id));
89+
}
90+
}
91+
}
92+
}
93+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH2067
7+
{
8+
namespace BaseClassAndDerivedInterfaceProxies
9+
{
10+
//Base [Base] -> Derived1 [IDerived1] -> Derived2 [IDerived2]
11+
public class NotMappedBase
12+
{
13+
}
14+
15+
public class Base : NotMappedBase
16+
{
17+
public virtual Guid Id { get; set; }
18+
public virtual int BaseName { get; set; }
19+
}
20+
21+
public class Derived1Interface : Base, IDerived1
22+
{
23+
public virtual string Derived1Name { get; set; }
24+
}
25+
26+
public class Derived2Interface : Derived1Interface, IDerived2
27+
{
28+
public virtual string Derived2Name { get; set; }
29+
}
30+
31+
public interface IDerived1
32+
{
33+
Guid Id { get; set; }
34+
string Derived1Name { get; set; }
35+
}
36+
37+
public interface IDerived2
38+
{
39+
Guid Id { get; set; }
40+
string Derived1Name { get; set; }
41+
}
42+
43+
[TestFixture]
44+
public class BaseClassAndDerivedInterfaceProxiesFixture : TestCaseMappingByCode
45+
{
46+
private Guid _id = Guid.NewGuid();
47+
48+
protected override HbmMapping GetMappings()
49+
{
50+
var mapper = new ModelMapper();
51+
mapper.Class<Base>(
52+
rc =>
53+
{
54+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
55+
rc.Property(x => x.BaseName);
56+
});
57+
58+
mapper.JoinedSubclass<Derived1Interface>(
59+
rc =>
60+
{
61+
rc.Proxy(typeof(IDerived1));
62+
rc.Property(x => x.Derived1Name);
63+
});
64+
65+
mapper.JoinedSubclass<Derived2Interface>(
66+
rc =>
67+
{
68+
rc.Proxy(typeof(IDerived2));
69+
rc.Property(x => x.Derived2Name);
70+
});
71+
72+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
73+
}
74+
75+
[Test]
76+
public void ProxyForBaseClass()
77+
{
78+
using (var s = OpenSession())
79+
{
80+
var b = s.Load<Base>(_id);
81+
Assert.That(b.Id, Is.EqualTo(_id));
82+
}
83+
}
84+
85+
[Test]
86+
public void ProxyForDerived1Interface()
87+
{
88+
using (var s = OpenSession())
89+
{
90+
var b = s.Load(typeof(Derived1Interface), _id);
91+
92+
Assert.That(b, Is.InstanceOf(typeof(IDerived1)));
93+
Assert.That(b, Is.InstanceOf(typeof(Base)));
94+
Assert.That(((IDerived1) b).Id, Is.EqualTo(_id));
95+
}
96+
}
97+
98+
[Test]
99+
public void ProxyForDerived2Interface()
100+
{
101+
using (var s = OpenSession())
102+
{
103+
var b = s.Load(typeof(Derived2Interface), _id);
104+
105+
Assert.That(b, Is.InstanceOf(typeof(IDerived1)));
106+
Assert.That(b, Is.InstanceOf(typeof(IDerived2)));
107+
Assert.That(b, Is.InstanceOf(typeof(Base)));
108+
Assert.That(((IDerived2) b).Id, Is.EqualTo(_id));
109+
}
110+
}
111+
}
112+
}
113+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using NHibernate.Cfg.MappingSchema;
3+
using NHibernate.Mapping.ByCode;
4+
using NUnit.Framework;
5+
6+
namespace NHibernate.Test.NHSpecificTest.GH2067
7+
{
8+
namespace BaseClassDerived1InterfaceDerived2ClassProxies
9+
{
10+
//Base [Base] -> Derived1 [IDerived1] -> Derived2 [Derived2]
11+
public class NotMappedBase
12+
{
13+
}
14+
15+
public class Base : NotMappedBase
16+
{
17+
public virtual Guid Id { get; set; }
18+
public virtual int BaseName { get; set; }
19+
}
20+
21+
public class Derived1 : Base, IDerived1
22+
{
23+
public virtual string Derived1Name { get; set; }
24+
}
25+
26+
public class Derived2 : Derived1
27+
{
28+
public virtual string Derived2Name { get; set; }
29+
}
30+
31+
public interface IDerived1
32+
{
33+
Guid Id { get; set; }
34+
string Derived1Name { get; set; }
35+
}
36+
37+
[TestFixture]
38+
public class BaseClassDerived1InterfaceDerived2ClassProxiesFixture : TestCaseMappingByCode
39+
{
40+
private Guid _id = Guid.NewGuid();
41+
42+
protected override HbmMapping GetMappings()
43+
{
44+
var mapper = new ModelMapper();
45+
mapper.Class<Base>(
46+
rc =>
47+
{
48+
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
49+
rc.Property(x => x.BaseName);
50+
});
51+
52+
mapper.JoinedSubclass<Derived1>(
53+
rc =>
54+
{
55+
rc.Proxy(typeof(IDerived1));
56+
rc.Property(x => x.Derived1Name);
57+
});
58+
59+
mapper.JoinedSubclass<Derived2>(
60+
rc => { rc.Property(x => x.Derived2Name); });
61+
62+
return mapper.CompileMappingForAllExplicitlyAddedEntities();
63+
}
64+
65+
[Test]
66+
public void ProxyForBase()
67+
{
68+
using (var s = OpenSession())
69+
{
70+
var b = s.Load(typeof(Base), _id);
71+
Assert.That(((Base) b).Id, Is.EqualTo(_id));
72+
}
73+
}
74+
75+
[Test]
76+
public void ProxyForDerived1Interface()
77+
{
78+
using (var s = OpenSession())
79+
{
80+
var b = s.Load(typeof(Derived1), _id);
81+
82+
Assert.That(b, Is.InstanceOf(typeof(IDerived1)));
83+
Assert.That(b, Is.InstanceOf(typeof(Base)));
84+
Assert.That(((IDerived1) b).Id, Is.EqualTo(_id));
85+
}
86+
}
87+
88+
[Test]
89+
public void ProxyForDerived2()
90+
{
91+
using (var s = OpenSession())
92+
{
93+
var b = s.Load(typeof(Derived2), _id);
94+
95+
Assert.That(b, Is.InstanceOf(typeof(IDerived1)));
96+
Assert.That(b, Is.InstanceOf(typeof(Derived2)));
97+
Assert.That(b, Is.InstanceOf(typeof(Base)));
98+
Assert.That(((Derived2) b).Id, Is.EqualTo(_id));
99+
}
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)