【问题标题】:Bogus faked strings length in range between values值之间范围内的伪造字符串长度
【发布时间】:2021-06-13 11:37:12
【问题描述】:

我正在为 Bogus 生成的字符串属性编写规则:

var fakeThings= new Faker<Thing>()
   .RuleFor(x => x.Name, f => f.Company.CompanyName());

如何在指定值之间生成Bogus中的字符串属性?比如:

.RuleFor(x => x.Name, f => f.Company.CompanyName().Length(1, 30);
// returns CompanyName with min 1 char and max 30 chars

【问题讨论】:

    标签: c# faker bogus


    【解决方案1】:

    您还可以对任何string 使用.ClampLength(min, max) 扩展方法。例如:

    using Bogus.Extensions;
    
    .RuleFor(x => x.Name, f => f.Company.CompanyName().ClampLength(1, 30));
    

    【讨论】:

      【解决方案2】:

      实际上,这取决于您使用的版本。我建议您根据所需的字符集尝试String2Utf16String

      .RuleFor(x => x.Name, f => f.Random.String2(1, 30);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-19
        • 2010-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多