forked from dillenmeister/Trello.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemberTests.cs
202 lines (160 loc) · 6.09 KB
/
MemberTests.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
using System;
using System.Linq;
using ExpectedObjects;
using NUnit.Framework;
namespace TrelloNet.Tests
{
[TestFixture]
public class MemberTests : TrelloTestBase
{
[Test]
public void Me_Always_ReturnsTheMemberMe()
{
var expectedMe = CreateExpectedMemberMe();
var actualMe = _trelloReadOnly.Members.Me();
expectedMe.ShouldMatch(actualMe);
}
[Test]
public void WithId_Trello_ReturnsTheMemberTrello()
{
var expectedMember = CreateExpectedMemberTrello();
var actualMember = _trelloReadOnly.Members.WithId("trello");
expectedMember.ShouldMatch(actualMember);
Assert.That(string.IsNullOrEmpty(actualMember.Bio));
}
[Test]
public void WithId_IdOfTrello_ReturnsTheMemberTrello()
{
var expectedMember = CreateExpectedMemberTrello();
var actualMember = _trelloReadOnly.Members.WithId("4e6a7fad05d98b02ba00845c");
expectedMember.ShouldMatch(actualMember);
Assert.That(string.IsNullOrEmpty(actualMember.Bio));
}
[Test]
public void WithId_NonExistingMember_ReturnsNull()
{
var member = _trelloReadOnly.Members.WithId("nonexistingmember123");
Assert.That(member, Is.Null);
}
[Test]
public void WithId_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Members.WithId(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "idOrUsername"));
}
[Test]
public void ForCard_WelcomeCardOfTheWelcomeBoard_ReturnsMeOnly()
{
var members = _trelloReadOnly.Members.ForCard(new CardId(Constants.WelcomeCardOfTheWelcomeBoardId));
Assert.That(members.Count(), Is.EqualTo(1));
Assert.That(members.First().Id, Is.EqualTo(Constants.MeId));
}
[Test]
public void ForCard_WelcomeCardOfTheWelcomeBoard_AllFieldsOfMemberAreMapped()
{
var expectedMember = CreateExpectedMemberMe();
var actualMember = _trelloReadOnly.Members.ForCard(new CardId(Constants.WelcomeCardOfTheWelcomeBoardId)).Single(m => m.Id == Constants.MeId);
expectedMember.ShouldMatch(actualMember);
}
[Test]
public void ForCard_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Members.ForCard(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "card"));
}
[Test]
public void ForBoard_WelcomeBoard_ReturnsThreeMembers()
{
var members = _trelloReadOnly.Members.ForBoard(new BoardId(Constants.WelcomeBoardId));
Assert.That(members.Count(), Is.EqualTo(3));
}
[Test, Description("Seems like the invitation expires, so we just check that we get no exception here really")]
public void InvitedForBoard_WelcomeBoard_Returns1Member()
{
var members = _trelloReadOnly.Members.InvitedForBoard(new BoardId(Constants.WelcomeBoardId));
Assert.That(members.Count(), Is.EqualTo(0));
}
[Test]
public void ForBoard_WelcomeBoard_AllFieldsOfMemberAreMapped()
{
var expectedMember = CreateExpectedMemberMe();
var actualMember = _trelloReadOnly.Members.ForBoard(new BoardId(Constants.WelcomeBoardId)).Single(m => m.Id == Constants.MeId);
expectedMember.ShouldMatch(actualMember);
}
[Test]
public void ForBoard_WelcomeBoardAndFilterOwner_ReturnsOneMember()
{
var members = _trelloReadOnly.Members.ForBoard(new BoardId(Constants.WelcomeBoardId), MemberFilter.Owners);
Assert.That(members.Count(), Is.EqualTo(1));
Assert.That(members.First().Id, Is.EqualTo(Constants.MeId));
}
[Test]
public void ForBoard_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Members.ForBoard(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "board"));
}
[Test]
public void ForOrganization_TestOrganization_ReturnsMe()
{
var members = _trelloReadOnly.Members.ForOrganization(new OrganizationId(Constants.TestOrganizationId));
Assert.That(members.Count(), Is.EqualTo(1));
Assert.That(members.First().Id, Is.EqualTo(Constants.MeId));
}
[Test]
public void ForOrganization_TestOrganization_AllFieldsOfMemberAreMapped()
{
var expectedMember = CreateExpectedMemberMe();
var actualMember = _trelloReadOnly.Members.ForOrganization(new OrganizationId(Constants.TestOrganizationId)).Single(m => m.Id == Constants.MeId);
expectedMember.ShouldMatch(actualMember);
}
[Test]
public void ForOrganization_Null_Throws()
{
Assert.That(() => _trelloReadOnly.Members.ForOrganization(null),
Throws.TypeOf<ArgumentNullException>().With.Matches<ArgumentNullException>(e => e.ParamName == "organization"));
}
[Test]
public void ForToken_TokenOfMe_ReturnsMe()
{
var expected = CreateExpectedMemberMe();
var member = _trelloReadOnly.Members.ForToken("a0f05ce01f11b4dceb1127e244bdc9c45705d44f3ec1b349f3f4a4c306e20fcf");
expected.ShouldMatch(member);
}
[Test]
public void ToString_EqualsFullName()
{
var member = new Member { FullName = "a name" };
Assert.That(member.ToString(), Is.EqualTo("a name"));
}
private static ExpectedObject CreateExpectedMemberMe()
{
// The reason we return an anonymous type instead of Member is because we dont know what Member.Status will be, and this is a way of not comparing that property
// Also for some unknown reason GravatarHash returns different results for different API calls. Not important enough to troubleshoot.
return new
{
FullName = "Trello.NET Test User",
Bio = "Test bio",
Url = "https://trello.com/trellnettestuser",
Username = "trellnettestuser",
Id = Constants.MeId,
AvatarHash = "076e3caed758a1c18c91a0e9cae3368f",
Initials = "TU"
// Status = <-- Ignore status since we don't know
}.ToExpectedObject();
}
private static ExpectedObject CreateExpectedMemberTrello()
{
return new
{
FullName = "Trello",
Url = "https://trello.com/trello",
Username = "trello",
Id = "4e6a7fad05d98b02ba00845c",
AvatarHash = "a6cc37f6849928acb91064cf65e61cbc",
Initials = "T",
Status = MemberStatus.Disconnected
}.ToExpectedObject();
}
}
}