-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBootstrapBlazorTestBase.cs
More file actions
59 lines (48 loc) · 1.78 KB
/
BootstrapBlazorTestBase.cs
File metadata and controls
59 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using Bunit;
using Microsoft.Extensions.Configuration;
namespace UnitTestEditor;
public class BootstrapBlazorTestBase : IDisposable
{
protected BunitContext Context { get; }
protected ICacheManager Cache { get; }
public BootstrapBlazorTestBase()
{
Context = new BunitContext();
Context.JSInterop.Mode = JSRuntimeMode.Loose;
ConfigureServices(Context.Services);
ConfigureConfiguration(Context.Services);
// 渲染 BootstrapBlazorRoot 组件 激活 ICacheManager 接口
Cache = Context.Services.GetRequiredService<ICacheManager>();
}
protected virtual void ConfigureServices(IServiceCollection services)
{
services.AddBootstrapBlazor();
services.ConfigureJsonLocalizationOptions(op =>
{
op.IgnoreLocalizerMissing = false;
});
}
protected virtual void ConfigureConfiguration(IServiceCollection services)
{
// 增加单元测试 appsettings.json 配置文件
var builder = new ConfigurationBuilder();
//builder.AddJsonFile("appsettings.json");
//if (cultureName != null)
//{
// builder.AddInMemoryCollection(new Dictionary<string, string?>()
// {
// ["BootstrapBlazorOptions:DefaultCultureInfo"] = cultureName
// });
//}
var config = builder.Build();
services.AddSingleton<IConfiguration>(config);
}
public void Dispose()
{
Context.Dispose();
GC.SuppressFinalize(this);
}
}