c# - 值之间范围内的伪造字符串长度
问题描述
我为 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
解决方案
您还可以将.ClampLength(min, max)
扩展方法用于任何string
. 例如:
using Bogus.Extensions;
.RuleFor(x => x.Name, f => f.Company.CompanyName().ClampLength(1, 30));
推荐阅读
- amazon-web-services - AppSync 到 DynamoDB 更新查询映射错误
- heroku - heroku 自定义域:主机
- c# - 无法让泛型工作 - 不接受变量
- java - 如何在 protobuf 消息中建模 Java 原始 int[] 数组
- sql - 将多个查询合并为一个查询
- kubernetes - Kubernetes ReadOnlyMany + ReadWriteOnce
- phpmyadmin - PHP7 没有在 apache2 上正确安装?
- visual-studio - Visual Studio 中的 Service Fabric 服务模板
- python - 我的 LSTM 模型精度只有 0.5 左右
- javascript - 使用 JavaScript 对象构造函数更改文本颜色