This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
/
COMP-52.xml
163 lines (150 loc) · 5.03 KB
/
COMP-52.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?xml version="1.0" encoding="utf-8"?>
<issues>
<issue>
<field name="Priority">
<value>Minor</value>
</field>
<field name="Type">
<value>Feature</value>
</field>
<field name="State">
<value>Obsolete</value>
</field>
<field name="Assignee" />
<field name="Subsystem">
<value>Validator</value>
</field>
<field name="Fix versions" />
<field name="Affected versions" />
<field name="Fixed in build" />
<field name="numberInProject">
<value>52</value>
</field>
<field name="summary">
<value>It should be possible to apply validators declared on a base interface of a given type</value>
</field>
<field name="description">
<value>I need to separate class implementation and validation logic that apply to it.
I prefer having an interface with validation attributes rather than have them in my concrete class.
My current implementation of this feature allow this test case to pass (and no regression for other tests):
[TestFixture]
public class ValidatorContainerInterfaceTestCase {
class Form1
: IForm1Validation1
, IForm1Validation2
, IForm1Validation3
{
public string UserId { get; set; }
public string Password { get; set; }
public string PasswordConfirmation { get; set; }
}
[ValidatorContainerInterfaceFlag]
interface IForm1Validation1
: IValidatorContainerInterface
{
[ValidateNonEmpty]
[ValidateLength(1)]
string UserId { get; }
[ValidateNonEmpty]
[ValidateLength(8)]
string Password { get; }
}
[ValidatorContainerInterfaceFlag]
interface IForm1Validation2
: IValidatorContainerInterface
{
[ValidateSameAs("Password")]
string PasswordConfirmation { get; }
}
interface IForm1Validation3
: IValidatorContainerInterface {
[ValidateSameAs("Password")]
string PasswordConfirmation { get; }
}
[Test]
public void AssertValidatorsAreFoundInImplementedInterfaceMembers() {
ValidatorRunner runner = new ValidatorRunner(true, new CachedValidationRegistry());
Form1 f = new Form1();
bool v = runner.IsValid(f);
Assert.IsFalse(v);
}
[Test]
public void AssertOnlySpecfiedInterfaceValidatorsAreFound() {
ValidatorRunner runner = new ValidatorRunner(true, new CachedValidationRegistry());
Form1 f = new Form1();
f.PasswordConfirmation = f.Password = "password";
bool v = runner.IsValid<IForm1Validation2>(f);
Assert.IsTrue(v);
f.Password = "another";
v = runner.IsValid<IForm1Validation2>(f);
Assert.IsFalse(v);
}
[Test]
public void AssertRequireAttributeOnValidatorContainerInterfaceDefinition() {
ValidatorRunner runner = new ValidatorRunner(true, new CachedValidationRegistry());
Form1 f = new Form1();
f.Password = "another";
f.PasswordConfirmation = "password";
bool v;
try {
v = runner.IsValid<IForm1Validation3>(f);
Assert.Fail("should have raised NotSupportedException");
}
catch (NotSupportedException nse) {
// expected exception
Assert.IsTrue(nse.Message.Contains(typeof(IForm1Validation3).Name));
Assert.IsTrue(nse.Message.Contains(typeof(ValidatorContainerInterfaceFlagAttribute).Name));
}
catch (Exception e) {
Assert.Fail(string.Format("should have raised NotSupportedException instead of {0}, exception message: {1}", e.GetType().Name, e));
}
}
[Test]
public void AssertRequireValidatorContainerInterfaceDefinitionIsAnInterface() {
ValidatorRunner runner = new ValidatorRunner(true, new CachedValidationRegistry());
Form1 f = new Form1();
f.Password = "another";
f.PasswordConfirmation = "password";
bool v;
try {
v = runner.IsValid<Form1>(f);
Assert.Fail("should have raised NotSupportedException");
}
catch (NotSupportedException nse) {
// expected exception
Assert.IsTrue(nse.Message.Contains(typeof(Form1).Name));
Assert.IsTrue(nse.Message.Contains("interface"));
}
catch (Exception e) {
Assert.Fail(string.Format("should have raised NotSupportedException instead of {0}, exception message: {1}", e.GetType().Name, e));
}
}
}
If anyone is interested, I can push the patch here.</value>
</field>
<field name="created">
<value>1201186806000</value>
</field>
<field name="updated">
<value>1285402212359</value>
</field>
<field name="reporterName">
<value>gauthier</value>
</field>
<field name="updaterName">
<value>henry</value>
</field>
<field name="resolved">
<value>1285402212359</value>
</field>
<field name="watcherName">
<value>User: id = 20-4[up-to-date]</value>
</field>
<field name="permittedGroup">
<value>All Users</value>
</field>
<comment author="roelofb" text="The comp-52-firstproposition.patch has gone stale.

The comp-52-enablingproposition(commentsfixed).patch was already applied IIRC" created="1219381686000" />
<comment author="hammett" text="Should we close this one?" created="1229881520000" />
<comment author="henry" text="The patch was partially and the validator today can extract validation info from metadata or interfaces." created="1285402212359" />
</issue>
</issues>