Skip to content

Commit e27981d

Browse files
Fixed configuration for new Settings values
1 parent 93990f1 commit e27981d

File tree

4 files changed

+15
-42
lines changed

4 files changed

+15
-42
lines changed

src/NetCore.Utilities.Email.SendGrid.Tests/SmtpServiceTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ public class SendGridServiceTests
1111
private readonly SendGridServiceOptions _options = new SendGridServiceOptions()
1212
{
1313
AdminEmail = "[email protected]",
14-
Port = 15,
15-
UseSsl = true,
16-
SenderUsername = "User",
17-
SenderPassword = "Password",
18-
Server = "Server",
14+
SendGridApiKey = "APIKEY",
1915
AddEnvironmentSuffix = false,
2016
AlwaysTemplateEmails = false
2117
};

src/NetCore.Utilities.Email.SendGrid.Tests/StartupExtensiosTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
using Microsoft.AspNetCore.Hosting;
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.DependencyInjection;
4-
using Microsoft.Extensions.Logging;
54
using Microsoft.Extensions.Options;
65
using Moq;
76
using Xunit;
87

98
namespace ICG.NetCore.Utilities.Email.SendGrid.Tests
109
{
11-
public class StartupExtensiosTests
10+
public class StartupExtensionsTests
1211
{
1312
[Fact]
1413
public void Configuration_ShouldMapAllValues()
@@ -28,11 +27,11 @@ public void Configuration_ShouldMapAllValues()
2827
Assert.NotNull(myConfig);
2928
var values = myConfig.Value;
3029
Assert.Equal("[email protected]", values.AdminEmail);
31-
Assert.Equal("test.SendGrid.com", values.Server);
32-
Assert.Equal(527, values.Port);
33-
Assert.True(values.UseSsl);
34-
Assert.Equal("MySender", values.SenderUsername);
35-
Assert.Equal("Password", values.SenderPassword);
30+
Assert.Equal("TestKey", values.SendGridApiKey);
31+
Assert.Single(values.AdditionalApiKeys);
32+
var specialKeyValue = values.AdditionalApiKeys["SpecialSender"];
33+
Assert.Equal("SpecialKey", specialKeyValue);
34+
3635
Assert.True(values.AlwaysTemplateEmails);
3736
Assert.True(values.AddEnvironmentSuffix);
3837
}

src/NetCore.Utilities.Email.SendGrid.Tests/appsettings.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"SendGridServiceOptions": {
33
"AdminEmail": "[email protected]",
4-
"Server": "test.SendGrid.com",
5-
"Port": "527",
6-
"UseSsl": true,
7-
"SenderUsername": "MySender",
8-
"SenderPassword": "Password",
4+
"SendGridApiKey": "TestKey",
5+
"AdditionalApiKeys": { "SpecialSender": "SpecialKey" },
96
"AlwaysTemplateEmails": true,
107
"AddEnvironmentSuffix": true
118
}

src/NetCore.Utilities.Email.SendGrid/SendGridServiceOptions.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.ComponentModel.DataAnnotations;
1+
using System.Collections.Generic;
2+
using System.ComponentModel.DataAnnotations;
23

34
namespace ICG.NetCore.Utilities.Email.SendGrid
45
{
@@ -14,34 +15,14 @@ public class SendGridServiceOptions
1415
public string AdminEmail { get; set; }
1516

1617
/// <summary>
17-
/// The server for outbound emails
18+
/// The SendGrid API key that needs to
1819
/// </summary>
19-
[Display(Name = "Server")]
20-
public string Server { get; set; }
20+
public string SendGridApiKey { get; set; }
2121

2222
/// <summary>
23-
/// The port to use for communication
23+
/// Optional additional API Keys for sending outbound emails
2424
/// </summary>
25-
[Display(Name = "Port")]
26-
public int Port { get; set; }
27-
28-
/// <summary>
29-
/// Should this use SSL connection
30-
/// </summary>
31-
[Display(Name = "Use SSL")]
32-
public bool UseSsl { get; set; }
33-
34-
/// <summary>
35-
/// The username to use for sending
36-
/// </summary>
37-
[Display(Name = "Sender Username")]
38-
public string SenderUsername { get; set; }
39-
40-
/// <summary>
41-
/// THe password to use for sending
42-
/// </summary>
43-
[Display(Name = "Sender Password")]
44-
public string SenderPassword { get; set; }
25+
public Dictionary<string, string> AdditionalApiKeys { get; set; }
4526

4627
/// <summary>
4728
/// If selected outbound emails will be sent with the default template unless a special template is requested

0 commit comments

Comments
 (0)