Skip to content

Commit badff1f

Browse files
AlexanderKotfredericDelaporte
authored andcommitted
NHV-134 AutoGenerateFromMapping option implementation and tests (#10)
1 parent 9dee962 commit badff1f

File tree

12 files changed

+849
-109
lines changed

12 files changed

+849
-109
lines changed

src/NHibernate.Validator.Tests/Engine/Tagging/ClassValidatorTagging.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void WhenTagsIncludeOnlyNull_ValidateOnlyWithNoTags()
157157
[Test]
158158
public void WhenTagIsSpecified_ValidateRelationForGivenTags()
159159
{
160-
// specifying [Valid] the relation is always analized
160+
// specifying [Valid] the relation is always analyzed
161161
IClassValidator cv = new ClassValidator(typeof(EntityWithReletion));
162162
cv.GetInvalidValues(new EntityWithReletion { Reference = new Entity() }, typeof(Error)).Should().Have.Count.EqualTo(1);
163163
cv.GetInvalidValues(new EntityWithReletion { Reference = new Entity() }, typeof(Error), null).Should().Have.Count.EqualTo(2);
@@ -166,7 +166,7 @@ public void WhenTagIsSpecified_ValidateRelationForGivenTags()
166166
[Test]
167167
public void WhenTagIsSpecified_ValidateCollectionForGivenTags()
168168
{
169-
// specifying [Valid] the collection is always analized
169+
// specifying [Valid] the collection is always analyzed
170170
IClassValidator cv = new ClassValidator(typeof(EntityWithCollection));
171171
cv.GetInvalidValues(new EntityWithCollection { Entities = new List<Entity> { new Entity(), new Entity() } }, typeof(Error)).Should().Have.Count.EqualTo(2);
172172
cv.GetInvalidValues(new EntityWithCollection { Entities = new List<Entity> { new Entity(), new Entity() } }, typeof(Error), null).Should().Have.Count.EqualTo(4);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace NHibernate.Validator.Tests.Integration
5+
{
6+
public class FromNhibMetadata
7+
{
8+
public virtual int Id { get; set; }
9+
10+
public virtual DateTime? DateNotNull { get; set; }
11+
12+
public virtual string StrValue { get; set; }
13+
14+
public virtual decimal Dec { get; set; }
15+
16+
public virtual En1 EnumV { get; set; }
17+
18+
public virtual Cmp1 Cmp { get; set; }
19+
20+
public virtual ISet<Cmp2> Cmps2
21+
{
22+
get { return _cmps2; }
23+
set { _cmps2 = value; }
24+
}
25+
private ISet<Cmp2> _cmps2 = new HashSet<Cmp2>();
26+
}
27+
28+
public abstract class Cmp1Base
29+
{
30+
public virtual FromNhibMetadata Container { get; set; }
31+
public virtual En1 CEnumV { get; set; }
32+
public virtual string CStrValue { get; set; }
33+
}
34+
35+
public class Cmp1 : Cmp1Base
36+
{ }
37+
38+
public class Cmp2
39+
{
40+
public virtual En1 CEnumV1 { get; set; }
41+
public virtual string CStrValue1 { get; set; }
42+
43+
protected virtual bool Equals(Cmp2 obj)
44+
{
45+
return CEnumV1 == obj.CEnumV1 && CStrValue1 == obj.CStrValue1;
46+
}
47+
48+
public override int GetHashCode()
49+
{
50+
return (CStrValue1 + CEnumV1.ToString()).GetHashCode();
51+
}
52+
53+
}
54+
55+
public enum En1
56+
{
57+
v1 = 0,
58+
v2 = 1
59+
}
60+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
3+
namespace="NHibernate.Validator.Tests.Integration"
4+
assembly="NHibernate.Validator.Tests"
5+
default-access="property"
6+
default-lazy="false">
7+
8+
<class name="FromNhibMetadata">
9+
10+
<id name="Id">
11+
<generator class="assigned"/>
12+
</id>
13+
14+
<property name="DateNotNull" not-null="true" />
15+
<property name="StrValue" type="String" column="str" length="5"/>
16+
<property name="Dec" type="Decimal" precision="5" scale="2"/>
17+
<property name="EnumV"/>
18+
19+
<component name="Cmp" class="Cmp1">
20+
<property name="CEnumV"/>
21+
<property name="CStrValue" type="String" length="3"/>
22+
</component>
23+
24+
<set name="Cmps2" table="FromNhibMetadata_cmps2" lazy="true">
25+
<key column="cmpsid"/>
26+
<composite-element class="Cmp2">
27+
<property name="CEnumV1"/>
28+
<property name="CStrValue1" type="String" length="5"/>
29+
</composite-element>
30+
</set>
31+
32+
</class>
33+
</hibernate-mapping>

0 commit comments

Comments
 (0)