forked from dillenmeister/Trello.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChecklistTests.cs
184 lines (147 loc) · 6.11 KB
/
ChecklistTests.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Collections.Generic;
using System.Linq;
using ExpectedObjects;
using NUnit.Framework;
namespace TrelloNet.Tests
{
[TestFixture]
public class ChecklistTests : TrelloTestBase
{
private readonly IBoardId _welcomeBoardWritable = new BoardId("4f41e4803374646b5c74bd69");
[Test]
public void ForBoard_WelcomeBoard_ReturnsFourChecklists()
{
var checkLists = _trelloReadOnly.Checklists.ForBoard(new BoardId(Constants.WelcomeBoardId));
Assert.That(checkLists.Count(), Is.EqualTo(2));
}
[Test]
public void ForBoard_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Checklists.ForBoard(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "board"));
}
[Test]
public void GetByCard_TheChecklistCard_ReturnsOneChecklist()
{
var checkLists = _trelloReadOnly.Checklists.ForCard(new CardId("4f2b8b4d4f2cb9d16d3684fc"));
Assert.That(checkLists.Count(), Is.EqualTo(1));
}
[Test]
public void ForCard_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Checklists.ForCard(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "card"));
}
[Test]
public void WithId_AChecklist_ReturnsThatChecklist()
{
var expectedChecklist = new Checklist
{
Id = "4f2b8b4d4f2cb9d16d3684c7",
IdBoard = Constants.WelcomeBoardId,
Name = "Checklist",
Pos = 16384,
CheckItems = new List<CheckItem>
{
new CheckItem { Id = "4f2b8b4d4f2cb9d16d3684c4", Name = "Make your own boards", Pos = 16481 },
new CheckItem { Id = "4f2b8b4d4f2cb9d16d3684c5", Name = "Invite your team", Pos = 33232 },
new CheckItem { Id = "4f2b8b4d4f2cb9d16d3684c6", Name = "Enjoy an ice-cold lemonade", Pos = 49687 }
}
}.ToExpectedObject();
var actualChecklist = _trelloReadOnly.Checklists.WithId("4f2b8b4d4f2cb9d16d3684c7");
expectedChecklist.ShouldEqual(actualChecklist);
}
[Test]
public void WithId_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Checklists.WithId(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "id"));
}
[Test]
public void ToString_EqualsName()
{
var checklist = new Checklist { Name = "a name" };
Assert.That(checklist.ToString(), Is.EqualTo("a name"));
}
[Test]
public void Scenario_AddChecklist()
{
var checklist = _trelloReadWrite.Checklists.Add("a new checklist", _welcomeBoardWritable);
Assert.That(checklist.CheckItems.Count, Is.EqualTo(0));
Assert.That(checklist.Id, Is.Not.Empty);
Assert.That(checklist.IdBoard, Is.EqualTo(_welcomeBoardWritable.GetBoardId()));
Assert.That(checklist.Name, Is.EqualTo("a new checklist"));
}
[Test]
public void Scenario_ChangeNameOfAChecklist()
{
var checklist = _trelloReadWrite.Checklists.Add("a checklist", _welcomeBoardWritable);
_trelloReadWrite.Checklists.ChangeName(checklist, "a new name");
var checklistAfterChange = _trelloReadWrite.Checklists.WithId(checklist.Id);
Assert.That(checklistAfterChange.Name, Is.EqualTo("a new name"));
}
[Test]
public void Scenario_AddAndDeleteCheckItem()
{
var checklist = _trelloReadWrite.Checklists.Add("a checklist", _welcomeBoardWritable);
_trelloReadWrite.Checklists.AddCheckItem(checklist, "a new check item");
var checklistAfterAdd = _trelloReadWrite.Checklists.WithId(checklist.Id);
Assert.That(checklistAfterAdd.CheckItems.Count, Is.EqualTo(1));
Assert.That(checklistAfterAdd.CheckItems.First().Name, Is.EqualTo("a new check item"));
_trelloReadWrite.Checklists.RemoveCheckItem(checklist, checklistAfterAdd.CheckItems.First().Id);
var checklistAfterRemove = _trelloReadWrite.Checklists.WithId(checklist.Id);
Assert.That(checklistAfterRemove.CheckItems.Count, Is.EqualTo(0));
}
[TestCase("")]
[TestCase(null)]
public void Add_NameIsInvalid_Throws(string name)
{
Assert.That(() => _trelloReadWrite.Checklists.Add(name, new BoardId("dummy")),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void Add_NameIsTooLong_Throws()
{
Assert.That(() => _trelloReadWrite.Checklists.Add(new string('x', 16385), new BoardId("dummy")),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[TestCase("")]
[TestCase(null)]
public void ChangeName_NameIsInvalid_Throws(string name)
{
Assert.That(() => _trelloReadWrite.Checklists.ChangeName(new ChecklistId("dummy"), name),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void ChangeName_NameIsTooLong_Throws()
{
Assert.That(() => _trelloReadWrite.Checklists.ChangeName(new ChecklistId("dummy"), new string('x', 16385)),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[TestCase("")]
[TestCase(null)]
public void AddCheckItem_NameIsInvalid_Throws(string name)
{
Assert.That(() => _trelloReadWrite.Checklists.AddCheckItem(new ChecklistId("dummy"), name),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void AddCheckItem_NameIsTooLong_Throws()
{
Assert.That(() => _trelloReadWrite.Checklists.AddCheckItem(new ChecklistId("dummy"), new string('x', 16385)),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void Scenario_UpdateName()
{
var checklist = _trelloReadWrite.Checklists.WithId("4f41e4803374646b5c74bd67");
checklist.Name = "Updated name";
_trelloReadWrite.Checklists.Update(checklist);
var checklistsAfterUpdate = _trelloReadWrite.Checklists.WithId(checklist.Id);
checklist.Name = "Checklist";
_trelloReadWrite.Checklists.Update(checklist);
Assert.That(checklistsAfterUpdate.Name, Is.EqualTo("Updated name"));
}
}
}