We cannot use ShouldHaveValidationErrorFor and ShouldNotHaveValidationErrorFor methods for nested properties. For example, for tested class has a property of another class. For example, we cannot write:
validator.ShouldHaveValidationErrorFor(x => x.AddNewComment.CommentText, model);
(an exception is thrown)
For more info please get the latest development version of nopCommerce (open source shopping cart). It's not an official release yet, so get it here http://nopcommerce.codeplex.com/SourceControl/list/changesets . Open Nop.Web.MVC.Tests project, then \Public\Validators\Blogs\BlogPostValidatorTests.cs unit test file. Look at its implementation
Comments: The test helper extensions are only designed to work with simple cases - you'll need to assert the result of performing validation manually when working with complex child properties.
validator.ShouldHaveValidationErrorFor(x => x.AddNewComment.CommentText, model);
(an exception is thrown)
For more info please get the latest development version of nopCommerce (open source shopping cart). It's not an official release yet, so get it here http://nopcommerce.codeplex.com/SourceControl/list/changesets . Open Nop.Web.MVC.Tests project, then \Public\Validators\Blogs\BlogPostValidatorTests.cs unit test file. Look at its implementation
Comments: The test helper extensions are only designed to work with simple cases - you'll need to assert the result of performing validation manually when working with complex child properties.