2010-05-12 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.ComponentModel.DataAnnotations / Test / System.ComponentModel.DataAnnotations / ValidationAttributeTest.cs
1 //
2 // ValidationAttributeTest.cs
3 //
4 // Authors:
5 //      Marek Habersack <mhabersack@novell.com>
6 //
7 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29 using System.Collections.Generic;
30 using System.ComponentModel.DataAnnotations;
31 using System.Text;
32
33 using NUnit.Framework;
34
35 namespace MonoTests.System.ComponentModel.DataAnnotations
36 {
37         [TestFixture]
38         public class ValidationAttributeTest
39         {
40                 const string TEST_ERROR_MESSAGE = "Test Error Message";
41                 string ErrorMessageAccessor ()
42                 {
43                         return TEST_ERROR_MESSAGE;
44                 }
45
46                 [Test]
47                 public void Constructor ()
48                 {
49                         var attr = new ValidateFooAttribute ();
50
51                         Assert.IsNull (attr.ErrorMessage, "#A1");
52                         Assert.IsNull (attr.ErrorMessageResourceName, "#A2");
53                         Assert.IsNull (attr.ErrorMessageResourceType, "#A3");
54                         Assert.IsNotNull (attr.GetErrorMessageString (), "#A4");
55                 }
56
57                 [Test]
58                 public void Constructor_Func ()
59                 {
60                         var attr = new ValidateFooAttribute (ErrorMessageAccessor);
61
62                         Assert.IsNull (attr.ErrorMessage, "#A1");
63                         Assert.IsNull (attr.ErrorMessageResourceName, "#A2");
64                         Assert.IsNull (attr.ErrorMessageResourceType, "#A3");
65                         Assert.IsNotNull (attr.GetErrorMessageString (), "#A4");
66                         Assert.AreEqual (TEST_ERROR_MESSAGE, attr.GetErrorMessageString (), "#A4");
67                 }
68
69                 [Test]
70                 public void Constructor_String ()
71                 {
72                         var attr = new ValidateFooAttribute ("Another Test Error Message");
73
74                         Assert.IsNull (attr.ErrorMessage, "#A1");
75                         Assert.IsNull (attr.ErrorMessageResourceName, "#A2");
76                         Assert.IsNull (attr.ErrorMessageResourceType, "#A3");
77                         Assert.IsNotNull (attr.GetErrorMessageString (), "#A4");
78                         Assert.IsNotNull (attr.GetErrorMessageString (), "#A4-1");
79                         Assert.AreEqual ("Another Test Error Message", attr.GetErrorMessageString (), "#A4-2");
80                 }
81
82                 [Test]
83                 public void ErrorMessage ()
84                 {
85                         var attr = new ValidateFooAttribute ();
86
87                         Assert.IsNull (attr.ErrorMessage, "#A1");
88
89                         attr.ErrorMessage = "Test";
90                         Assert.AreEqual ("Test", attr.ErrorMessage, "#A2");
91 #if NET_4_0
92                         attr.ErrorMessage = String.Empty;
93                         Assert.AreEqual (String.Empty, attr.ErrorMessage, "#A3");
94
95                         attr.ErrorMessage = null;
96                         Assert.IsNull (attr.ErrorMessage, "#A4");
97 #else
98                         try {
99                                 attr.ErrorMessage = String.Empty;
100                                 Assert.Fail ("#A3");
101                         } catch (InvalidOperationException) {
102                                 // success
103                         }
104
105                         attr = new ValidateFooAttribute ("Test");
106                         try {
107                                 attr.ErrorMessage = null;
108                                 Assert.Fail ("#A4");
109                         } catch (ArgumentException) {
110                                 // success
111                         }
112
113                         attr = new ValidateFooAttribute ("Test");
114                         try {
115                                 attr.ErrorMessage = String.Empty;
116                                 Assert.Fail ("#A4");
117                         } catch (ArgumentException) {
118                                 // success
119                         }
120
121                         attr = new ValidateFooAttribute ();
122                         attr.ErrorMessageResourceName = "ErrorProperty1";
123
124                         try {
125                                 attr.ErrorMessage = "Test Message";
126                                 Assert.Fail ("#E1");
127                         } catch (InvalidOperationException) {
128                                 // success
129                         }
130 #endif
131                         
132                 }
133
134                 [Test]
135                 public void ErrorMessageResourceName ()
136                 {
137                         var attr = new ValidateFooAttribute ();
138
139                         Assert.IsNull (attr.ErrorMessageResourceName, "#A1");
140
141                         attr.ErrorMessageResourceName = "Test";
142                         Assert.IsNotNull (attr.ErrorMessageResourceName, "#A2-1");
143                         Assert.AreEqual ("Test", attr.ErrorMessageResourceName, "#A2-2");
144 #if NET_4_0
145                         attr.ErrorMessageResourceName = String.Empty;
146                         Assert.IsNotNull (attr.ErrorMessageResourceName, "#A3-1");
147                         Assert.AreEqual (String.Empty, attr.ErrorMessageResourceName, "#A3-2");
148
149                         attr.ErrorMessageResourceName = null;
150                         Assert.IsNull (attr.ErrorMessageResourceName, "#A3-1");
151 #else
152                         try {
153                                 attr.ErrorMessageResourceName = String.Empty;
154                                 Assert.Fail ("#A3-1");
155                         } catch (InvalidOperationException) {
156                                 // success
157                         }
158
159                         attr = new ValidateFooAttribute ("Test");
160                         try {
161                                 attr.ErrorMessageResourceName = String.Empty;
162                                 Assert.Fail ("#A3-2");
163                         } catch (ArgumentException) {
164                                 // success
165                         }
166
167                         attr = new ValidateFooAttribute ("Test");
168                         try {
169                                 attr.ErrorMessageResourceName = null;
170                                 Assert.Fail ("#A3-3");
171                         } catch (ArgumentException) {
172                                 // success
173                         }
174
175                         attr = new ValidateFooAttribute ();
176                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
177
178                         try {
179                                 attr.ErrorMessageResourceName = "NoSuchProperty";
180                                 Assert.Fail ("#A3-4");
181                         } catch (InvalidOperationException) {
182                                 // success
183                         }
184 #endif
185                 }
186
187                 [Test]
188                 public void ErrorMessageResourceType ()
189                 {
190                         var attr = new ValidateFooAttribute ();
191
192                         Assert.IsNull (attr.ErrorMessageResourceType, "#A1");
193
194                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
195                         Assert.IsNotNull (attr.ErrorMessageResourceType, "#A2-1");
196                         Assert.AreEqual (typeof (FooErrorMessageProvider), attr.ErrorMessageResourceType, "#A2-2");
197 #if !NET_4_0
198                         attr = new ValidateFooAttribute ();
199                         attr.ErrorMessageResourceName = "NoSuchProperty";
200                         
201                         try {
202                                 attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
203                                 Assert.Fail ("#A3");
204                         } catch (InvalidOperationException) {
205                                 // success
206                         }
207 #endif
208                 }
209
210                 [Test]
211                 public void ErrorMessageString ()
212                 {
213                         var attr = new ValidateFooAttribute ();
214
215                         Assert.IsNotNull (attr.GetErrorMessageString (), "#A1-1");
216                         Assert.IsTrue (attr.GetErrorMessageString ().Length > 0, "#A1-2");
217
218                         attr = new ValidateFooAttribute ();
219                         attr.ErrorMessageResourceName = "TestResource";
220                         try {
221                                 attr.GetErrorMessageString ();
222                                 Assert.Fail ("#A2-1");
223                         } catch (InvalidOperationException) {
224                                 // success
225                         }
226 #if NET_4_0
227                         attr = new ValidateFooAttribute ();
228                         attr.ErrorMessageResourceName = String.Empty;
229                         try {
230                                 attr.GetErrorMessageString ();
231                                 Assert.Fail ("#A2-1");
232                         } catch (InvalidOperationException) {
233                                 // success
234                         }
235
236                         attr = new ValidateFooAttribute ();
237                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
238                         attr.ErrorMessageResourceName = null;
239                         
240                         try {
241                                 attr.GetErrorMessageString ();
242                                 Assert.Fail ("#A3-1");
243                         } catch (InvalidOperationException) {
244                                 // success
245                         }
246
247                         attr = new ValidateFooAttribute ();
248                         attr.ErrorMessageResourceName = String.Empty;
249                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
250                         try {
251                                 string s = attr.GetErrorMessageString ();
252                                 Assert.Fail ("#A3-2");
253                         } catch (InvalidOperationException) {
254                                 // success
255                         }
256
257                         attr = new ValidateFooAttribute ();
258                         attr.ErrorMessageResourceName = "NoSuchProperty";
259                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
260                         try {
261                                 attr.GetErrorMessageString ();
262                                 Assert.Fail ("#A4");
263                         } catch (InvalidOperationException) {
264                                 // success
265                         }
266
267                         attr = new ValidateFooAttribute ();
268                         attr.ErrorMessageResourceName = "ErrorProperty2";
269                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
270                         try {
271                                 attr.GetErrorMessageString ();
272                                 Assert.Fail ("#A5");
273                         } catch (InvalidOperationException) {
274                                 // success
275                         }
276
277                         attr = new ValidateFooAttribute ();
278                         attr.ErrorMessageResourceName = "ErrorProperty3";
279                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
280                         try {
281                                 attr.GetErrorMessageString ();
282                                 Assert.Fail ("#A5");
283                         } catch (InvalidOperationException) {
284                                 // success
285                         }
286
287                         attr = new ValidateFooAttribute ();
288                         attr.ErrorMessageResourceName = "ErrorProperty4";
289                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
290                         try {
291                                 attr.GetErrorMessageString ();
292                                 Assert.Fail ("#A6");
293                         } catch (InvalidOperationException) {
294                                 // success
295                         }
296
297                         attr = new ValidateFooAttribute ();
298                         attr.ErrorMessageResourceName = "ErrorProperty5";
299                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
300                         try {
301                                 attr.GetErrorMessageString ();
302                                 Assert.Fail ("#A7");
303                         } catch (InvalidOperationException) {
304                                 // success
305                         }
306
307                         attr = new ValidateFooAttribute ();
308                         attr.ErrorMessageResourceName = "ErrorField1";
309                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
310                         try {
311                                 attr.GetErrorMessageString ();
312                                 Assert.Fail ("#B1");
313                         } catch (InvalidOperationException) {
314                                 // success
315                         }
316
317                         attr = new ValidateFooAttribute ();
318                         attr.ErrorMessageResourceName = "ErrorField2";
319                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
320                         try {
321                                 attr.GetErrorMessageString ();
322                                 Assert.Fail ("#B2");
323                         } catch (InvalidOperationException) {
324                                 // success
325                         }
326 #endif
327
328                         attr = new ValidateFooAttribute ();
329                         attr.ErrorMessageResourceName = "ErrorProperty1";
330                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
331                         Assert.IsNotNull (attr.GetErrorMessageString (), "#C1-1");
332                         Assert.AreEqual ("Error Message 1", attr.GetErrorMessageString (), "#C1-2");
333
334                         attr = new ValidateFooAttribute (ErrorMessageAccessor);
335                         Assert.IsNotNull (attr.GetErrorMessageString (), "#D1-1");
336                         Assert.AreEqual (TEST_ERROR_MESSAGE, attr.GetErrorMessageString (), "#D1-2");
337
338                         attr = new ValidateFooAttribute ();
339                         attr.ErrorMessageResourceName = "ErrorProperty1";
340                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
341                         Assert.IsNotNull (attr.GetErrorMessageString (), "#D1-3");
342                         Assert.AreEqual ("Error Message 1", attr.GetErrorMessageString (), "#D1-4");
343 #if NET_4_0
344                         attr.ErrorMessage = "Test Message";
345                         try {
346                                 attr.GetErrorMessageString ();
347                                 Assert.Fail ("#E1");
348                         } catch (InvalidOperationException) {
349                                 // success
350                         }
351 #endif
352                 }
353
354                 [Test]
355                 public void FormatErrorMessage ()
356                 {
357                         var attr = new ValidateFooAttribute ();
358
359                         Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#A1-1");
360                         Assert.AreEqual ("The field SomeField is invalid.", attr.FormatErrorMessage ("SomeField"), "#A1-2");
361
362                         attr.ErrorMessage = "Test: {0}";
363                         Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#A2-1");
364                         Assert.AreEqual ("Test: SomeField", attr.FormatErrorMessage ("SomeField"), "#A2-2");
365 #if !NET_4_0
366                         attr = new ValidateFooAttribute ();
367 #else
368                         attr.ErrorMessage = null;
369 #endif
370                         attr.ErrorMessageResourceName = "ErrorProperty1";
371                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
372                         Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#B1-1");
373                         Assert.AreEqual ("Error Message 1", attr.FormatErrorMessage ("SomeField"), "#B1-2");
374 #if !NET_4_0
375                         attr = new ValidateFooAttribute ();
376 #endif
377                         attr.ErrorMessageResourceName = "ErrorProperty6";
378                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
379                         Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#B2-1");
380                         Assert.AreEqual ("Error Message 6: SomeField", attr.FormatErrorMessage ("SomeField"), "#B2-2");
381 #if !NET_4_0
382                         attr = new ValidateFooAttribute ();
383 #endif
384                         attr.ErrorMessageResourceName = "ErrorProperty6";
385                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
386                         Assert.IsNotNull (attr.FormatErrorMessage ("SomeField"), "#B3-1");
387                         Assert.AreEqual ("Error Message 6: ", attr.FormatErrorMessage (null), "#B3-2");
388                 }
389 #if NET_4_0
390                 [Test]
391                 public void GetValidationResult ()
392                 {
393                         var attr = new ValidateBarAttribute ();
394
395                         try {
396                                 attr.GetValidationResult ("stuff", null);
397                                 Assert.Fail ("#A1");
398                         } catch (ArgumentNullException) {
399                                 // success
400                         }
401
402                         var vc = new ValidationContext ("stuff", null, null);
403                         vc.DisplayName = "MyStuff";
404                         var vr = attr.GetValidationResult ("stuff", vc);
405                         Assert.IsNull (vr, "#A2");
406
407                         vr = attr.GetValidationResult (null, vc);
408                         Assert.IsNotNull(vr, "#A3-1");
409                         Assert.IsNotNull (vr.ErrorMessage, "#A3-2");
410                         Assert.AreEqual ("The field MyStuff is invalid.", vr.ErrorMessage, "#A3-3");
411
412                         attr.ErrorMessage = "My Error Message: {0}";
413                         vr = attr.GetValidationResult (null, vc);
414                         Assert.IsNotNull (vr, "#A4-1");
415                         Assert.IsNotNull (vr.ErrorMessage, "#A4-2");
416                         Assert.AreEqual ("My Error Message: MyStuff", vr.ErrorMessage, "#A4-3");
417
418                         attr.ErrorMessage = null;
419                         attr.ErrorMessageResourceName = "ErrorProperty1";
420                         attr.ErrorMessageResourceType = typeof (FooErrorMessageProvider);
421                         vr = attr.GetValidationResult (null, vc);
422                         Assert.IsNotNull (vr, "#A5-1");
423                         Assert.IsNotNull (vr.ErrorMessage, "#A5-2");
424                         Assert.AreEqual ("Error Message 1", vr.ErrorMessage, "#A5-3");
425
426                         attr.ErrorMessage = "My Error Message: {0}";
427                         attr.ErrorMessageResourceName = null;
428                         attr.ErrorMessageResourceType = null;
429                         vr = attr.GetValidationResult (null, vc);
430                         Assert.IsNotNull (vr, "#A6-1");
431                         Assert.IsNotNull (vr.MemberNames, "#A6-2");
432                         int count = 0;
433                         foreach (string s in vr.MemberNames)
434                                 count++;
435                         Assert.AreEqual (0, count, "#A6-3");
436                         Assert.AreEqual ("My Error Message: MyStuff", vr.ErrorMessage, "#A6-4");
437
438                         attr.ValidationResultErrorMessage = "My VR message";
439                         vr = attr.GetValidationResult (null, vc);
440                         Assert.IsNotNull (vr, "#A7-1");
441                         Assert.AreEqual ("My VR message", vr.ErrorMessage, "#A7-2");
442                 }
443
444                 [Test]
445                 public void IsValid_Object ()
446                 {
447                         var attr = new ValidateFooAttribute ();
448
449                         try {
450                                 attr.IsValid (null);
451                                 Assert.Fail ("#A1-1");
452                         } catch (NotImplementedException) {
453                                 // success
454                         }
455
456                         try {
457                                 attr.IsValid ("stuff");
458                                 Assert.Fail ("#A1-2");
459                         } catch (NotImplementedException) {
460                                 // success
461                         }
462                 }
463
464                 [Test]
465                 public void IsValid_Object_ValidationContext ()
466                 {
467                         var attr = new ValidateBarAttribute ();
468
469                         try {
470                                 // ...
471                                 attr.CallIsValid (null, null);
472                                 Assert.Fail ("#A1");
473                         } catch (NullReferenceException) {
474                                 // success
475                         }
476
477                         var vc = new ValidationContext ("stuff", null, null);
478                         var vr = attr.CallIsValid (null, vc);
479                         Assert.IsNotNull (vr, "#A2-1");
480                         Assert.IsNotNull (vr.ErrorMessage, "#A2-2");
481                         Assert.AreEqual ("The field String is invalid.", vr.ErrorMessage, "#A2-3");
482                         Assert.IsNotNull (vr.MemberNames, "#A2-4"); 
483                         
484                         int count = 0;
485                         foreach (string s in vr.MemberNames)
486                                 count++;
487                         Assert.AreEqual (0, count, "#A2-5");
488
489                         vc.MemberName = "SomeMember";
490                         vr = attr.CallIsValid (null, vc);
491                         Assert.IsNotNull (vr, "#A3-1");
492                         Assert.IsNotNull (vr.ErrorMessage, "#A3-2");
493                         Assert.AreEqual ("The field String is invalid.", vr.ErrorMessage, "#A3-3");
494                         Assert.IsNotNull (vr.MemberNames, "#A3-4");
495
496                         var list = new List <string> ();
497                         foreach (string s in vr.MemberNames)
498                                 list.Add (s);
499                         Assert.AreEqual (1, list.Count, "#A3-5");
500                         Assert.AreEqual ("SomeMember", list [0], "#A3-6");
501                 }
502
503                 [Test]
504                 public void Validate_Object_ValidationContext ()
505                 {
506                         var attr = new ValidateBazAttribute ();
507
508                         try {
509                                 attr.Validate ("stuff", (ValidationContext) null);
510                                 Assert.Fail ("#A1");
511                         } catch (ArgumentNullException) {
512                                 // success
513                         }
514
515                         var vc = new ValidationContext ("stuff", null, null);
516                         try {
517                                 attr.Validate (null, vc);
518                                 Assert.Fail ("#A2-1");
519                         } catch (ValidationException) {
520                                 // success
521                         }
522                         Assert.AreEqual (3, attr.Calls.Count, "#A2-1");
523                         Assert.AreEqual ("ValidationResult IsValid (object value, ValidationContext validationContext)", attr.Calls [0], "#A2-2");
524                         Assert.AreEqual ("bool IsValid (object value)", attr.Calls [1], "#A2-3");
525                         Assert.AreEqual ("string FormatErrorMessage (string name)", attr.Calls [2], "#A2-4");
526                 }
527 #endif
528                 [Test]
529                 public void Validate_Object_String ()
530                 {
531                         var attr = new ValidateBazAttribute ();
532
533                         try {
534                                 attr.Validate (null, (string) null);
535                                 Assert.Fail ("#A2");
536                         } catch (ValidationException) {
537                                 // success
538                         }
539
540                         Assert.AreEqual (2, attr.Calls.Count, "#A2-1");
541                         Assert.AreEqual ("bool IsValid (object value)", attr.Calls [0], "#A2-2");
542                         Assert.AreEqual ("string FormatErrorMessage (string name)", attr.Calls [1], "#A2-3");
543                 }
544         }
545
546         class ValidateFooAttribute : ValidationAttribute
547         {
548                 public ValidateFooAttribute ()
549                         : base ()
550                 { }
551
552                 public ValidateFooAttribute (Func<string> errorMessageAccessor)
553                         : base (errorMessageAccessor)
554                 { }
555
556                 public ValidateFooAttribute (string errorMessage)
557                         : base (errorMessage)
558                 { }
559
560                 public string GetErrorMessageString ()
561                 {
562                         return ErrorMessageString;
563                 }
564 #if !NET_4_0
565                 public override bool IsValid (object value)
566                 {
567                         return value != null;
568                 }
569 #endif
570         }
571
572         class ValidateBarAttribute : ValidateFooAttribute
573         {
574                 public string ValidationResultErrorMessage
575                 {
576                         get;
577                         set;
578                 }
579
580                 public override bool IsValid (object value)
581                 {
582                         return value != null;
583                 }
584 #if NET_4_0
585                 protected override ValidationResult IsValid (object value, ValidationContext validationContext)
586                 {
587                         if (!IsValid (value))
588                                 return new ValidationResult (ValidationResultErrorMessage);
589                         return null;
590                 }
591
592                 public ValidationResult CallIsValid (object value, ValidationContext validationContext)
593                 {
594                         return base.IsValid (value, validationContext);
595                 }
596 #endif
597         }
598
599         class ValidateBazAttribute : ValidateBarAttribute
600         {
601                 public readonly List<string> Calls = new List<string> ();
602
603                 public override bool IsValid (object value)
604                 {
605                         Calls.Add ("bool IsValid (object value)");
606                         return base.IsValid (value);
607                 }
608 #if NET_4_0
609                 protected override ValidationResult IsValid (object value, ValidationContext validationContext)
610                 {
611                         Calls.Add ("ValidationResult IsValid (object value, ValidationContext validationContext)");
612                         return base.IsValid (value, validationContext);
613                 }
614 #endif
615                 public override string FormatErrorMessage (string name)
616                 {
617                         Calls.Add ("string FormatErrorMessage (string name)");
618                         return base.FormatErrorMessage (name);
619                 }
620         }
621
622         class FooErrorMessageProvider
623         {
624                 public static string ErrorProperty1
625                 {
626                         get { return "Error Message 1"; }
627                 }
628
629                 public static int ErrorProperty2
630                 {
631                         get { return 1; }
632                 }
633
634                 public string ErrorProperty3
635                 {
636                         get { return "Error Message 2"; }
637                 }
638
639                 protected static string ErrorProperty4
640                 {
641                         get { return "Error Message 3"; }
642                 }
643
644                 public static string ErrorProperty5
645                 {
646                         set { }
647                 }
648
649                 public static string ErrorProperty6
650                 {
651                         get { return "Error Message 6: {0}"; }
652                 }
653
654                 public string ErrorField1 = "Error Message 4";
655                 public static string ErrorField2 = "Error Message 5";
656         }
657 }