Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'us1882-test' into us1882

Conflicts:
	.gitignore
  • Loading branch information...
commit a21ebe40919ebbeba1ca6b87b14401f5503cf5dd 2 parents 1dd1698 + e7e7ea0
@tbischel tbischel authored
View
5 .gitignore 100644 → 100755
@@ -7,3 +7,8 @@ SendGrid/Tests/bin/
SendGrid/Tests/obj/
SendGrid/_ReSharper.SendGrid/
*.suo
+SendGrid/Example/bin/
+SendGrid/Example/obj/
+SendGrid/*/bin/
+SendGrid/*/obj/
+
View
6 SendGrid/Example/Example.csproj
@@ -47,6 +47,12 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SendGridMail\Mail.csproj">
+ <Project>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</Project>
+ <Name>Mail</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
1  SendGrid/Example/Program.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Net.Mail;
using System.Text;
+using SendGrid.Transport;
namespace Example
{
View
2  SendGrid/SendGrid.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail", "SendGrid\Mail.csproj", "{3C687BEF-FF50-44AD-8315-2D4237281AF8}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail", "SendGridMail\Mail.csproj", "{3C687BEF-FF50-44AD-8315-2D4237281AF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{0319E73A-7039-4858-B047-1EDF88BB6BD1}"
EndProject
View
14 SendGrid/SendGrid/Transport/ITransport.cs
@@ -1,14 +0,0 @@
-namespace SendGrid.Transport
-{
- /// <summary>
- ///
- /// </summary>
- public interface ITransport
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="message"></param>
- void Deliver(ISendGrid message);
- }
-}
View
2  SendGrid/SendGrid/Header.cs → SendGrid/SendGridMail/Header.cs
@@ -4,7 +4,7 @@
using System.Net.Mail;
using System.Text;
-namespace SendGrid
+namespace SendGridMail
{
public class Header : IHeader
{
View
2  SendGrid/SendGrid/IHeader.cs → SendGrid/SendGridMail/IHeader.cs
@@ -4,7 +4,7 @@
using System.Net.Mail;
using System.Text;
-namespace SendGrid
+namespace SendGridMail
{
public interface IHeader
{
View
2  SendGrid/SendGrid/ISendGrid.cs → SendGrid/SendGridMail/ISendGrid.cs
@@ -6,7 +6,7 @@
using System.Net.Mime;
using System.Text;
-namespace SendGrid
+namespace SendGridMail
{
public enum TransportType
{
View
4 SendGrid/SendGrid/Mail.csproj → SendGrid/SendGridMail/Mail.csproj
@@ -8,8 +8,8 @@
<ProjectGuid>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>SendGrid</RootNamespace>
- <AssemblyName>SendGrid</AssemblyName>
+ <RootNamespace>SendGridMail</RootNamespace>
+ <AssemblyName>SendGridMail</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
View
6 SendGrid/SendGrid/Properties/AssemblyInfo.cs → SendGrid/SendGridMail/Properties/AssemblyInfo.cs
@@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("SendGrid")]
+[assembly: AssemblyTitle("SendGridMail")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("SendGrid")]
+[assembly: AssemblyProduct("SendGridMail")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -22,6 +22,8 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("193fa200-8430-4206-aacd-2d2bb2dfa6cf")]
+[assembly: InternalsVisibleTo("Tests")]
+
// Version information for an assembly consists of the following four values:
//
// Major Version
View
12 SendGrid/SendGrid/SendGrid.cs → SendGrid/SendGridMail/SendGrid.cs
@@ -8,7 +8,7 @@
using System.Runtime.InteropServices.ComTypes;
using System.Text;
-namespace SendGrid
+namespace SendGridMail
{
public class SendGrid : ISendGrid
{
@@ -86,6 +86,7 @@ public void InitializeFilters()
Html = html;
}
+ #region Properties
public MailAddress From
{
get
@@ -168,7 +169,9 @@ public IHeader Header
public String Text { get; set; }
public TransportType Transport { get; set; }
+ #endregion
+ #region Methods for setting data
public void AddTo(String address)
{
var mailAddress = new MailAddress(address);
@@ -296,7 +299,9 @@ private void Set(string field, string value)
{
throw new NotImplementedException();
}
+ #endregion
+ #region SMTP API Functions
public void DisableGravatar()
{
this.header.Disable(this._filters["Gravatar"]);
@@ -441,15 +446,16 @@ public void EnableBypassListManagement()
{
this.header.Enable(this._filters["BypassListManagement"]);
}
+ #endregion
public MailMessage CreateMimeMessage()
{
String smtpapi = Header.AsJson();
if (!String.IsNullOrEmpty(smtpapi))
- this.message.Headers.Add("X-SmtpApi", "{" + smtpapi + "}");
+ message.Headers.Add("X-SmtpApi", "{" + smtpapi + "}");
- return this.message;
+ return message;
}
public void Mail()
View
14 SendGrid/SendGridMail/Transport/ITransport.cs
@@ -0,0 +1,14 @@
+namespace SendGridMail.Transport
+{
+ /// <summary>
+ ///
+ /// </summary>
+ public interface ITransport
+ {
+ /// <summary>
+ /// Delivers a message using the protocol of the derived class
+ /// </summary>
+ /// <param name="message">the message to be delivered</param>
+ void Deliver(ISendGrid message);
+ }
+}
View
4 SendGrid/SendGrid/Transport/REST.cs → SendGrid/SendGridMail/Transport/REST.cs
@@ -8,7 +8,7 @@
using System.Web;
using System.Xml;
-namespace SendGrid.Transport
+namespace SendGridMail.Transport
{
public class REST : ITransport
{
@@ -28,7 +28,7 @@ public REST(NetworkCredential credentials, String url = Endpoint)
_queryParameters["api_key"] = credentials.Password;
_format = XmlFormat;
- _restEndpoint = url + "." + this._format;
+ _restEndpoint = url + "." + _format;
}
public void Deliver(ISendGrid message)
View
21 SendGrid/SendGrid/Transport/SMTP.cs → SendGrid/SendGridMail/Transport/SMTP.cs
@@ -2,7 +2,7 @@
using System.Net;
using System.Net.Mail;
-namespace SendGrid.Transport
+namespace SendGridMail.Transport
{
/// <summary>
/// Transport class for delivering messages via SMTP
@@ -72,16 +72,29 @@ public void Deliver(ISendGrid message)
/// <param name="credentials">Sendgrid user credentials</param>
/// <param name="host">MTA recieving this message. By default, sent through SendGrid.</param>
/// <param name="port">SMTP port 25 is the default. Port 465 can be used for Secure SMTP.</param>
- public static SMTP SmtpFactory(NetworkCredential credentials, String host = SmtpServer, Int32 port = Port)
+ public static SMTP GenerateInstance(NetworkCredential credentials, String host = SmtpServer, Int32 port = Port)
{
var client = new SmtpWrapper(host, port, credentials, SmtpDeliveryMethod.Network);
return new SMTP(client, credentials, host, port);
}
/// <summary>
+ /// For Unit Testing Only!
+ /// </summary>
+ /// <param name="client"></param>
+ /// <param name="credentials"></param>
+ /// <param name="host"></param>
+ /// <param name="port"></param>
+ /// <returns></returns>
+ internal static SMTP GenerateInstance(ISmtpClient client, NetworkCredential credentials, String host = SmtpServer, Int32 port = Port)
+ {
+ return new SMTP(client, credentials, host, port);
+ }
+
+ /// <summary>
/// Interface to allow testing
/// </summary>
- private interface ISmtpClient
+ internal interface ISmtpClient
{
bool EnableSsl { get; set; }
void Send(MailMessage mime);
@@ -90,7 +103,7 @@ private interface ISmtpClient
/// <summary>
/// Implementation of SmtpClient wrapper, separated to allow dependency injection
/// </summary>
- private class SmtpWrapper : ISmtpClient
+ internal class SmtpWrapper : ISmtpClient
{
private readonly SmtpClient _client;
public bool EnableSsl
View
4 SendGrid/Tests/TestHeader.cs
@@ -4,7 +4,7 @@
using System.Text;
using Moq;
using NUnit.Framework;
-using SendGrid;
+using SendGridMail;
namespace Tests
{
@@ -17,7 +17,7 @@ public void TestAddTo()
var foo = new Mock<IHeader>();
foo.Setup(m => m.Enable("foo"));
- var bar = new SendGrid.SendGrid(foo.Object);
+ var bar = new SendGrid(foo.Object);
Assert.AreEqual(1, 2, "I suck");
}
View
19 SendGrid/Tests/TestSendgridMessageSetup.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using SendGridMail;
+
+namespace Tests
+{
+ [TestFixture]
+ public class TestSendgridMessageSetup
+ {
+ [Test]
+ public void TestAddTo()
+ {
+ var foo = new SendGrid();
+ }
+ }
+}
View
3  SendGrid/Tests/Tests.csproj
@@ -54,6 +54,7 @@
<ItemGroup>
<Compile Include="TestHeader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TestSendgridMessageSetup.cs" />
<Compile Include="Transport\TestREST.cs" />
<Compile Include="Transport\TestSMTP.cs" />
</ItemGroup>
@@ -63,7 +64,7 @@
</None>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\SendGrid\Mail.csproj">
+ <ProjectReference Include="..\SendGridMail\Mail.csproj">
<Project>{3C687BEF-FF50-44AD-8315-2D4237281AF8}</Project>
<Name>Mail</Name>
</ProjectReference>
View
8 SendGrid/Tests/Transport/TestSMTP.cs
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Text;
+using Moq;
using NUnit.Framework;
+using SendGridMail.Transport;
namespace Tests.Transport
{
@@ -12,7 +15,10 @@ public class TestSMTP
[Test]
public void Deliver()
{
-
+ var mock = new Mock<SMTP.ISmtpClient>();
+ var client = mock.Object;
+ var credentials = new NetworkCredential("username", "password");
+ SMTP.GenerateInstance(client, credentials);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.