J
Jay
In both of the UnitTest projects that ship with the Ent Lib, (VSTS and
Nunit), there is a TestMethod with the name:
AttributeWithLowerAndUpperBoundsOnlyCreatesAppropriateValidator.
Each of these tests creates a StringLengthValidatorAttribute:
ValidatorAttribute attribute = new StringLengthValidatorAttribute(10,
20);
The next line creates a validator object based on the settings defined
in the Attribute:
Validator validator =
((IValidatorDescriptor)attribute).CreateValidator(null, null, null);
The final step prior to being able to access the properties of the
StringLengthValidator is:
StringLengthValidator stringLengthValidator = validator as
StringLengthValidator;
The following is what I have completed in my UnitTest class. The
concept of my Unit Test is to loop through all properties defined in
my Entity class, and then through the Attributes defined for each
property.
Sample:
foreach (PropertyInfo myInfo in myType.GetProperties())
{
foreach (Attribute attribute in myInfo.GetCustomAttributes(true))
{
if (attribute is
MSValidation.Validators.StringLengthValidatorAttribute)
{
Validator validator = ((IValidatorDescriptor)
(ValidatorAttribute)attribute).CreateValidator(null, null, null);
Assert.IsNotNull(validator);
StringLengthValidator stringLengthValidator = validator as
StringLengthValidator;
Assert.IsNotNull(stringLengthValidator);
}
}
}
The issue is that I am getting a compile error of:
Microsoft.Practices.EnterpriseLibrary.Validation.IValidatorDescriptor'
is inaccessible due to its protection level
D:\Development\UnitTest\Entity\CustomerUnitTest.cs
As expected, the IValidatorDescriptor is not color-coded in my unit
test but is in the sample UnitTests. My project is referencing the
EntLib...Validation DLL but I am obviously missing something. Can you
help?
Thanks
Nunit), there is a TestMethod with the name:
AttributeWithLowerAndUpperBoundsOnlyCreatesAppropriateValidator.
Each of these tests creates a StringLengthValidatorAttribute:
ValidatorAttribute attribute = new StringLengthValidatorAttribute(10,
20);
The next line creates a validator object based on the settings defined
in the Attribute:
Validator validator =
((IValidatorDescriptor)attribute).CreateValidator(null, null, null);
The final step prior to being able to access the properties of the
StringLengthValidator is:
StringLengthValidator stringLengthValidator = validator as
StringLengthValidator;
The following is what I have completed in my UnitTest class. The
concept of my Unit Test is to loop through all properties defined in
my Entity class, and then through the Attributes defined for each
property.
Sample:
foreach (PropertyInfo myInfo in myType.GetProperties())
{
foreach (Attribute attribute in myInfo.GetCustomAttributes(true))
{
if (attribute is
MSValidation.Validators.StringLengthValidatorAttribute)
{
Validator validator = ((IValidatorDescriptor)
(ValidatorAttribute)attribute).CreateValidator(null, null, null);
Assert.IsNotNull(validator);
StringLengthValidator stringLengthValidator = validator as
StringLengthValidator;
Assert.IsNotNull(stringLengthValidator);
}
}
}
The issue is that I am getting a compile error of:
Microsoft.Practices.EnterpriseLibrary.Validation.IValidatorDescriptor'
is inaccessible due to its protection level
D:\Development\UnitTest\Entity\CustomerUnitTest.cs
As expected, the IValidatorDescriptor is not color-coded in my unit
test but is in the sample UnitTests. My project is referencing the
EntLib...Validation DLL but I am obviously missing something. Can you
help?
Thanks