Skip to content

Commit ce3722d

Browse files
committed
can't find a way to write a proper test - need to test the applicability of a convention to particular IUserType
1 parent 182e05c commit ce3722d

File tree

4 files changed

+83
-7
lines changed

4 files changed

+83
-7
lines changed

src/FluentNHibernate.Testing/AutoMapping/Apm/AutoPersistenceModelTests.Conventions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using FluentNHibernate.Automapping.TestFixtures;
33
using FluentNHibernate.Automapping.TestFixtures.ComponentTypes;
44
using FluentNHibernate.Automapping.TestFixtures.CustomTypes;
5+
using FluentNHibernate.Conventions;
6+
using FluentNHibernate.Conventions.AcceptanceCriteria;
57
using FluentNHibernate.Conventions.Helpers;
8+
using FluentNHibernate.Conventions.Inspections;
69
using FluentNHibernate.Testing.Automapping;
710
using NUnit.Framework;
811

@@ -79,6 +82,12 @@ public void TestAutoMapClassAppliesConventions()
7982
.Element("class").HasAttribute("table", "test");
8083
}
8184

85+
[Test]
86+
public void UserTypeConventionAppliesToNullableType()
87+
{
88+
new ValueTypeConvention().Accept(new ConcreteAcceptanceCriteria<IPropertyInspector>());
89+
}
90+
8291
[Test]
8392
public void TypeConventionShouldForcePropertyToBeMapped()
8493
{

src/FluentNHibernate.Testing/AutoMapping/TestFixtures.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Data;
55
using System.Drawing;
6+
using System.IO;
67
using FluentNHibernate.Automapping.TestFixtures.ComponentTypes;
78
using FluentNHibernate.Automapping.TestFixtures.CustomCompositeTypes;
89
using FluentNHibernate.Automapping.TestFixtures.CustomTypes;
@@ -155,6 +156,62 @@ public class ClassWithUserType
155156
public Custom Custom { get; set; }
156157
}
157158

159+
public class ContainingUserValueType
160+
{
161+
public int Id { get; set; }
162+
public UserValueType UserValueType { get; set; }
163+
}
164+
165+
public struct UserValueType: IUserType
166+
{
167+
public string AddressLine1 { get; set; }
168+
public string AddressLine2 { get; set; }
169+
170+
public bool Equals(object x, object y)
171+
{
172+
throw new NotImplementedException();
173+
}
174+
175+
public int GetHashCode(object x)
176+
{
177+
throw new NotImplementedException();
178+
}
179+
180+
public object NullSafeGet(IDataReader rs, string[] names, object owner)
181+
{
182+
throw new NotImplementedException();
183+
}
184+
185+
public void NullSafeSet(IDbCommand cmd, object value, int index)
186+
{
187+
throw new NotImplementedException();
188+
}
189+
190+
public object DeepCopy(object value)
191+
{
192+
throw new NotImplementedException();
193+
}
194+
195+
public object Replace(object original, object target, object owner)
196+
{
197+
throw new NotImplementedException();
198+
}
199+
200+
public object Assemble(object cached, object owner)
201+
{
202+
throw new NotImplementedException();
203+
}
204+
205+
public object Disassemble(object value)
206+
{
207+
throw new NotImplementedException();
208+
}
209+
210+
public SqlType[] SqlTypes { get; private set; }
211+
public Type ReturnedType { get { return typeof(Double); } }
212+
public bool IsMutable { get; private set; }
213+
}
214+
158215
public class ClassWithCompositeUserType
159216
{
160217
public int Id { get; set; }
@@ -222,6 +279,16 @@ public class DoubleString
222279
public class CustomTypeConvention : UserTypeConvention<CustomUserType>
223280
{}
224281

282+
public class ValueTypeConvention: UserTypeConvention<UserValueType>
283+
{
284+
public override void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
285+
{
286+
base.Accept(criteria);
287+
criteria.Expect(x => x.Length > 15);
288+
}
289+
290+
}
291+
225292
public class CustomCompositeTypeConvention : IUserTypeConvention
226293
{
227294
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)

src/FluentNHibernate/Conventions/IVersionConvention.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace FluentNHibernate.Conventions
66
{
77
/// <summary>
8-
/// Version convention, implement this interface to apply changes to vesion mappings.
8+
/// Version convention, implement this interface to apply changes to version mappings.
99
/// </summary>
1010
public interface IVersionConvention : IConvention<IVersionInspector, IVersionInstance>
1111
{ }

src/FluentNHibernate/Conventions/UserTypeConvention.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public virtual void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
1919
{
2020
var userType = Activator.CreateInstance<TUserType>();
2121
var returnedType = userType.ReturnedType;
22-
if (returnedType.IsValueType)
23-
{
24-
var nullableReturnedType = typeof(Nullable<>).MakeGenericType(returnedType);
25-
criteria.Expect(x => x.Type == returnedType || x.Type == nullableReturnedType);
26-
}
27-
else
22+
//if (returnedType.IsValueType)
23+
//{
24+
// var nullableReturnedType = typeof(Nullable<>).MakeGenericType(returnedType);
25+
// criteria.Expect(x => x.Type == returnedType || x.Type == nullableReturnedType);
26+
//}
27+
//else
2828
criteria.Expect(x => x.Type == returnedType);
2929
}
3030

0 commit comments

Comments
 (0)