-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathDomainClassTests.cs
116 lines (104 loc) · 3.6 KB
/
DomainClassTests.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using Domain;
using System;
using System.Drawing;
using System.Linq;
using System.Reflection;
using Xunit;
namespace test
{
public class DomainClassTests
{
private static Team CreateTeamAjax()
{
return new Team("AFC Ajax", "The Lancers", "1900", "Amsterdam Arena");
}
[Fact]
public void NewTeamGetsId()
{
var team = CreateTeamAjax();
var privateId = typeof(Team).GetProperty("Id", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotEqual(Guid.Empty, privateId.GetValue(team));
}
[Fact]
public void TeamAllowsNewPlayer()
{
var team = CreateTeamAjax();
team.AddPlayer("André", "Onana", out string response);
Assert.Equal("André Onana", team.Players.First().Name);
}
[Fact]
public void TeamAllowsMultiplePlayers()
{
var team = CreateTeamAjax();
team.AddPlayer("André", "Onana", out string response);
team.AddPlayer("Matthijs", "de Ligt", out response);
Assert.Equal(2, team.Players.Count());
}
[Fact]
public void TeamPreventsDuplicatePlayer()
{
var team = CreateTeamAjax();
team.AddPlayer("André", "Onana", out string response);
team.AddPlayer("André", "Onana", out response);
Assert.Single(team.Players);
}
[Fact]
public void TeamReturnsDuplicateMessageForDuplicatePlayer()
{
var team = CreateTeamAjax();
team.AddPlayer("André", "Onana", out string response);
team.AddPlayer("André", "Onana", out response);
Assert.Equal("Duplicate player", response);
}
[Fact]
public void CanAddManager()
{
var team = CreateTeamAjax();
var firstmanager = new Manager("Marcel", "Keizer");
team.ChangeManagement(firstmanager);
var privateId = typeof(Team).GetProperty("Id", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.Equal(privateId.GetValue(team), firstmanager.CurrentTeamId);
Assert.Equal(firstmanager.Name, team.ManagerName);
}
[Fact]
public void CanReplaceManager()
{
var team = CreateTeamAjax();
var firstmanager = new Manager("Marcel", "Keizer");
team.ChangeManagement(firstmanager);
var newmanager = (new Manager("Erik", "ten Hag"));
team.ChangeManagement(newmanager);
var privateId = typeof(Team).GetProperty("Id", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.Equal(privateId.GetValue(team), newmanager.CurrentTeamId);
Assert.Equal(newmanager.Name, team.ManagerName);
}
[Fact]
public void ReplacedManagerHasNoCurrentTeamId()
{
var team = CreateTeamAjax();
var firstmanager = new Manager("Marcel", "Keizer");
team.ChangeManagement(firstmanager);
var newmanager = (new Manager("Erik", "ten Hag"));
team.ChangeManagement(newmanager);
Assert.Null(firstmanager.CurrentTeamId);
}
[Fact]
public void ReplacedManagerHasOldTeamIdInPastIds()
{
var team = CreateTeamAjax();
var firstmanager = new Manager("Marcel", "Keizer");
team.ChangeManagement(firstmanager);
var newmanager = (new Manager("Erik", "ten Hag"));
team.ChangeManagement(newmanager);
var privateId = typeof(Team).GetProperty("Id", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.Equal(privateId.GetValue(team), firstmanager.PastTeams.FirstOrDefault().TeamId);
}
[Fact]
public void CanSetHomeColors()
{
var team = CreateTeamAjax();
team.SpecifyHomeUniformColors(Color.White, Color.Red);
Assert.Equal(new Color[] { Color.White, Color.Red }, new Color[] { team.HomeColors.Primary, team.HomeColors.Secondary });
}
}
}