• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rwjdk / TrelloDotNet / 15715919831

17 Jun 2025 07:01PM UTC coverage: 79.816% (-0.5%) from 80.303%
15715919831

push

github

rwjdk
Version 2.0.6

2539 of 3460 branches covered (73.38%)

Branch coverage included in aggregate %.

27 of 75 new or added lines in 9 files covered. (36.0%)

6 existing lines in 2 files now uncovered.

4480 of 5334 relevant lines covered (83.99%)

107.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.22
/src/TrelloDotNet/TrelloClient.Boards.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Security;
5
using System.Text.Json;
6
using System.Threading;
7
using System.Threading.Tasks;
8
using TrelloDotNet.Control;
9
using TrelloDotNet.Model;
10
using TrelloDotNet.Model.Options;
11
using TrelloDotNet.Model.Options.GetBoardOptions;
12
using TrelloDotNet.Model.Options.UpdateBoardPreferencesOptions;
13

14
// ReSharper disable UnusedMember.Global
15

16
namespace TrelloDotNet
17
{
18
    public partial class TrelloClient
19
    {
20
        /// <summary>
21
        /// Creates a new Trello board with the specified properties and optional configuration options.
22
        /// </summary>
23
        /// <param name="board">The Board object containing the properties for the new board</param>
24
        /// <param name="options">Optional settings for the new board, such as default labels or lists</param>
25
        /// <param name="cancellationToken">Cancellation Token</param>
26
        /// <returns>The newly created Board object</returns>
27
        public async Task<Board> AddBoardAsync(Board board, AddBoardOptions options = null, CancellationToken cancellationToken = default)
28
        {
29
            var parameters = _queryParametersBuilder.GetViaQueryParameterAttributes(board).ToList();
33✔
30
            if (options != null)
33✔
31
            {
32
                parameters.AddRange(_queryParametersBuilder.GetViaQueryParameterAttributes(options));
1✔
33
            }
34

35
            return await _apiRequestController.Post<Board>($"{UrlPaths.Boards}", cancellationToken, parameters.ToArray());
33✔
36
        }
33✔
37

38
        /// <summary>
39
        /// Closes (archives) a board, making it inactive but not permanently deleted. The board can be reopened later.
40
        /// </summary>
41
        /// <param name="boardId">ID of the board to close</param>
42
        /// <param name="cancellationToken">Cancellation Token</param>
43
        /// <returns>The closed Board object</returns>
44
        public async Task<Board> CloseBoardAsync(string boardId, CancellationToken cancellationToken = default)
45
        {
46
            return await _apiRequestController.Put<Board>($"{UrlPaths.Boards}/{boardId}", cancellationToken, new QueryParameter("closed", true));
1✔
47
        }
1✔
48

49
        /// <summary>
50
        /// Reopens a board that was previously closed (archived), making it active again.
51
        /// </summary>
52
        /// <param name="boardId">ID of the board to reopen</param>
53
        /// <param name="cancellationToken">Cancellation Token</param>
54
        /// <returns>The reopened Board object</returns>
55
        public async Task<Board> ReOpenBoardAsync(string boardId, CancellationToken cancellationToken = default)
56
        {
57
            return await _apiRequestController.Put<Board>($"{UrlPaths.Boards}/{boardId}", cancellationToken, new QueryParameter("closed", false));
1✔
58
        }
1✔
59

60
        /// <summary>
61
        /// Updates the properties of an existing board with the specified changes.
62
        /// </summary>
63
        /// <param name="boardWithChanges">A Board object containing the updated properties (must include the board's ID)</param>
64
        /// <param name="cancellationToken">Cancellation Token</param>
65
        /// <returns>The updated Board object</returns>
66
        [Obsolete("Use UpdateBoard overload that does delta updates (List<BoardUpdate> valuesToUpdate). This Method will be removed in TrelloDotNet 3.0")]
67
        public async Task<Board> UpdateBoardAsync(Board boardWithChanges, CancellationToken cancellationToken = default)
68
        {
UNCOV
69
            return await _apiRequestController.Put<Board>($"{UrlPaths.Boards}/{boardWithChanges.Id}", cancellationToken, _queryParametersBuilder.GetViaQueryParameterAttributes(boardWithChanges));
×
UNCOV
70
        }
×
71

72
        /// <summary>
73
        /// Updates one or more specific fields on a Board, such as name, description, etc.
74
        /// </summary>
75
        /// <param name="boardId">The ID of the board to update.</param>
76
        /// <param name="valuesToUpdate">A list of updates to apply to the board. <see cref="BoardUpdate"/></param>
77
        /// <param name="cancellationToken">CancellationToken</param>
78
        /// <returns>The updated <see cref="Board"/>.</returns>
79
        public async Task<Board> UpdateBoardAsync(string boardId, List<BoardUpdate> valuesToUpdate, CancellationToken cancellationToken = default)
80
        {
81
            var parameters = valuesToUpdate.Select(x => x.ToQueryParameter()).ToList();
5✔
82
            return await _apiRequestController.Put<Board>($"{UrlPaths.Boards}/{boardId}", cancellationToken, parameters.ToArray());
2✔
83
        }
2✔
84

85
        /// <summary>
86
        /// Permanently deletes a board by its ID. This action cannot be undone. For a reversible option, use CloseBoardAsync instead.
87
        /// </summary>
88
        /// <remarks>
89
        /// As this is a major action, deletion is only allowed if TrelloClient.Options.AllowDeleteOfBoards is set to true as a secondary confirmation.
90
        /// </remarks>
91
        /// <param name="boardId">ID of the board to delete</param>
92
        /// <param name="cancellationToken">Cancellation Token</param>
93
        public async Task DeleteBoardAsync(string boardId, CancellationToken cancellationToken = default)
94
        {
95
            if (Options.AllowDeleteOfBoards)
52✔
96
            {
97
                await _apiRequestController.Delete($"{UrlPaths.Boards}/{boardId}", cancellationToken, 0);
27✔
98
            }
99
            else
100
            {
101
                throw new SecurityException("Deletion of Boards are disabled via Options.AllowDeleteOfBoards (You need to enable this as a secondary confirmation that you REALLY wish to use that option as there is no going back: https://support.atlassian.com/trello/docs/deleting-a-board/)");
25✔
102
            }
103
        }
27✔
104

105
        /// <summary>
106
        /// Retrieves a board by its ID.
107
        /// </summary>
108
        /// <param name="boardId">ID of the board</param>
109
        /// <param name="cancellationToken">Cancellation Token</param>
110
        /// <returns>The Board object with the specified ID</returns>
111
        public async Task<Board> GetBoardAsync(string boardId, CancellationToken cancellationToken = default)
112
        {
113
            return await _apiRequestController.Get<Board>(GetUrlBuilder.GetBoard(boardId), cancellationToken);
3✔
114
        }
3✔
115

116
        /// <summary>
117
        /// Retrieves plan information for a specific board, including its subscription level (Free, Standard, Premium, Enterprise) and supported features.
118
        /// </summary>
119
        /// <param name="boardId">ID of the board to get plan information for</param>
120
        /// <param name="cancellationToken">Cancellation Token</param>
121
        /// <returns>A TrelloPlanInformation object describing the board's plan and features</returns>
122
        public async Task<TrelloPlanInformation> GetTrelloPlanInformationForBoardAsync(string boardId, CancellationToken cancellationToken = default)
123
        {
124
            return await _apiRequestController.Get<TrelloPlanInformation>(GetUrlBuilder.GetBoard(boardId, new GetBoardOptions
1✔
125
            {
1✔
126
                BoardFields = new BoardFields("name", "premiumFeatures")
1✔
127
            }), cancellationToken);
1✔
128
        }
1✔
129

130
        /// <summary>
131
        /// Retrieves a board by its ID, with options to include additional nested data such as cards, lists, or organization details.
132
        /// </summary>
133
        /// <param name="boardId">ID of the board.</param>
134
        /// <param name="options">Options specifying which fields and nested data to include</param>
135
        /// <param name="cancellationToken">Cancellation Token</param>
136
        /// <returns>The Board object with the specified ID and requested details</returns>
137
        public async Task<Board> GetBoardAsync(string boardId, GetBoardOptions options, CancellationToken cancellationToken = default)
138
        {
139
            options.AdjustFieldsBasedOnSelectedOptions();
4✔
140
            var board = await _apiRequestController.Get<Board>(GetUrlBuilder.GetBoard(boardId), cancellationToken, options.GetParameters());
4✔
141
            if (options.IncludeCards != GetBoardOptionsIncludeCards.None)
4✔
142
            {
143
                board.Cards = FilterCards(board.Cards, options.CardsFilterConditions);
1✔
144
                board.Cards = OrderCards(board.Cards, options.CardsOrderBy);
1✔
145
            }
146

147
            return board;
4✔
148
        }
4✔
149

150
        /// <summary>
151
        /// Retrieves all boards that a specified member has access to.
152
        /// </summary>
153
        /// <param name="memberId">ID of the member to find boards for</param>
154
        /// <param name="cancellationToken">Cancellation Token</param>
155
        /// <returns>A list of Board objects the member can access</returns>
156
        public async Task<List<Board>> GetBoardsForMemberAsync(string memberId, CancellationToken cancellationToken = default)
157
        {
158
            return await _apiRequestController.Get<List<Board>>(GetUrlBuilder.GetBoardsForMember(memberId), cancellationToken);
2✔
159
        }
2✔
160

161
        /// <summary>
162
        /// Retrieves all boards that a specified member has access to, with options to include additional nested data.
163
        /// </summary>
164
        /// <param name="memberId">ID of the member to find boards for</param>
165
        /// <param name="options">Options specifying which fields and nested data to include</param>
166
        /// <param name="cancellationToken">Cancellation Token</param>
167
        /// <returns>A list of Board objects the member can access</returns>
168
        public async Task<List<Board>> GetBoardsForMemberAsync(string memberId, GetBoardOptions options, CancellationToken cancellationToken = default)
169
        {
170
            return await _apiRequestController.Get<List<Board>>(GetUrlBuilder.GetBoardsForMember(memberId), cancellationToken, options.GetParameters());
3✔
171
        }
3✔
172

173
        /// <summary>
174
        /// Retrieves all boards that the current Trello API token has access to.
175
        /// </summary>
176
        /// <param name="cancellationToken">Cancellation Token</param>
177
        /// <returns>A list of Board objects accessible to the current token</returns>
178
        public async Task<List<Board>> GetBoardsCurrentTokenCanAccessAsync(CancellationToken cancellationToken = default)
179
        {
180
            var tokenMember = await GetTokenMemberAsync(cancellationToken);
1✔
181
            return await GetBoardsForMemberAsync(tokenMember.Id, cancellationToken);
1✔
182
        }
1✔
183

184
        /// <summary>
185
        /// Retrieves all boards that the current Trello API token has access to, with options to include additional nested data.
186
        /// </summary>
187
        /// <param name="options">Options specifying which fields and nested data to include</param>
188
        /// <param name="cancellationToken">Cancellation Token</param>
189
        /// <returns>A list of Board objects accessible to the current token</returns>
190
        public async Task<List<Board>> GetBoardsCurrentTokenCanAccessAsync(GetBoardOptions options, CancellationToken cancellationToken = default)
191
        {
192
            var tokenMember = await GetTokenMemberAsync(cancellationToken);
3✔
193
            return await GetBoardsForMemberAsync(tokenMember.Id, options, cancellationToken);
3✔
194
        }
3✔
195

196
        /// <summary>
197
        /// Retrieves all boards in a specified organization, given the organization's ID.
198
        /// </summary>
199
        /// <param name="organizationId">ID of the organization to get boards for</param>
200
        /// <param name="cancellationToken">Cancellation Token</param>
201
        /// <returns>A list of Board objects in the organization</returns>
202
        public async Task<List<Board>> GetBoardsInOrganizationAsync(string organizationId, CancellationToken cancellationToken = default)
203
        {
204
            return await _apiRequestController.Get<List<Board>>(GetUrlBuilder.GetBoardsInOrganization(organizationId), cancellationToken);
1✔
205
        }
1✔
206

207
        /// <summary>
208
        /// Retrieves all boards in a specified organization, with options to include additional nested data.
209
        /// </summary>
210
        /// <param name="organizationId">ID of the organization to get boards for</param>
211
        /// <param name="options">Options specifying which fields and nested data to include</param>
212
        /// <param name="cancellationToken">Cancellation Token</param>
213
        /// <returns>A list of Board objects in the organization</returns>
214
        public async Task<List<Board>> GetBoardsInOrganizationAsync(string organizationId, GetBoardOptions options, CancellationToken cancellationToken = default)
215
        {
216
            return await _apiRequestController.Get<List<Board>>(GetUrlBuilder.GetBoardsInOrganization(organizationId), cancellationToken, options.GetParameters());
1✔
217
        }
1✔
218

219
        /// <summary>
220
        /// Updates the preferences of a board, such as visibility, voting, comments, and other settings. Only the specified options are changed; others remain unchanged.
221
        /// </summary>
222
        /// <param name="boardId">ID of the board to update preferences for</param>
223
        /// <param name="options">The preference options to set (leave properties null to keep existing values)</param>
224
        /// <param name="cancellationToken">Cancellation Token</param>
225
        public async Task UpdateBoardPreferencesAsync(string boardId, UpdateBoardPreferencesOptions options, CancellationToken cancellationToken = default)
226
        {
227
            List<QueryParameter> parameters = new List<QueryParameter>();
1✔
228
            SetOption(options.CardCovers, "prefs/cardCovers");
1✔
229
            SetOption(options.Visibility, "prefs/permissionLevel");
1✔
230
            SetOption(options.ShowCompletedStatusOnCardFront, "prefs/showCompleteStatus");
1✔
231
            SetOption(options.HideVotes, "prefs/hideVotes");
1✔
232
            SetOption(options.WhoCanVote, "prefs/voting");
1✔
233
            SetOption(options.WhoCanComment, "prefs/comments");
1✔
234
            SetOption(options.WhoCanAddAndRemoveMembers, "prefs/invitations");
1✔
235
            SetOption(options.SelfJoin, "prefs/selfJoin");
1✔
236
            SetOption(options.CardAging, "prefs/cardAging");
1✔
237

238
            if (parameters.Count > 0)
1✔
239
            {
240
                await _apiRequestController.Put($"{UrlPaths.Boards}/{boardId}", cancellationToken, 0, parameters.ToArray());
1✔
241
            }
242

243
            void SetOption(Enum @enum, string parameterKey)
244
            {
245
                if (@enum != null)
9✔
246
                {
247
                    parameters.Add(new QueryParameter(parameterKey, @enum.GetJsonPropertyName()));
9✔
248
                }
249
            }
9✔
250
        }
1✔
251
    }
252
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc