Skip to content

Commit

Permalink
Merge revision 2988
Browse files Browse the repository at this point in the history
SVN: branches/1.2.x@2995
  • Loading branch information
Sergey Koshcheyev committed Sep 21, 2007
1 parent 8ae337e commit 1f9bc8d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH1119/Fixture.cs
@@ -0,0 +1,34 @@
#if NET_2_0
using NUnit.Framework;

using System;

namespace NHibernate.Test.NHSpecificTest.NH1119
{
[TestFixture]
public class Fixture : BugTestCase
{
public override string BugNumber
{
get { return "NH1119"; }
}

[Test]
public void SelectMinFromEmptyTable()
{
using (ISession s = OpenSession())
{
try
{
DateTime dt = s.CreateQuery("select max(tc.DateTimeProperty) from TestClass tc").UniqueResult<DateTime>();
string msg = "Calling UniqueResult<T> where T is a value type"
+ " should throw InvalidCastException when the result"
+ " is null";
Assert.Fail(msg);
}
catch (InvalidCastException) { }
}
}
}
}
#endif
13 changes: 13 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH1119/Mappings.hbm.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="NHibernate.Test.NHSpecificTest.NH1119"
assembly="NHibernate.Test">

<class name="TestClass" table="TestClassNH1119">
<id name="ID">
<generator class="native"/>
</id>
<property name="DateTimeProperty"/>
</class>

</hibernate-mapping>
21 changes: 21 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/NH1119/Model.cs
@@ -0,0 +1,21 @@
using System;

namespace NHibernate.Test.NHSpecificTest.NH1119
{
public class TestClass
{
private int _ID;
public virtual int ID
{
get { return _ID; }
set { _ID = value; }
}

private DateTime _DateTimeProperty;
public virtual DateTime DateTimeProperty
{
get { return _DateTimeProperty; }
set { _DateTimeProperty = value; }
}
}
}
7 changes: 6 additions & 1 deletion src/NHibernate.Test/NHibernate.Test-2.0.csproj
Expand Up @@ -221,6 +221,8 @@
<Compile Include="NHSpecificTest\BasicTimeFixture.cs" />
<Compile Include="NHSpecificTest\BugTestCase.cs" />
<Compile Include="NHSpecificTest\CollectionFixture.cs" />
<Compile Include="NHSpecificTest\NH1119\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1119\Model.cs" />
<Compile Include="NHSpecificTest\NH1018\Employee.cs" />
<Compile Include="NHSpecificTest\NH1018\Employer.cs" />
<Compile Include="NHSpecificTest\NH1018\NH1018Fixture.cs" />
Expand Down Expand Up @@ -911,6 +913,9 @@
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH1018\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH1119\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
Expand All @@ -929,4 +934,4 @@
copy "$(ProjectDir)\hibernate.cfg.xml" "hibernate.cfg.xml"
copy /y "..\..\..\NHibernate.DomainModel\ABC.hbm.xml" "ABC.hbm.xml"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
12 changes: 10 additions & 2 deletions src/NHibernate/Impl/AbstractQueryImpl.cs
Expand Up @@ -616,7 +616,15 @@ internal protected ISessionImplementor Session
#if NET_2_0
public T UniqueResult<T>()
{
return (T) UniqueResult();
object result = UniqueResult();
if (result == null && typeof(T).IsValueType)
{
throw new InvalidCastException("UniqueResult<T>() cannot cast null result to value type. Call UniqueResult<T?>() instead");
}
else
{
return (T)UniqueResult();
}
}
#endif

Expand Down Expand Up @@ -767,4 +775,4 @@ public override string ToString()
return queryString;
}
}
}
}
10 changes: 9 additions & 1 deletion src/NHibernate/Impl/CriteriaImpl.cs
Expand Up @@ -122,7 +122,15 @@ public IList<T> List<T>()

public T UniqueResult<T>()
{
return (T) UniqueResult();
object result = UniqueResult();
if (result == null && typeof(T).IsValueType)
{
throw new InvalidCastException("UniqueResult<T>() cannot cast null result to value type. Call UniqueResult<T?>() instead");
}
else
{
return (T)UniqueResult();
}
}
#endif

Expand Down

0 comments on commit 1f9bc8d

Please sign in to comment.