Q: How to mock a validator for unit testing I have a method that validate an Object calling an external service:
public void Validate(IValidator<MyType> validator)
{
    IMapper<MyType> mapper = new MyTypeMapper();
    foreach (var element in this.Elements)
    {
        ValidationResult result = validator.Validate(myTypeInstance, mapper, new ValidationConfiguration());

        if (result.IsValid)
            // do something
        else
            // do something else
     }
}

Now in my unit test I have a collection of elements. And I want that if an element have a given id number the Validate method should return another stub with validation messages:
// arrange
var myAggregate aggregate = ElementsNonValidated.Stub();
var mockedValidator = new Mock<IValidator<MyType>>();

mockedValidator.Setup(a => a.Validate(
                 It.Is<Mytype>(x => x.Id == Guid.Parse("3F2504E0-4F89-11D3-9A0C-0305E82C3301")),
                 new Mapper(),
                 new ValidationConfiguration()
                )).Returns<ValidationResult>(x => x = new ValidationResult());

// act
myAggregate.Valida(mockedValidator.Object);

The problem is: When unit test starts and go forth till the real method validate still return result=null. Why? What's wrong with my mock?

A: The problem is here:
mockedValidator.Setup(a => a.Validate(
             It.Is<Mytype>(x => x.Id == Guid.Parse("3F2504E0-4F89-11D3-9A0C-0305E82C3301")),
             new Mapper(), 
             new ValidationConfiguration()
            )).Returns<ValidationResult>(x => x = new ValidationResult());

You setup Validate to expect specific Mapper and ValidationResult instances, which of course do not match the instances used in your system under test.  If you don't care what instance should be used for a parameter, use It.IsAny<>:
mockedValidator.Setup(a => a.Validate(
             It.Is<Mytype>(x => x.Id == Guid.Parse("3F2504E0-4F89-11D3-9A0C-0305E82C3301")),
             It.IsAny<Mapper>(), 
             It.IsAny<ValidationConfiguration>()
            )).Returns<ValidationResult>(x => x = new ValidationResult());

This will return a new ValidationResult for any and every invocation to Validate where the object's Id is equal to that particular GUID.

The reason for the TargetParameterCountException is in your Returns statement, and is answered here.
