Skip to content

Commit e5cf3d0

Browse files
committed
Ported some tests
SVN: trunk@5785
1 parent 09637cb commit e5cf3d0

File tree

6 files changed

+455
-0
lines changed

6 files changed

+455
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using NHibernate.Mapping.ByCode;
4+
using NHibernate.Mapping.ByCode.Impl;
5+
using NUnit.Framework;
6+
using SharpTestsEx;
7+
8+
namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
9+
{
10+
public class CompatibilityWithCandidatePersistentMembers
11+
{
12+
public abstract class Geo
13+
{
14+
public string Descrition { get; set; }
15+
protected Geo Parent { get; set; }
16+
protected ICollection<Geo> Elements { get; set; }
17+
}
18+
19+
[Test]
20+
public void GetFirstPropertyOfTypeShouldUseSameConceptsOfCandidatePersistentMembersProvider()
21+
{
22+
var memberProvider = new DefaultCandidatePersistentMembersProvider();
23+
var properties = memberProvider.GetRootEntityMembers(typeof(Geo));
24+
if(properties.Select(p => p.Name).Contains("Parent"))
25+
{
26+
typeof(Geo).GetFirstPropertyOfType(typeof(Geo)).Should().Not.Be.Null();
27+
}
28+
}
29+
}
30+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using NHibernate.Mapping.ByCode;
2+
using NUnit.Framework;
3+
using SharpTestsEx;
4+
5+
namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
6+
{
7+
public class GetFirstImplementorConcreteClassesTest
8+
{
9+
private class MyClass1
10+
{
11+
12+
}
13+
private class MyClass2 : MyClass1
14+
{
15+
16+
}
17+
private class MyClass3 : MyClass2
18+
{
19+
20+
}
21+
private class MyClass4 : MyClass3
22+
{
23+
24+
}
25+
26+
[Test]
27+
public void WhenImplIsAtSameLevelThenReturnImplementor()
28+
{
29+
typeof(MyClass1).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass1));
30+
typeof(MyClass2).GetFirstImplementorOf(typeof(MyClass2)).Should().Be(typeof(MyClass2));
31+
typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass3)).Should().Be(typeof(MyClass3));
32+
typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass4)).Should().Be(typeof(MyClass4));
33+
}
34+
35+
[Test]
36+
public void WhenImplIsAtDifferentLevelThenReturnImplementor()
37+
{
38+
typeof(MyClass2).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass2));
39+
typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass2));
40+
typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass2)).Should().Be(typeof(MyClass3));
41+
typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass2));
42+
typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass2)).Should().Be(typeof(MyClass3));
43+
typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass3)).Should().Be(typeof(MyClass4));
44+
}
45+
46+
[Test]
47+
public void WhenImplIsAtUpLevelThenReturnNull()
48+
{
49+
typeof(MyClass2).GetFirstImplementorOf(typeof(MyClass3)).Should().Be.Null();
50+
typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass4)).Should().Be.Null();
51+
}
52+
}
53+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using NHibernate.Mapping.ByCode;
3+
using NUnit.Framework;
4+
using SharpTestsEx;
5+
6+
namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
7+
{
8+
public class GetFirstImplementorTest
9+
{
10+
private interface IInterfaceNoImpl
11+
{
12+
13+
}
14+
private interface IInterface1
15+
{
16+
17+
}
18+
private interface IInterface2
19+
{
20+
21+
}
22+
private interface IInterface3
23+
{
24+
25+
}
26+
private class MyClassNoInterface
27+
{
28+
29+
}
30+
private class MyClass1: IInterface1
31+
{
32+
33+
}
34+
private class MyClass2: MyClass1, IInterface2
35+
{
36+
37+
}
38+
private class MyClass3 : MyClass2, IInterface3
39+
{
40+
41+
}
42+
43+
[Test]
44+
public void WhenInvalidThenThrows()
45+
{
46+
Executing.This(()=>((System.Type) null).GetFirstImplementorOf(typeof(IInterfaceNoImpl))).Should().Throw<ArgumentNullException>();
47+
Executing.This(() => typeof(IInterfaceNoImpl).GetFirstImplementorOf(null)).Should().Throw<ArgumentNullException>();
48+
}
49+
50+
[Test]
51+
public void WhenIsInterfaceThenNoImplementor()
52+
{
53+
typeof(IInterfaceNoImpl).GetFirstImplementorOf(typeof(IInterfaceNoImpl)).Should().Be.Null();
54+
}
55+
56+
[Test]
57+
public void WhenImplAsNoInterfaceThenNoImplementor()
58+
{
59+
typeof(MyClassNoInterface).GetFirstImplementorOf(typeof(IInterfaceNoImpl)).Should().Be.Null();
60+
}
61+
62+
[Test]
63+
public void WhenImplIsAtSameLevelThenReturnImplementor()
64+
{
65+
typeof(MyClass1).GetFirstImplementorOf(typeof(IInterface1)).Should().Be(typeof(MyClass1));
66+
typeof(MyClass2).GetFirstImplementorOf(typeof(IInterface2)).Should().Be(typeof(MyClass2));
67+
typeof(MyClass3).GetFirstImplementorOf(typeof(IInterface3)).Should().Be(typeof(MyClass3));
68+
}
69+
70+
[Test]
71+
public void WhenImplIsAtDifferentLevelThenReturnImplementor()
72+
{
73+
typeof(MyClass2).GetFirstImplementorOf(typeof(IInterface1)).Should().Be(typeof(MyClass1));
74+
typeof(MyClass3).GetFirstImplementorOf(typeof(IInterface2)).Should().Be(typeof(MyClass2));
75+
typeof(MyClass3).GetFirstImplementorOf(typeof(IInterface1)).Should().Be(typeof(MyClass1));
76+
}
77+
}
78+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using NHibernate.Mapping.ByCode;
5+
using NUnit.Framework;
6+
using SharpTestsEx;
7+
8+
namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
9+
{
10+
public class GetMemberFromInterfacesTest
11+
{
12+
private class BaseEntity
13+
{
14+
public int Id { get; set; }
15+
}
16+
17+
private interface IEntity
18+
{
19+
bool IsValid { get; }
20+
string Something { get; set; }
21+
}
22+
23+
private interface IHasSomething
24+
{
25+
string Something { get; set; }
26+
}
27+
28+
private class Person : BaseEntity, IEntity, IHasSomething
29+
{
30+
private int someField;
31+
public string Name { get; set; }
32+
public bool IsValid { get { return false; } }
33+
public string Something { get; set; }
34+
}
35+
36+
private interface IInheritedHasSomething : IHasSomething
37+
{
38+
string Blah { get; set; }
39+
}
40+
41+
42+
[Test]
43+
public void WhenNullArgumentThenThrows()
44+
{
45+
Executing.This(() => ((MemberInfo)null).GetPropertyFromInterfaces().ToList()).Should().Throw<ArgumentNullException>();
46+
}
47+
48+
[Test]
49+
public void WhenNoInterfaceThenEmptyList()
50+
{
51+
For<BaseEntity>.Property(x=> x.Id).GetPropertyFromInterfaces().Should().Be.Empty();
52+
}
53+
54+
[Test]
55+
public void WhenFieldThenEmptyList()
56+
{
57+
ForClass<Person>.Field("someField").GetPropertyFromInterfaces().Should().Be.Empty();
58+
}
59+
60+
[Test]
61+
public void WhenOneInterfaceThenReturnMemberInfoOfInterface()
62+
{
63+
var members = For<Person>.Property(x => x.IsValid).GetPropertyFromInterfaces();
64+
members.Single().Should().Be(For<IEntity>.Property(x=> x.IsValid));
65+
}
66+
67+
[Test]
68+
public void WhenTwoInterfacesThenReturnMemberInfoOfEachInterface()
69+
{
70+
var members = For<Person>.Property(x => x.Something).GetPropertyFromInterfaces();
71+
members.Should().Contain(For<IEntity>.Property(x => x.Something));
72+
members.Should().Contain(For<IHasSomething>.Property(x => x.Something));
73+
}
74+
75+
[Test]
76+
public void WhenPropertyOfInterfaceThenNotThrows()
77+
{
78+
var member = For<IInheritedHasSomething>.Property(x => x.Blah);
79+
member.Executing(x=> x.GetPropertyFromInterfaces().Any()).NotThrows();
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)