我需要在QPushButton里面放一个QMenu.它是否可能,如果可能,那么如何?
我希望实现这样的目标:

我对多个模型对象中的某些属性有类似的规则,我想用自定义属性验证器替换它们,以避免单元测试中的代码重复.
我有我的财产验证人:
public class IntIdPropertyValidator: PropertyValidator
{
public IntIdPropertyValidator()
: base("Property {PropertyName} should be greater than 0")
{
}
protected override bool IsValid(PropertyValidatorContext context)
{
var value = (int)context.PropertyValue;
return value > 0;
}
}
Run Code Online (Sandbox Code Playgroud)
并在模型验证器类中连接它:
public class SomeRequestValidator : AbstractValidator<CreateWordRequest>
{
public SomeRequestValidator()
{
RuleFor(x => x.Id).SetValidator(new IntIdPropertyValidator());
}
}
Run Code Online (Sandbox Code Playgroud)
试图测试:
[Test]
public void Validate_IdHasValidator_Success()
{
Init();
validator.ShouldHaveChildValidator(x => x.Id, typeof(IntIdPropertyValidator));
}
Run Code Online (Sandbox Code Playgroud)
但测试总是失败.
那么,我如何测试实际为属性Id设置的验证器?