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

djsuperchief / Kyameru / 15686782324

16 Jun 2025 04:45PM UTC coverage: 87.848%. Remained the same
15686782324

push

github

web-flow
Merge pull request #200 from djsuperchief/199-fix-target-versions

Changed SNS to .NET Standard

501 of 630 branches covered (79.52%)

Branch coverage included in aggregate %.

69 of 76 new or added lines in 3 files covered. (90.79%)

2875 of 3213 relevant lines covered (89.48%)

22.53 hits per line

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

91.04
/source/components/Kyameru.Component.Sns/Implementation/SnsTo.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Security.Cryptography.X509Certificates;
5
using System.Threading;
6
using System.Threading.Tasks;
7
using Amazon.SimpleNotificationService;
8
using Amazon.SimpleNotificationService.Model;
9
using Kyameru.Core.Entities;
10
using Microsoft.Extensions.Logging;
11

12
namespace Kyameru.Component.Sns
13
{
14
    public class SnsTo : ITo
15
    {
16
        public event EventHandler<Log> OnLog;
17

18
        private readonly string[] requiredHeaders = new string[] { "ARN" };
9✔
19
        private readonly IAmazonSimpleNotificationService snsClient;
20
        private Dictionary<string, string> snsHeaders;
21

22
        public SnsTo(IAmazonSimpleNotificationService client)
9✔
23
        {
9✔
24
            snsClient = client;
9✔
25
        }
9✔
26

27
        public async Task ProcessAsync(Routable routable, CancellationToken cancellationToken)
28
        {
7✔
29
            try
30
            {
7✔
31
                Log(LogLevel.Information, Resources.INFO_PROCESSING);
7✔
32
                var message = SnsMessage.FromRoutable(routable, snsHeaders);
7✔
33
                var request = new PublishRequest
7✔
34
                {
7✔
35
                    TopicArn = message.Arn,
7✔
36
                    Message = message.Message,
7✔
37
                    MessageDeduplicationId = routable.Headers.TryGetValue("SNSDeduplicationId", string.Empty),
7✔
38
                    MessageGroupId = routable.Headers.TryGetValue("SNSGroupId", string.Empty)
7✔
39
                };
7✔
40

41
                if (message.Attributes.Count > 0)
7✔
42
                {
4✔
43
                    request.MessageAttributes = message.Attributes.ToDictionary(x => x.Key, x => new MessageAttributeValue
20✔
44
                    {
12✔
45
                        DataType = "String",
12✔
46
                        StringValue = x.Value
12✔
47
                    });
12✔
48
                }
4✔
49
                Log(LogLevel.Information, Resources.INFO_SENDING);
7✔
50
                var response = await snsClient.PublishAsync(request, cancellationToken);
7✔
51
                if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
6✔
52
                {
5✔
53
                    routable.SetHeader("&SNSMessageId", response.MessageId);
5✔
54
                    routable.SetHeader("&SNSSequenceNumber", response.SequenceNumber);
5✔
55
                    Log(LogLevel.Information, string.Format(Resources.INFO_SENT, response.MessageId));
5✔
56
                }
5✔
57
                else
58
                {
1✔
59
                    var errorMessage = string.Format(Resources.ERROR_HTTP_RESPONSE, response.HttpStatusCode);
1✔
60
                    Log(LogLevel.Information, errorMessage);
1✔
61
                    routable.SetInError(new Error("SNS", "To", errorMessage));
1✔
62
                }
1✔
63
            }
6✔
64
            catch (Exception ex)
1✔
65
            {
1✔
66
                routable.SetInError(new Error("SNS", "To", ex.Message));
1✔
67
                Log(LogLevel.Error, string.Format(Resources.ERROR_SENDING, ex.Message), ex);
1✔
68
            }
1✔
69
        }
7✔
70
        public void SetHeaders(Dictionary<string, string> headers)
71
        {
9✔
72
            var missing = requiredHeaders.Where(x => headers.Keys.All(y => y != x));
27✔
73
            if (missing.Any())
9✔
74
            {
1✔
75
                throw new Core.Exceptions.ComponentException(string.Format(Resources.MISSING_HEADER_EXCEPTION, string.Join(",", missing.ToList())));
1✔
76
            }
77

78
            snsHeaders = headers;
8✔
79
        }
8✔
80

81
        private void Log(LogLevel logLevel, string message, Exception exception = null)
82
        {
21✔
83
            if (this.OnLog != null)
21!
NEW
84
            {
×
NEW
85
                this.OnLog?.Invoke(this, new Core.Entities.Log(logLevel, message, exception));
×
NEW
86
            }
×
87
        }
21✔
88
    }
89
}
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