c# - 构建配置后如何更新 IOptions?
问题描述
上下文: 在集成测试中,我们需要使用不同的选项来测试不同的案例。我不想为每个测试创建一个不同的 TestServerFixture。
请求: 我正在寻找全局更新 IOptions 的可能性。
测试服务器夹具:
public Dictionary<string, string> Data {get; set;} = new Dictionary<string, string>
{
{"identity:claimsidentity:roleclaimtype", roleClaimType},
{"identity:claimsidentity:usernameclaimtype", usernameClaimType},
{"identity:claimsidentity:useridclaimtype", useridClaimType},
{"identity:claimsidentity:securitystampclaimtype", securityStampClaimType},
{"identity:user:requireUniqueEmail", "true"},
{"identity:password:RequiredLength", "10"},
{"identity:password:RequireNonAlphanumeric", "false"},
{"identity:password:RequireUpperCase", "false"},
{"identity:password:RequireDigit", "false"},
{"identity:password:RequireLowerCase", "false"},
{"identity:lockout:AllowedForNewUsers", "FALSe"},
{"identity:lockout:MaxFailedAccessAttempts", "1000"}
};
[..]
var hostBuilder = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, builder) =>
{
builder
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.AddInMemoryCollection(Data);
})
[..]
测试:
[Fact]
public async Task Should_Do_Something()
{
// When I do a call to the server, identity:user:requireUniqueEmail will be true
TestServerFixture.Data = //New Data with identity:user:requireUniqueEmail = false;
// When I do a call to the server, identity:user:requireUniqueEmail will be false
}
因此,每次我为属性 Data 设置一个新值时,它都会自动更新当前配置。
你知道怎么做吗?
解决方案
推荐阅读
- excel - 使用 python 预加载(刷新)tableau 工作簿(工作表)
- rest - 是否可以向 REST 端点发送 SOAP 请求?
- python-3.x - 在 python 3 中使用打印命令的结果作为输入值
- r - 从预测对象中提取值并绘制箱线图
- sqlite - 对数据库执行 sql 查询时出错
- php - 在用户个人资料中保存联系表格 7 数据 (Woocommerce)
- .net - linq to sql 字符串属性包含查询参数数组
- html - 使用 BFO、Freemarker 和 HTML 在多个页面上重复表格列标题 - NetSuite
- angular - RxJs:从孩子那里收集一定数量的“回调”
- google-cloud-firestore - 在 Purescript 中建模 Javascript 对象