Skip to content

Commit 93990f1

Browse files
Initial project checkin with source code. NON-FUNCTIONAL but ready to start implementation
1 parent 0f11521 commit 93990f1

File tree

10 files changed

+559
-1
lines changed

10 files changed

+559
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ services.UseIcgNetCoreUtilitiesEmailSendGrid();
4646
Additionally you must specify the needed configuration elements within your AppSettings.json file
4747

4848
```
49-
"SendGridEmailOptions": {
49+
"SendGridServiceOptions": {
5050
"AdminEmail": "[email protected]",
5151
"Server": "test.smtp.com",
5252
"Port": 527,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<RootNamespace>ICG.NetCore.Utilities.Email.SendGrid.Tests</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
14+
<PackageReference Include="Moq" Version="4.16.0" />
15+
<PackageReference Include="xunit" Version="2.4.1" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\NetCore.Utilities.Email.SendGrid\NetCore.Utilities.Email.SendGrid.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<None Update="appsettings.json">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</None>
30+
</ItemGroup>
31+
32+
</Project>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
using System.Collections.Generic;
2+
using System.Text;
3+
using Microsoft.Extensions.Options;
4+
using Moq;
5+
using Xunit;
6+
7+
namespace ICG.NetCore.Utilities.Email.SendGrid.Tests
8+
{
9+
public class SendGridServiceTests
10+
{
11+
private readonly SendGridServiceOptions _options = new SendGridServiceOptions()
12+
{
13+
AdminEmail = "[email protected]",
14+
Port = 15,
15+
UseSsl = true,
16+
SenderUsername = "User",
17+
SenderPassword = "Password",
18+
Server = "Server",
19+
AddEnvironmentSuffix = false,
20+
AlwaysTemplateEmails = false
21+
};
22+
private readonly ISendGridService _service;
23+
24+
public SendGridServiceTests()
25+
{
26+
_service = new SendGridService(new OptionsWrapper<SendGridServiceOptions>(_options));
27+
}
28+
29+
[Fact]
30+
public void AdminEmail_ShouldReturnConfigurationEmail()
31+
{
32+
//Arrange
33+
var expectedEmail = "[email protected]";
34+
35+
//Act
36+
var result = _service.AdminEmail;
37+
38+
//Assert
39+
Assert.Equal(expectedEmail, result);
40+
}
41+
42+
[Fact]
43+
public void AdminEmail_ShouldReturnNullWhenNoConfiguration()
44+
{
45+
//Arrange
46+
var testService = new SendGridService(new OptionsWrapper<SendGridServiceOptions>(null));
47+
48+
//Act
49+
var result = testService.AdminEmail;
50+
51+
//Assert
52+
Assert.Null(result);
53+
}
54+
55+
[Fact]
56+
public void SendToAdministrator_ShouldSend_DefaultingFromAndToAddress()
57+
{
58+
//Arrange
59+
var subject = "Test";
60+
var message = "Message";
61+
62+
//Act
63+
_service.SendMessageToAdministrator(subject, message);
64+
65+
//Verify
66+
}
67+
68+
[Fact]
69+
public void SendToAdministrator_ShouldSend_DefaultingFromAndToAddress_WithCCRecipients()
70+
{
71+
//Arrange
72+
var subject = "Test";
73+
var message = "Message";
74+
var cc = new List<string> {"[email protected]"};
75+
76+
//Act
77+
_service.SendMessageToAdministrator(cc, subject, message);
78+
79+
//Verify
80+
}
81+
82+
[Fact]
83+
public void SendMessage_WithoutCCRecipients_ShouldSend_DefaultingFromAddress()
84+
{
85+
//Arrange
86+
var to = "[email protected]";
87+
var subject = "test";
88+
var message = "message";
89+
90+
//Act
91+
_service.SendMessage(to, subject, message);
92+
93+
//Verify
94+
}
95+
96+
[Fact]
97+
public void SendMessage_WithCCRecipients_ShouldSend_DefaultingFromAddress()
98+
{
99+
//Arrange
100+
var to = "[email protected]";
101+
var cc = new List<string> {"[email protected]"};
102+
var subject = "test";
103+
var message = "message";
104+
105+
//Act
106+
_service.SendMessage(to, cc, subject, message);
107+
108+
//Verify
109+
}
110+
111+
[Fact]
112+
public void SendMessageWithAttachment_ShouldSend_DefaultingFromAddress()
113+
{
114+
//Arrange
115+
var to = "[email protected]";
116+
var cc = new List<string> { "[email protected]" };
117+
var subject = "test";
118+
var fileContent = Encoding.ASCII.GetBytes("Testing");
119+
var fileName = "test.txt";
120+
var message = "message";
121+
122+
//Act
123+
_service.SendMessageWithAttachment(to, cc, subject, fileContent, fileName, message);
124+
125+
//Assets
126+
}
127+
128+
[Fact]
129+
public void SendMessage_ShouldPassOptionalTemplateName_ToMessageMethods()
130+
{
131+
//Arrange
132+
var to = "[email protected]";
133+
var cc = new List<string> { "[email protected]" };
134+
var subject = "test";
135+
var message = "message";
136+
var requestedTemplate = "Test";
137+
138+
//Act
139+
_service.SendMessage(to, cc, subject, message, requestedTemplate);
140+
141+
//Assets
142+
}
143+
144+
[Fact]
145+
public void SendMessageWithAttachment_ShouldPassOptionalTemplateName_ToMessageMethods()
146+
{
147+
//Arrange
148+
var to = "[email protected]";
149+
var cc = new List<string> { "[email protected]" };
150+
var subject = "test";
151+
var fileContent = Encoding.ASCII.GetBytes("Testing");
152+
var fileName = "test.txt";
153+
var message = "message";
154+
var requestedTemplate = "Test";
155+
156+
//Act
157+
_service.SendMessageWithAttachment(to, cc, subject, fileContent, fileName, message, requestedTemplate);
158+
159+
//Assets
160+
}
161+
}
162+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Logging;
5+
using Microsoft.Extensions.Options;
6+
using Moq;
7+
using Xunit;
8+
9+
namespace ICG.NetCore.Utilities.Email.SendGrid.Tests
10+
{
11+
public class StartupExtensiosTests
12+
{
13+
[Fact]
14+
public void Configuration_ShouldMapAllValues()
15+
{
16+
//Arrange
17+
var collection = new ServiceCollection();
18+
var configuration = new ConfigurationBuilder()
19+
.AddJsonFile("appsettings.json")
20+
.Build();
21+
collection.UseIcgNetCoreUtilitiesEmailSendGrid(configuration);
22+
var services = collection.BuildServiceProvider();
23+
24+
//Act
25+
var myConfig = services.GetService<IOptions<SendGridServiceOptions>>();
26+
27+
//Assert
28+
Assert.NotNull(myConfig);
29+
var values = myConfig.Value;
30+
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);
36+
Assert.True(values.AlwaysTemplateEmails);
37+
Assert.True(values.AddEnvironmentSuffix);
38+
}
39+
40+
41+
[Fact]
42+
public void ServiceCollection_ShouldRegisterSendGridService()
43+
{
44+
//Arrange
45+
var collection = new ServiceCollection();
46+
var configuration = new ConfigurationBuilder()
47+
.AddJsonFile("appsettings.json")
48+
.Build();
49+
collection.AddSingleton(new Mock<Microsoft.Extensions.Hosting.IHostingEnvironment>().Object);
50+
collection.AddSingleton(new Mock<IHostingEnvironment>().Object);
51+
collection.UseIcgNetCoreUtilitiesEmailSendGrid(configuration);
52+
var services = collection.BuildServiceProvider();
53+
54+
//Act
55+
var result = services.GetService<ISendGridService>();
56+
57+
//Assert
58+
Assert.NotNull(result);
59+
Assert.IsType<SendGridService>(result);
60+
}
61+
}
62+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"SendGridServiceOptions": {
3+
"AdminEmail": "[email protected]",
4+
"Server": "test.SendGrid.com",
5+
"Port": "527",
6+
"UseSsl": true,
7+
"SenderUsername": "MySender",
8+
"SenderPassword": "Password",
9+
"AlwaysTemplateEmails": true,
10+
"AddEnvironmentSuffix": true
11+
}
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30804.86
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Utilities.Email.SendGrid", "NetCore.Utilities.Email.SendGrid\NetCore.Utilities.Email.SendGrid.csproj", "{48F8F9BE-5579-4B92-AF46-194F755ECAB0}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Utilities.Email.SendGrid.Tests", "NetCore.Utilities.Email.SendGrid.Tests\NetCore.Utilities.Email..SendGrid.Tests.csproj", "{5DFA4C47-6FBF-42F7-8179-1A07404CB9DF}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{48F8F9BE-5579-4B92-AF46-194F755ECAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{48F8F9BE-5579-4B92-AF46-194F755ECAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{48F8F9BE-5579-4B92-AF46-194F755ECAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{48F8F9BE-5579-4B92-AF46-194F755ECAB0}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{5DFA4C47-6FBF-42F7-8179-1A07404CB9DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{5DFA4C47-6FBF-42F7-8179-1A07404CB9DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{5DFA4C47-6FBF-42F7-8179-1A07404CB9DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{5DFA4C47-6FBF-42F7-8179-1A07404CB9DF}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {01D2F991-8C73-4CEA-9077-223E967FBAB5}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using ICG.NetCore.Utilities.Email.SendGrid;
2+
using Microsoft.Extensions.Configuration;
3+
4+
namespace Microsoft.Extensions.DependencyInjection
5+
{
6+
/// <summary>
7+
/// Extension methods to make DI easier
8+
/// </summary>
9+
public static class StartupExtensions
10+
{
11+
/// <summary>
12+
/// Registers the items included in the ICG AspNetCore Utilities project for Dependency Injection
13+
/// </summary>
14+
/// <param name="services">Your existing services collection</param>
15+
/// <param name="configuration">The configuration instance to load settings</param>
16+
public static void UseIcgNetCoreUtilitiesEmailSendGrid(this IServiceCollection services, IConfiguration configuration)
17+
{
18+
//Register internal services
19+
services.UseIcgNetCoreUtilitiesEmail(configuration);
20+
21+
//Bind additional services
22+
services.AddTransient<ISendGridService, SendGridService>();
23+
services.Configure<SendGridServiceOptions>(configuration.GetSection(nameof(SendGridServiceOptions)));
24+
}
25+
}
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Version>0.0.0</Version>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<TargetFramework>net5.0</TargetFramework>
9+
<RootNamespace>ICG.NetCore.Utilities.Email.SendGrid</RootNamespace>
10+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
</PropertyGroup>
12+
13+
<PropertyGroup>
14+
<PackageId>ICG.NetCore.Utilities.Email.SendGrid</PackageId>
15+
<Title>NetCore Utilities Email SendGrid</Title>
16+
<Description>A library providing an easy to use set of functions rounding the SendGrid API for email delivery.</Description>
17+
<Copyright>Copyright 2021, IowaComputerGurus, Inc. All Rights Reserved</Copyright>
18+
<PackageProjectUrl>https://github.com/IowaComputerGurus/netcore.utilities.email.SendGrid</PackageProjectUrl>
19+
<PackageTags>aspnetcore;utility;email</PackageTags>
20+
<RepositoryUrl>https://github.com/IowaComputerGurus/netcore.utilities.email.SendGrid</RepositoryUrl>
21+
<Authors>MitchelSellers;IowaComputerGurus</Authors>
22+
<Owners>IowaComputerGurus</Owners>
23+
<PackageIconUrl>https://raw.githubusercontent.com/IowaComputerGurus/netcore.utilities.email.sendgrid/main/icgAppIcon.png</PackageIconUrl>
24+
<IsPackable>True</IsPackable>
25+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
26+
<IncludeSymbols>true</IncludeSymbols>
27+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
28+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
29+
</PropertyGroup>
30+
31+
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
32+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
33+
</PropertyGroup>
34+
35+
<ItemGroup>
36+
<PackageReference Include="icg.netcore.utilities.email" Version="3.0.4" />
37+
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
38+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
39+
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
40+
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
41+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
42+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
43+
<PrivateAssets>all</PrivateAssets>
44+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
45+
</PackageReference>
46+
</ItemGroup>
47+
48+
</Project>

0 commit comments

Comments
 (0)