forked from dillenmeister/Trello.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListTests.cs
211 lines (160 loc) · 5.99 KB
/
ListTests.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Linq;
using ExpectedObjects;
using NUnit.Framework;
namespace TrelloNet.Tests
{
[TestFixture]
public class ListTests : TrelloTestBase
{
private readonly IBoardId _welcomeBoardWritable = new BoardId("4f41e4803374646b5c74bd69");
private readonly IListId _basicsListWritable = new ListId(Constants.WritableListId);
[Test]
public void WithId_WelcomeBoardBasicsList_ReturnsTheBasicsList()
{
var expectedList = CreateExpectedBasicsList();
var actualList = _trelloReadOnly.Lists.WithId(Constants.WelcomeBoardBasicsListId);
expectedList.ShouldEqual(actualList);
}
[Test]
public void WithId_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Lists.WithId(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "id"));
}
[Test]
public void ForBoard_WelcomeBoard_AllFieldsOfListAreMapped()
{
var expectedList = CreateExpectedBasicsList();
var list = _trelloReadOnly.Lists.ForBoard(new BoardId(Constants.WelcomeBoardId)).Single(l => l.Id == Constants.WelcomeBoardBasicsListId);
expectedList.ShouldEqual(list);
}
[Test]
public void ForBoard_WelcomeBoard_ReturnsThreeLists()
{
var lists = _trelloReadOnly.Lists.ForBoard(new BoardId(Constants.WelcomeBoardId));
Assert.That(lists, Has.Count.EqualTo(3));
}
[Test]
public void ForBoard_WelcomeBoardAndClosed_ReturnsTwoLists()
{
var lists = _trelloReadOnly.Lists.ForBoard(new BoardId(Constants.WelcomeBoardId), ListFilter.Closed);
Assert.That(lists, Has.Count.EqualTo(2));
}
[Test]
public void ForBoard_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Lists.ForBoard(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "board"));
}
[Test]
public void ForCard_WelcomeCardOfTheWelcomeBoard_ReturnsWelcomeBoardBasicsList()
{
var expectedList = CreateExpectedBasicsList();
var list = _trelloReadOnly.Lists.ForCard(new CardId(Constants.WelcomeCardOfTheWelcomeBoardId));
expectedList.ShouldEqual(list);
}
[Test]
public void ForCard_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Lists.ForCard(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "card"));
}
[Test]
public void Scenario_AddAndArchive()
{
var list = _trelloReadWrite.Lists.Add(new NewList("A new list", _welcomeBoardWritable));
Assert.That(list.Closed, Is.False);
Assert.That(list.IdBoard, Is.EqualTo(_welcomeBoardWritable.GetBoardId()));
Assert.That(list.Name, Is.EqualTo("A new list"));
_trelloReadWrite.Lists.Archive(list);
var closedList = _trelloReadWrite.Lists.WithId(list.Id);
Assert.That(closedList.Closed, Is.True);
}
[Test]
public void Scenario_ArchiveAndUnarchive()
{
_trelloReadWrite.Lists.Archive(_basicsListWritable);
var closedList = _trelloReadWrite.Lists.WithId(_basicsListWritable.GetListId());
Assert.That(closedList.Closed, Is.True);
_trelloReadWrite.Lists.Unarchive(closedList);
var reopenedList = _trelloReadWrite.Lists.WithId(_basicsListWritable.GetListId());
Assert.That(reopenedList.Closed, Is.False);
}
[Test]
public void Scenario_ChangeName()
{
_trelloReadWrite.Lists.ChangeName(_basicsListWritable, "A new name");
var listWithChangedName = _trelloReadWrite.Lists.WithId(_basicsListWritable.GetListId());
Assert.That(listWithChangedName.Name, Is.EqualTo("A new name"));
_trelloReadWrite.Lists.ChangeName(_basicsListWritable, "Basics");
}
[Test]
public void ToString_EqualsName()
{
var list = new List { Name = "a name" };
Assert.That(list.ToString(), Is.EqualTo("a name"));
}
[TestCase("")]
[TestCase(null)]
public void Add_NameIsInvalid_Throws(string name)
{
Assert.That(() => _trelloReadOnly.Lists.Add(new NewList(name, new BoardId("dummy"))),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void Add_NameIsTooLong_Throws()
{
Assert.That(() => _trelloReadOnly.Lists.Add(new NewList(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.Lists.ChangeName(new ListId("dummy"), name),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void ChangeName_NameIsTooLong_Throws()
{
Assert.That(() => _trelloReadWrite.Lists.ChangeName(new ListId("dummy"), new string('x', 16385)),
Throws.InstanceOf<ArgumentException>().With.Matches<ArgumentException>(e => e.ParamName == "name"));
}
[Test]
public void Scenario_UpdateNameAndClosed()
{
var list = _trelloReadWrite.Lists.WithId(Constants.WritableListId);
list.Name = "Updated name";
list.Closed = true;
_trelloReadWrite.Lists.Update(list);
var listAfterUpdate = _trelloReadWrite.Lists.WithId(list.Id);
list.Name = "Basics";
list.Closed = false;
_trelloReadWrite.Lists.Update(list);
Assert.That(listAfterUpdate.Name, Is.EqualTo("Updated name"));
Assert.That(listAfterUpdate.Closed, Is.EqualTo(true));
}
[Test, Ignore("Trello does something, the position when getting the list agais is not 1234")]
public void Scenario_ChangePosOfList()
{
var list = _trelloReadWrite.Lists.WithId(Constants.WritableListId);
var previousPos = list.Pos;
_trelloReadWrite.Lists.ChangePos(list, 1234);
var listAfterPosChange = _trelloReadWrite.Lists.WithId(Constants.WritableListId);
Assert.That(listAfterPosChange.Pos, Is.EqualTo(1234));
_trelloReadWrite.Lists.ChangePos(list, previousPos);
}
private static ExpectedObject CreateExpectedBasicsList()
{
return new List
{
Closed = false,
Id = Constants.WelcomeBoardBasicsListId,
IdBoard = Constants.WelcomeBoardId,
Name = "Basics",
Pos = 16384
}.ToExpectedObject();
}
}
}