Skip to content

Commit 74e55cb

Browse files
committed
test: 增加单元测试
1 parent 49d4b8e commit 74e55cb

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

test/UnitTestRegion/RegionTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace UnitTestRegion;
6+
7+
public class RegionTest
8+
{
9+
[Fact]
10+
public void Test1()
11+
{
12+
13+
}
14+
}

test/UnitTestRegion/ServiceTest.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
namespace UnitTestRegion;
6+
7+
public class UnitTest1
8+
{
9+
[Fact]
10+
public void GetCities_Ok()
11+
{
12+
var sc = new ServiceCollection();
13+
sc.AddBootstrapBlazorRegionService();
14+
15+
var provider = sc.BuildServiceProvider();
16+
var regionService = provider.GetRequiredService<IRegionService>();
17+
18+
var provinces = regionService.GetProvinces();
19+
Assert.Equal(34, provinces.Count);
20+
21+
var cities = regionService.GetCities("北京市");
22+
Assert.Empty(cities);
23+
24+
cities = regionService.GetCities("河北省");
25+
Assert.Equal(11, cities.Count);
26+
27+
cities = regionService.GetCities("台湾省");
28+
Assert.Equal(9, cities.Count);
29+
}
30+
31+
[Fact]
32+
public void GetCounties_Ok()
33+
{
34+
var sc = new ServiceCollection();
35+
sc.AddBootstrapBlazorRegionService();
36+
37+
var provider = sc.BuildServiceProvider();
38+
var regionService = provider.GetRequiredService<IRegionService>();
39+
40+
var counties = regionService.GetCounties("北京市");
41+
Assert.Equal(16, counties.Count);
42+
43+
counties = regionService.GetCounties("天津市");
44+
Assert.Equal(16, counties.Count);
45+
46+
counties = regionService.GetCounties("承德市");
47+
Assert.Equal(11, counties.Count);
48+
49+
counties = regionService.GetCounties("嘉义市");
50+
Assert.Equal(15, counties.Count);
51+
52+
counties = regionService.GetCounties("重庆市");
53+
Assert.Equal(38, counties.Count);
54+
}
55+
56+
[Fact]
57+
public void GetDetails_Ok()
58+
{
59+
var sc = new ServiceCollection();
60+
sc.AddBootstrapBlazorRegionService();
61+
62+
var provider = sc.BuildServiceProvider();
63+
var regionService = provider.GetRequiredService<IRegionService>();
64+
65+
var details = regionService.GetDetails("659012");
66+
Assert.Equal(4, details.Count);
67+
}
68+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
12+
<PackageReference Include="xunit" Version="2.9.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.*" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\src\components\BootstrapBlazor.Region\BootstrapBlazor.Region.csproj" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Using Include="Xunit" />
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)