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

rwjdk / TrelloDotNet / 6852213317

13 Nov 2023 03:36PM UTC coverage: 66.31% (-0.5%) from 66.806%
6852213317

push

github

rwjdk
1.9.5 CS Proj and Changelog

889 of 1665 branches covered (0.0%)

Branch coverage included in aggregate %.

2331 of 3191 relevant lines covered (73.05%)

56.09 hits per line

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

68.57
/TrelloDotNet/TrelloDotNet/TrelloClient.Attachments.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Threading;
4
using System.Threading.Tasks;
5
using TrelloDotNet.Control;
6
using TrelloDotNet.Model;
7

8
namespace TrelloDotNet
9
{
10
    public partial class TrelloClient
11
    {
12
        /// <summary>
13
        /// Get Attachments on a card
14
        /// </summary>
15
        /// <param name="cardId">Id of the Card</param>
16
        /// <param name="cancellationToken">Cancellation Token</param>
17
        /// <returns>The Attachments</returns>
18
        public async Task<List<Attachment>> GetAttachmentsOnCardAsync(string cardId, CancellationToken cancellationToken = default)
19
        {
20
            return await _apiRequestController.Get<List<Attachment>>(GetUrlBuilder.GetAttachmentsOnCard(cardId), cancellationToken);
4✔
21
        }
4✔
22

23
        /// <summary>
24
        /// Delete an Attachments on a card
25
        /// </summary>
26
        /// <param name="cardId">Id of the Card</param>
27
        /// <param name="attachmentId">Id of Attachment</param>
28
        /// <param name="cancellationToken">Cancellation Token</param>
29
        public async Task DeleteAttachmentOnCardAsync(string cardId, string attachmentId, CancellationToken cancellationToken = default)
30
        {
31
            await _apiRequestController.Delete(GetUrlBuilder.GetAttachmentOnCard(cardId, attachmentId), cancellationToken, 0);
2✔
32
        }
2✔
33

34
        /// <summary>
35
        /// Add an Attachment to a Card
36
        /// </summary>
37
        /// <param name="cardId">Id of the Card</param>
38
        /// <param name="attachmentUrlLink">A Link Attachment</param>
39
        /// <param name="cancellationToken">Cancellation Token</param>
40
        /// <returns>The Created Attachment</returns>
41
        public async Task<Attachment> AddAttachmentToCardAsync(string cardId, AttachmentUrlLink attachmentUrlLink, CancellationToken cancellationToken = default)
42
        {
43
            var parameters = new List<QueryParameter> { new QueryParameter("url", attachmentUrlLink.Url) };
2✔
44
            if (!string.IsNullOrWhiteSpace(attachmentUrlLink.Name))
2✔
45
            {
46
                parameters.Add(new QueryParameter("name", attachmentUrlLink.Name));
2✔
47
            }
48

49
            if (attachmentUrlLink.NamedPosition.HasValue)
2!
50
            {
51
                switch (attachmentUrlLink.NamedPosition.Value)
×
52
                {
53
                    case NamedPosition.Top:
54
                        parameters.Add(new QueryParameter("pos", "bottom")); //NB: Trello have an mis-implementation where these are reversed on attachments so however wrong this looks, it is correct
×
55
                    break;
×
56
                    case NamedPosition.Bottom:
57
                        parameters.Add(new QueryParameter("pos", "top")); //NB: Trello have an mis-implementation where these are reversed on attachments so however wrong this looks, it is correct
×
58
                        break;
×
59
                    default:
60
                        parameters.Add(new QueryParameter("pos", Convert.ToInt32(attachmentUrlLink.NamedPosition.Value)));
×
61
                        break;
62
                };
63
            }
64

65
            return await _apiRequestController.Post<Attachment>($"{UrlPaths.Cards}/{cardId}/attachments", cancellationToken, parameters.ToArray());
2✔
66
        }
2✔
67

68
        /// <summary>
69
        /// Add an Attachment to a Card
70
        /// </summary>
71
        /// <param name="cardId">Id of the Card</param>
72
        /// <param name="attachmentFileUpload">A Link Attachment</param>
73
        /// <param name="setAsCover">Make this attachment the cover of the Card</param>
74
        /// <param name="cancellationToken">Cancellation Token</param>
75
        /// <returns>The Created Attachment</returns>
76
        public async Task<Attachment> AddAttachmentToCardAsync(string cardId, AttachmentFileUpload attachmentFileUpload, bool setAsCover = false, CancellationToken cancellationToken = default)
77
        {
78
            var parameters = new List<QueryParameter>();
1✔
79
            if (!string.IsNullOrWhiteSpace(attachmentFileUpload.Name))
1✔
80
            {
81
                parameters.Add(new QueryParameter("name", attachmentFileUpload.Name));
1✔
82
            }
83

84
            if (setAsCover)
1✔
85
            {
86
                parameters.Add(new QueryParameter("setCover", "true"));
1✔
87
            }
88
            
89
            return await _apiRequestController.PostWithAttachmentFileUpload<Attachment>($"{UrlPaths.Cards}/{cardId}/attachments", attachmentFileUpload, cancellationToken, parameters.ToArray());
1✔
90
        }
1✔
91
    }
92
}
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

© 2025 Coveralls, Inc