|
@@ -0,0 +1,29 @@
|
|
1
|
+# 开始XUnit
|
|
2
|
+
|
|
3
|
+最简单的就是
|
|
4
|
+```
|
|
5
|
+public void PlayerService_GetAllPlayers_InvalidLeage()
|
|
6
|
+{
|
|
7
|
+ //Arrange
|
|
8
|
+ var mockLeageRepo = new MockLeagueRepository().MockIsValid(false);
|
|
9
|
+ var playerService = new PlayerService(new MockPlayerRepository().Object, new MockTeamRepository().Object, mockLeagueRepo.Object);
|
|
10
|
+
|
|
11
|
+ //Act
|
|
12
|
+ var allPlayers = playerService.GetForLeague(1);
|
|
13
|
+
|
|
14
|
+ //Assert
|
|
15
|
+ Assert.Empty(allPlayers);
|
|
16
|
+ mockLeagueRepo.VerifyIsValid(Times.Once());
|
|
17
|
+}
|
|
18
|
+```
|
|
19
|
+
|
|
20
|
+测试数据源
|
|
21
|
+```
|
|
22
|
+--InlineData特性
|
|
23
|
+--ClassData特性
|
|
24
|
+--MemberData特性
|
|
25
|
+--来自外部json文件
|
|
26
|
+--来自TheoryData<>泛型
|
|
27
|
+```
|
|
28
|
+
|
|
29
|
+案例源码:F:\demos\UnitTest\ThirdDemo
|