|
From: <fab...@us...> - 2011-04-28 12:44:04
|
Revision: 5785
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5785&view=rev
Author: fabiomaulo
Date: 2011-04-28 12:43:58 +0000 (Thu, 28 Apr 2011)
Log Message:
-----------
Ported some tests
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/
trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/CompatibilityWithCandidatePersistentMembers.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorConcreteClassesTest.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorTest.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetMemberFromInterfacesTest.cs
trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/TypeExtensionsTest.cs
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/CompatibilityWithCandidatePersistentMembers.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/CompatibilityWithCandidatePersistentMembers.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/CompatibilityWithCandidatePersistentMembers.cs 2011-04-28 12:43:58 UTC (rev 5785)
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Mapping.ByCode;
+using NHibernate.Mapping.ByCode.Impl;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
+{
+ public class CompatibilityWithCandidatePersistentMembers
+ {
+ public abstract class Geo
+ {
+ public string Descrition { get; set; }
+ protected Geo Parent { get; set; }
+ protected ICollection<Geo> Elements { get; set; }
+ }
+
+ [Test]
+ public void GetFirstPropertyOfTypeShouldUseSameConceptsOfCandidatePersistentMembersProvider()
+ {
+ var memberProvider = new DefaultCandidatePersistentMembersProvider();
+ var properties = memberProvider.GetRootEntityMembers(typeof(Geo));
+ if(properties.Select(p => p.Name).Contains("Parent"))
+ {
+ typeof(Geo).GetFirstPropertyOfType(typeof(Geo)).Should().Not.Be.Null();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorConcreteClassesTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorConcreteClassesTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorConcreteClassesTest.cs 2011-04-28 12:43:58 UTC (rev 5785)
@@ -0,0 +1,53 @@
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
+{
+ public class GetFirstImplementorConcreteClassesTest
+ {
+ private class MyClass1
+ {
+
+ }
+ private class MyClass2 : MyClass1
+ {
+
+ }
+ private class MyClass3 : MyClass2
+ {
+
+ }
+ private class MyClass4 : MyClass3
+ {
+
+ }
+
+ [Test]
+ public void WhenImplIsAtSameLevelThenReturnImplementor()
+ {
+ typeof(MyClass1).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass1));
+ typeof(MyClass2).GetFirstImplementorOf(typeof(MyClass2)).Should().Be(typeof(MyClass2));
+ typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass3)).Should().Be(typeof(MyClass3));
+ typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass4)).Should().Be(typeof(MyClass4));
+ }
+
+ [Test]
+ public void WhenImplIsAtDifferentLevelThenReturnImplementor()
+ {
+ typeof(MyClass2).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass2));
+ typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass2));
+ typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass2)).Should().Be(typeof(MyClass3));
+ typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass1)).Should().Be(typeof(MyClass2));
+ typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass2)).Should().Be(typeof(MyClass3));
+ typeof(MyClass4).GetFirstImplementorOf(typeof(MyClass3)).Should().Be(typeof(MyClass4));
+ }
+
+ [Test]
+ public void WhenImplIsAtUpLevelThenReturnNull()
+ {
+ typeof(MyClass2).GetFirstImplementorOf(typeof(MyClass3)).Should().Be.Null();
+ typeof(MyClass3).GetFirstImplementorOf(typeof(MyClass4)).Should().Be.Null();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetFirstImplementorTest.cs 2011-04-28 12:43:58 UTC (rev 5785)
@@ -0,0 +1,78 @@
+using System;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
+{
+ public class GetFirstImplementorTest
+ {
+ private interface IInterfaceNoImpl
+ {
+
+ }
+ private interface IInterface1
+ {
+
+ }
+ private interface IInterface2
+ {
+
+ }
+ private interface IInterface3
+ {
+
+ }
+ private class MyClassNoInterface
+ {
+
+ }
+ private class MyClass1: IInterface1
+ {
+
+ }
+ private class MyClass2: MyClass1, IInterface2
+ {
+
+ }
+ private class MyClass3 : MyClass2, IInterface3
+ {
+
+ }
+
+ [Test]
+ public void WhenInvalidThenThrows()
+ {
+ Executing.This(()=>((System.Type) null).GetFirstImplementorOf(typeof(IInterfaceNoImpl))).Should().Throw<ArgumentNullException>();
+ Executing.This(() => typeof(IInterfaceNoImpl).GetFirstImplementorOf(null)).Should().Throw<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenIsInterfaceThenNoImplementor()
+ {
+ typeof(IInterfaceNoImpl).GetFirstImplementorOf(typeof(IInterfaceNoImpl)).Should().Be.Null();
+ }
+
+ [Test]
+ public void WhenImplAsNoInterfaceThenNoImplementor()
+ {
+ typeof(MyClassNoInterface).GetFirstImplementorOf(typeof(IInterfaceNoImpl)).Should().Be.Null();
+ }
+
+ [Test]
+ public void WhenImplIsAtSameLevelThenReturnImplementor()
+ {
+ typeof(MyClass1).GetFirstImplementorOf(typeof(IInterface1)).Should().Be(typeof(MyClass1));
+ typeof(MyClass2).GetFirstImplementorOf(typeof(IInterface2)).Should().Be(typeof(MyClass2));
+ typeof(MyClass3).GetFirstImplementorOf(typeof(IInterface3)).Should().Be(typeof(MyClass3));
+ }
+
+ [Test]
+ public void WhenImplIsAtDifferentLevelThenReturnImplementor()
+ {
+ typeof(MyClass2).GetFirstImplementorOf(typeof(IInterface1)).Should().Be(typeof(MyClass1));
+ typeof(MyClass3).GetFirstImplementorOf(typeof(IInterface2)).Should().Be(typeof(MyClass2));
+ typeof(MyClass3).GetFirstImplementorOf(typeof(IInterface1)).Should().Be(typeof(MyClass1));
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetMemberFromInterfacesTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetMemberFromInterfacesTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/GetMemberFromInterfacesTest.cs 2011-04-28 12:43:58 UTC (rev 5785)
@@ -0,0 +1,82 @@
+using System;
+using System.Linq;
+using System.Reflection;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
+{
+ public class GetMemberFromInterfacesTest
+ {
+ private class BaseEntity
+ {
+ public int Id { get; set; }
+ }
+
+ private interface IEntity
+ {
+ bool IsValid { get; }
+ string Something { get; set; }
+ }
+
+ private interface IHasSomething
+ {
+ string Something { get; set; }
+ }
+
+ private class Person : BaseEntity, IEntity, IHasSomething
+ {
+ private int someField;
+ public string Name { get; set; }
+ public bool IsValid { get { return false; } }
+ public string Something { get; set; }
+ }
+
+ private interface IInheritedHasSomething : IHasSomething
+ {
+ string Blah { get; set; }
+ }
+
+
+ [Test]
+ public void WhenNullArgumentThenThrows()
+ {
+ Executing.This(() => ((MemberInfo)null).GetPropertyFromInterfaces().ToList()).Should().Throw<ArgumentNullException>();
+ }
+
+ [Test]
+ public void WhenNoInterfaceThenEmptyList()
+ {
+ For<BaseEntity>.Property(x=> x.Id).GetPropertyFromInterfaces().Should().Be.Empty();
+ }
+
+ [Test]
+ public void WhenFieldThenEmptyList()
+ {
+ ForClass<Person>.Field("someField").GetPropertyFromInterfaces().Should().Be.Empty();
+ }
+
+ [Test]
+ public void WhenOneInterfaceThenReturnMemberInfoOfInterface()
+ {
+ var members = For<Person>.Property(x => x.IsValid).GetPropertyFromInterfaces();
+ members.Single().Should().Be(For<IEntity>.Property(x=> x.IsValid));
+ }
+
+ [Test]
+ public void WhenTwoInterfacesThenReturnMemberInfoOfEachInterface()
+ {
+ var members = For<Person>.Property(x => x.Something).GetPropertyFromInterfaces();
+ members.Should().Contain(For<IEntity>.Property(x => x.Something));
+ members.Should().Contain(For<IHasSomething>.Property(x => x.Something));
+ }
+
+ [Test]
+ public void WhenPropertyOfInterfaceThenNotThrows()
+ {
+ var member = For<IInheritedHasSomething>.Property(x => x.Blah);
+ member.Executing(x=> x.GetPropertyFromInterfaces().Any()).NotThrows();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/TypeExtensionsTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/TypeExtensionsTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/MappingByCode/TypeExtensionsTests/TypeExtensionsTest.cs 2011-04-28 12:43:58 UTC (rev 5785)
@@ -0,0 +1,207 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Reflection;
+using NHibernate.Mapping.ByCode;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.MappingByCode.TypeExtensionsTests
+{
+ public class TypeExtensionsTest
+ {
+ private const BindingFlags BindingFlagsIncludePrivate = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
+
+ [Test]
+ public void CanDetermineDictionaryKeyType()
+ {
+ typeof (IDictionary<string, int>).DetermineDictionaryKeyType().Should().Be.EqualTo<string>();
+ }
+
+ [Test]
+ public void WhenNoGenericDictionaryThenDetermineNullDictionaryKeyType()
+ {
+ typeof(IEnumerable<string>).DetermineDictionaryKeyType().Should().Be.Null();
+ }
+
+ [Test]
+ public void CanDetermineDictionaryValueType()
+ {
+ typeof(IDictionary<string, int>).DetermineDictionaryValueType().Should().Be.EqualTo<int>();
+ }
+
+ [Test]
+ public void WhenNoGenericDictionaryThenDetermineNullDictionaryValueType()
+ {
+ typeof(IEnumerable<string>).DetermineDictionaryValueType().Should().Be.Null();
+ }
+
+ private class MyBaseClass
+ {
+ public string BaseProperty { get; set; }
+ public bool BaseBool { get; set; }
+ private double SomethingPrivate { get; set; }
+ }
+ private class MyClass : MyBaseClass
+ {
+
+ }
+
+ [Test]
+ public void DecodeMemberAccessExpressionShouldReturnMemberOfDeclaringClass()
+ {
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(mc => mc.BaseProperty).Satisfy(
+ mi => mi.ReflectedType == typeof(MyBaseClass) && mi.DeclaringType == typeof(MyBaseClass));
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass>(mc => mc.BaseBool).Satisfy(
+ mi => mi.ReflectedType == typeof(MyBaseClass) && mi.DeclaringType == typeof(MyBaseClass));
+ }
+
+ [Test]
+ public void GenericDecodeMemberAccessExpressionShouldReturnMemberOfDeclaringClass()
+ {
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass, string>(mc => mc.BaseProperty).Satisfy(
+ mi => mi.ReflectedType == typeof(MyBaseClass) && mi.DeclaringType == typeof(MyBaseClass));
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpression<MyClass, bool>(mc => mc.BaseBool).Satisfy(
+ mi => mi.ReflectedType == typeof(MyBaseClass) && mi.DeclaringType == typeof(MyBaseClass));
+ }
+
+ [Test]
+ public void DecodeMemberAccessExpressionOfShouldReturnMemberOfRequiredClass()
+ {
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<MyClass>(mc => mc.BaseProperty).Satisfy(
+ mi => mi.ReflectedType == typeof (MyClass) && mi.DeclaringType == typeof (MyBaseClass));
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<MyClass>(mc => mc.BaseBool).Satisfy(
+ mi => mi.ReflectedType == typeof(MyClass) && mi.DeclaringType == typeof(MyBaseClass));
+ }
+
+ [Test]
+ public void GenericDecodeMemberAccessExpressionOfShouldReturnMemberOfRequiredClass()
+ {
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<MyClass, string>(mc => mc.BaseProperty).Satisfy(
+ mi => mi.ReflectedType == typeof(MyClass) && mi.DeclaringType == typeof(MyBaseClass));
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<MyClass, bool>(mc => mc.BaseBool).Satisfy(
+ mi => mi.ReflectedType == typeof(MyClass) && mi.DeclaringType == typeof(MyBaseClass));
+ }
+
+ [Test]
+ public void GetBaseTypesIncludesInterfaces()
+ {
+ typeof (Collection<>).GetBaseTypes().Should().Contain(typeof (IEnumerable));
+ }
+
+ private interface IEntity<T>
+ {
+ T Id { get; set; }
+ }
+ private abstract class AbstractEntity<T> : IEntity<T>
+ {
+ public abstract T Id { get; set; }
+ public abstract bool BaseBool { get; set; }
+ }
+
+ private class BaseEntity : AbstractEntity<int>
+ {
+ public override int Id { get; set; }
+
+ public override bool BaseBool { get; set; }
+ }
+ private class MyEntity: BaseEntity
+ {
+ }
+
+ [Test]
+ public void DecodeMemberAccessExpressionOfWithGenericShouldReturnMemberOfRequiredClass()
+ {
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<MyEntity>(mc => mc.Id).Satisfy(
+ mi => mi.ReflectedType == typeof(MyEntity) && mi.DeclaringType == typeof(BaseEntity));
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<MyEntity>(mc => mc.BaseBool).Satisfy(
+ mi => mi.ReflectedType == typeof(MyEntity) && mi.DeclaringType == typeof(BaseEntity));
+ }
+
+ [Test]
+ public void WhenBaseIsAbstractGenericGetMemberFromDeclaringType()
+ {
+ var mi = typeof(MyEntity).GetProperty("Id", typeof(int));
+ var declaringMi = mi.GetMemberFromDeclaringType();
+ declaringMi.DeclaringType.Should().Be<BaseEntity>();
+ declaringMi.ReflectedType.Should().Be<BaseEntity>();
+ }
+
+ [Test]
+ public void WhenBaseIsAbstractGetMemberFromDeclaringType()
+ {
+ var mi = typeof(MyEntity).GetProperty("BaseBool", typeof(bool));
+ var declaringMi = mi.GetMemberFromDeclaringType();
+ declaringMi.DeclaringType.Should().Be<BaseEntity>();
+ declaringMi.ReflectedType.Should().Be<BaseEntity>();
+ }
+
+ [Test]
+ public void GetFirstPropertyOfTypeWithNulls()
+ {
+ System.Type myType = null;
+ myType.GetFirstPropertyOfType(typeof (int), BindingFlagsIncludePrivate).Should().Be.Null();
+ myType = typeof (Array);
+ myType.GetFirstPropertyOfType(null, BindingFlagsIncludePrivate).Should().Be.Null();
+ }
+
+ [Test]
+ public void GetFirstPropertyOfType_WhenPropertyExistThenFindProperty()
+ {
+ typeof (MyBaseClass).GetFirstPropertyOfType(typeof (string)).Should().Be(
+ typeof (MyBaseClass).GetProperty("BaseProperty"));
+ typeof (MyBaseClass).GetFirstPropertyOfType(typeof (bool)).Should().Be(typeof (MyBaseClass).GetProperty("BaseBool"));
+ typeof (MyBaseClass).GetFirstPropertyOfType(typeof (double), BindingFlagsIncludePrivate).Should().Be(
+ typeof (MyBaseClass).GetProperty("SomethingPrivate", BindingFlagsIncludePrivate));
+ }
+
+ [Test]
+ public void GetFirstPropertyOfType_WhenPropertyNotExistThenNull()
+ {
+ typeof (MyBaseClass).GetFirstPropertyOfType(typeof (float)).Should().Be.Null();
+ // typeof (MyBaseClass).GetFirstPropertyOfType(typeof (double)).Should().Be.Null(); <= by default check private prop.
+ }
+
+ private interface IMyEntity : IEntity<Guid>
+ {
+
+ }
+
+ [Test]
+ public void WhenDecodeMemberAccessExpressionOfOnInheritedEntityInterfaceThenDecodeMember()
+ {
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<IMyEntity>(m => m.Id).Should().Not.Be.Null();
+ Mapping.ByCode.TypeExtensions.DecodeMemberAccessExpressionOf<IMyEntity, Guid>(m => m.Id).Should().Not.Be.Null();
+ }
+
+ [Test]
+ public void TheSequenceOfGetHierarchyFromBaseShouldStartFromBaseClassUpToGivenClass()
+ {
+ // excluding System.Object
+ typeof(MyEntity).GetHierarchyFromBase().Should().Have.SameSequenceAs(typeof(AbstractEntity<int>), typeof(BaseEntity), typeof(MyEntity));
+ }
+
+ [Test]
+ public void GetFirstPropertyOfType_WhenDelegateIsNullThenThrow()
+ {
+ var myType = typeof(Array);
+ Executing.This(()=> myType.GetFirstPropertyOfType(typeof(int), BindingFlagsIncludePrivate, null)).Should().Throw<ArgumentNullException>();
+ }
+
+ [Test]
+ public void GetFirstPropertyOfType_WhenAsDelegateThenUseDelegateToFilterProperties()
+ {
+ typeof (MyBaseClass).GetFirstPropertyOfType(typeof (string), BindingFlags.Public | BindingFlags.Instance, x => false).Should().Be.Null();
+ typeof (MyBaseClass).GetFirstPropertyOfType(typeof (string), BindingFlags.Public | BindingFlags.Instance, x => true).Should().Be(
+ typeof (MyBaseClass).GetProperty("BaseProperty"));
+ }
+
+ [Test]
+ public void HasPublicPropertyOf_WhenAsDelegateThenUseDelegateToFilterProperties()
+ {
+ typeof(MyBaseClass).HasPublicPropertyOf(typeof(string), x => false).Should().Be.False();
+ typeof(MyBaseClass).HasPublicPropertyOf(typeof(string), x => true).Should().Be.True();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-28 10:36:52 UTC (rev 5784)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2011-04-28 12:43:58 UTC (rev 5785)
@@ -608,6 +608,11 @@
<Compile Include="MappingByCode\NatureDemo\Naturalness\StateProvince.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\User.cs" />
<Compile Include="MappingByCode\NatureDemo\Naturalness\Zoo.cs" />
+ <Compile Include="MappingByCode\TypeExtensionsTests\CompatibilityWithCandidatePersistentMembers.cs" />
+ <Compile Include="MappingByCode\TypeExtensionsTests\GetFirstImplementorConcreteClassesTest.cs" />
+ <Compile Include="MappingByCode\TypeExtensionsTests\GetFirstImplementorTest.cs" />
+ <Compile Include="MappingByCode\TypeExtensionsTests\GetMemberFromInterfacesTest.cs" />
+ <Compile Include="MappingByCode\TypeExtensionsTests\TypeExtensionsTest.cs" />
<Compile Include="MappingByCode\TypeNameUtilTests.cs" />
<Compile Include="NHSpecificTest\AccessAndCorrectPropertyName\Fixture.cs" />
<Compile Include="NHSpecificTest\AccessAndCorrectPropertyName\Model.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|