Is it a bad practice for unit test that a class uses a specific verification class to authenticate an object?

I run all my actions through classes, which I call "commands." To illustrate this, to create a new user, I would call the following code

new CreateUserCommand(unitOfWork).SetName("Username").SetPassword("Blah").Execute();

Now I am considering the implementation of verification on this system to check things like password, specific length, username is not a duplicate in the database, etc.

To deal with this, I am considering using the correct validation and creating a validation class for each type of authentication object I want. For example, I will have a class, for example

public class NewUserValidation : ValidationFor<User>
{
   public NewUserValidation() 
   {
     // Validation Rules here
   }
}

, (, ).

. , , , .

, ( , , )? , , - .

, , , , , unit test, . , - , Execute() ( , ).

, , , . , ?


Edit: To answer both answers below, validation will be used inside the method Execute(), invoked validator.Validate(entity)in the implementation Execute().

Although I don’t want to violate DRY, I don’t see an easy way to verify that Execute()1) uses the correct validation class by default and 2) Actually calls the .validate(entity)validation class method ,

I can solve # 1 by creating an instance of the validation class in the constructor and exposing it through the public property of the command class, but I'm not sure how to correctly unit test for the second problem without repeating a separate test validation unit.

+3
source share
3 answers

. , , , , .

, , , . , .


EDIT: .

Execute, , validate . , , .

(stackoverflow.com). , , .


EDIT: (stackoverflow.com). , . Microsoft Moles (microsoft.com) .

+2

DRY, , . , Execute . unit test Execute? , ?

, , ", ". , factory Command.

unit test , Command. Command , , unit test, , . , , .

+1

, validationFalingTest, .

, . , .

0

All Articles