diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..83fb9913 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Declare files that will always have CRLF line endings on checkout. +* text eol=lf diff --git a/.travis.yml b/.travis.yml index 9ebbb5af..c6dab165 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ before_script: - nuget restore src/SparkPost.sln script: - xbuild /p:Configuration=Release src/SparkPost.sln - - nunit-console /home/travis/build/SparkPost/csharp-sparkpost/src/SparkPost.Tests/bin/Release/SparkPost.Tests.dll + - nunit-console /home/travis/build/darrencauthon/csharp-sparkpost/src/SparkPost.Tests/bin/Release/SparkPost.Tests.dll diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 734b6836..566dda0e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,17 +1,15 @@ # Contributing to csharp-sparkpost -Transparency is one of our core values, and we encourage developers to contribute and become part of the SparkPost developer community. - The following is a set of guidelines for contributing to csharp-sparkpost, -which is hosted in the [SparkPost Organization](https://github.com/sparkpost) on GitHub. +which is hosted by [Darren Cauthon](https://github.com/darrencauthon) on GitHub. These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request. ## Submitting Issues -* Before logging an issue, please [search existing issues](https://github.com/SparkPost/csharp-sparkpost/issues?q=is%3Aissue+is%3Aopen) first. +* Before logging an issue, please [search existing issues](https://github.com/darrencauthon/csharp-sparkpost/issues?q=is%3Aissue+is%3Aopen) first. -* You can create an issue [here](https://github.com/SparkPost/csharp-sparkpost/issues/new). Please include the library version number and as much detail as possible in your report. +* You can create an issue [here](https://github.com/darrencauthon/csharp-sparkpost/issues/new). Please include the library version number and as much detail as possible in your report. ## Local Development @@ -34,4 +32,3 @@ To contribute to csharp-sparkpost: ### Releasing TODO: add instructions for publishing to https://www.nuget.org/ - diff --git a/README.md b/README.md index 0dd4f8ff..abb24299 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ - +# C# Library for [SparkPost](https://www.sparkpost.com) -[Sign up](https://app.sparkpost.com/sign-up?src=Dev-Website&sfdcid=70160000000pqBb) for a SparkPost account and visit our [Developer Hub](https://developers.sparkpost.com) for even more content. +[![Travis CI](https://travis-ci.org/darrencauthon/csharp-sparkpost.svg?branch=master)](https://travis-ci.org/darrencauthon/csharp-sparkpost) -# SparkPost C# Library - -[![Travis CI](https://travis-ci.org/SparkPost/ruby-sparkpost.svg?branch=master)](https://travis-ci.org/SparkPost/csharp-sparkpost) [![Slack Status](http://slack.sparkpost.com/badge.svg)](http://slack.sparkpost.com) - -The official C# package for the [SparkPost API](https://www.sparkpost.com/api). Xamarin.iOS and Xamarin.Android support provided in the Portable Package (PCL Profile7). +A C# package for the [SparkPost API](https://developers.sparkpost.com/api). Xamarin.iOS and Xamarin.Android support provided in the Portable Package (PCL Profile7). ## Installation @@ -107,7 +103,7 @@ The suppression list are users who have opted-out of your emails. To retrieve t ```c# var client = new Client("MY_API_KEY"); -client.Suppressions.List(); // returns a list of +client.Suppressions.List(); // returns a list of client.Suppressions.List(new { limit = 3 }); // it accepts an anonymous type for filters @@ -141,6 +137,10 @@ var client = new Client("MY_API_KEY"); client.Suppressions.Retrieve("testing@testing.com"); ``` +### Setting the API hostname +```c# +var client = new Client("MY_API_KEY", "https://api.eu.sparkpost.com"); +``` ### Contribute diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..2f4c3712 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,21 @@ +FROM mono +MAINTAINER Darren Cauthon + +RUN apt-get update +RUN apt-get install -y wget git dos2unix vim zip + +RUN nuget update -self + +ENV MONO_THREADS_PER_CPU 2000 + +WORKDIR / + +RUN git clone https://github.com/SparkPost/csharp-sparkpost.git + +WORKDIR /csharp-sparkpost/src + +ADD build_and_deploy.sh /csharp-sparkpost/src +RUN chmod 777 build_and_deploy.sh +RUN dos2unix build_and_deploy.sh + +CMD /csharp-sparkpost/src/build_and_deploy.sh diff --git a/docker/build_and_deploy.sh b/docker/build_and_deploy.sh new file mode 100644 index 00000000..61060b78 --- /dev/null +++ b/docker/build_and_deploy.sh @@ -0,0 +1,24 @@ +git pull origin master + +nuget restore +xbuild /p:Configuration=Release + +nuget pack SparkPost/SparkPost.nuspec -Prop Configuration=Release + +PACKAGE=$(ls *.nupkg) + +# This will unzip the nupkg, then zip it back up. +# This is done to some issue with the nuget command +# line app creating nupkg files that cannot be +# used by Visual Studio. +# https://github.com/NuGet/Home/issues/2833 +mv $PACKAGE file.zip +mkdir stuff +cd stuff +unzip ../file.zip +rm ../file.zip +zip -r ../file.zip * +cd .. +mv file.zip $PACKAGE + +nuget push $PACKAGE $APIKEY -s nuget.org diff --git a/docker/readme.md b/docker/readme.md new file mode 100644 index 00000000..9a0a62a7 --- /dev/null +++ b/docker/readme.md @@ -0,0 +1,17 @@ +## Build & Deploy via Docker & Nuget + +This docker container will pull the latest version of this library, create a nuget package, and deploy it to Nuget. + +The only thing is needs is a valid Nuget API key, from someone that has rights to publish the package to Nuget. + +``` +cd docker +docker build . # this will produce a hash key, say 12345678 +docker run -e "APIKEY=your_nuget_key_here" 12345678 +``` + +This container has been registered on Docker Hub, and can be run like so: + +``` +docker run -e "APIKEY=your_nuget_key_here" darrencauthon/csharp-sparkpost +``` diff --git a/examples/BCC/BCC.csproj b/examples/BCC/BCC.csproj new file mode 100644 index 00000000..d91d5ff1 --- /dev/null +++ b/examples/BCC/BCC.csproj @@ -0,0 +1,48 @@ + + + + Debug + AnyCPU + {16978032-B34C-44B6-8DA1-475D751338F1} + Exe + BCC + BCC + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + full + true + bin\Release + prompt + 4 + true + + + + + + ..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\SparkPost.1.6.2\lib\net45\SparkPost.dll + + + + + + + + + + + \ No newline at end of file diff --git a/examples/BCC/Program.cs b/examples/BCC/Program.cs new file mode 100644 index 00000000..aa83bc5f --- /dev/null +++ b/examples/BCC/Program.cs @@ -0,0 +1,60 @@ +using System; +using System.Configuration; + +namespace SparkPost.Examples +{ + internal class BCC + { + public static void Main(string[] args) + { + var settings = ConfigurationManager.AppSettings; + var fromAddr = settings["fromaddr"]; + var toAddr = settings["toaddr"]; + var ccAddr = settings["ccaddr"]; + var bccAddr = settings["bccaddr"]; + + var trans = new Transmission(); + + var to = new Recipient + { + Address = new Address {Email = toAddr} + }; + trans.Recipients.Add(to); + + var cc = new Recipient + { + Address = new Address + { + Email = ccAddr, + HeaderTo = toAddr + } + }; + trans.Recipients.Add(cc); + + var bcc = new Recipient + { + Address = new Address + { + Email = bccAddr, + HeaderTo = toAddr + } + }; + trans.Recipients.Add(bcc); + + trans.Content.From.Email = fromAddr; + trans.Content.Subject = "SparkPost BCC / CC example"; + trans.Content.Text = + "This message was sent To 1 recipient, 1 recipient was CC'd and 1 sneaky recipient was BCC'd."; + trans.Content.Headers.Add("CC", ccAddr); + + Console.Write("Sending BCC / CC sample mail..."); + + var client = new Client(settings["apikey"]); + client.CustomSettings.SendingMode = SendingModes.Sync; + + var response = client.Transmissions.Send(trans); + + Console.WriteLine("done"); + } + } +} \ No newline at end of file diff --git a/examples/BCC/Properties/AssemblyInfo.cs b/examples/BCC/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a6581ba6 --- /dev/null +++ b/examples/BCC/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("BCC")] +[assembly: AssemblyDescription("SparkPost C# BCC Example")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/examples/BCC/packages.config b/examples/BCC/packages.config new file mode 100644 index 00000000..6a1b8114 --- /dev/null +++ b/examples/BCC/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/examples/CC/CC.csproj b/examples/CC/CC.csproj new file mode 100644 index 00000000..629a6bd0 --- /dev/null +++ b/examples/CC/CC.csproj @@ -0,0 +1,51 @@ + + + + Debug + AnyCPU + {2B086611-A56B-4857-9F7F-A8603D7AA3FD} + Exe + CC + CC + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + full + true + bin\Release + prompt + 4 + true + + + + + + ..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\SparkPost.1.6.2\lib\net45\SparkPost.dll + + + + + + + + + + app.config + + + + \ No newline at end of file diff --git a/examples/CC/Program.cs b/examples/CC/Program.cs new file mode 100644 index 00000000..1c569389 --- /dev/null +++ b/examples/CC/Program.cs @@ -0,0 +1,48 @@ +using System; +using System.Configuration; + +namespace SparkPost.Examples +{ + internal class CC + { + public static void Main(string[] args) + { + var settings = ConfigurationManager.AppSettings; + var fromAddr = settings["fromaddr"]; + var toAddr = settings["toaddr"]; + var ccAddr = settings["ccaddr"]; + + var trans = new Transmission(); + + var to = new Recipient + { + Address = new Address {Email = toAddr} + }; + trans.Recipients.Add(to); + + var cc = new Recipient + { + Address = new Address + { + Email = ccAddr, + HeaderTo = toAddr + } + }; + trans.Recipients.Add(cc); + + trans.Content.From.Email = fromAddr; + trans.Content.Subject = "SparkPost CC example"; + trans.Content.Text = "This message was sent To 1 recipient and 1 recipient was CC'd."; + trans.Content.Headers.Add("CC", ccAddr); + + Console.Write("Sending CC sample mail..."); + + var client = new Client(settings["apikey"]); + client.CustomSettings.SendingMode = SendingModes.Sync; + + var response = client.Transmissions.Send(trans); + + Console.WriteLine("done"); + } + } +} \ No newline at end of file diff --git a/examples/CC/Properties/AssemblyInfo.cs b/examples/CC/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..8b25fd52 --- /dev/null +++ b/examples/CC/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("CC")] +[assembly: AssemblyDescription("SparkPost C# CC Example")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/examples/CC/packages.config b/examples/CC/packages.config new file mode 100644 index 00000000..6a1b8114 --- /dev/null +++ b/examples/CC/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/examples/Examples.sln b/examples/Examples.sln new file mode 100644 index 00000000..66581834 --- /dev/null +++ b/examples/Examples.sln @@ -0,0 +1,35 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendInline", "SendInline\SendInline.csproj", "{8D45D223-E1FE-4652-A37E-09507AC4E107}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendTemplate", "SendTemplate\SendTemplate.csproj", "{A85DDE10-EBD6-4B58-93D6-185809C73FE8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CC", "CC\CC.csproj", "{2B086611-A56B-4857-9F7F-A8603D7AA3FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BCC", "BCC\BCC.csproj", "{16978032-B34C-44B6-8DA1-475D751338F1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16978032-B34C-44B6-8DA1-475D751338F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16978032-B34C-44B6-8DA1-475D751338F1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16978032-B34C-44B6-8DA1-475D751338F1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16978032-B34C-44B6-8DA1-475D751338F1}.Release|Any CPU.Build.0 = Release|Any CPU + {2B086611-A56B-4857-9F7F-A8603D7AA3FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B086611-A56B-4857-9F7F-A8603D7AA3FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B086611-A56B-4857-9F7F-A8603D7AA3FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B086611-A56B-4857-9F7F-A8603D7AA3FD}.Release|Any CPU.Build.0 = Release|Any CPU + {8D45D223-E1FE-4652-A37E-09507AC4E107}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D45D223-E1FE-4652-A37E-09507AC4E107}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D45D223-E1FE-4652-A37E-09507AC4E107}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D45D223-E1FE-4652-A37E-09507AC4E107}.Release|Any CPU.Build.0 = Release|Any CPU + {A85DDE10-EBD6-4B58-93D6-185809C73FE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A85DDE10-EBD6-4B58-93D6-185809C73FE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A85DDE10-EBD6-4B58-93D6-185809C73FE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A85DDE10-EBD6-4B58-93D6-185809C73FE8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/examples/SendInline/Program.cs b/examples/SendInline/Program.cs new file mode 100644 index 00000000..da028f55 --- /dev/null +++ b/examples/SendInline/Program.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Configuration; + +namespace SparkPost.Examples +{ + internal class SendInline + { + public static void Main(string[] args) + { + var settings = ConfigurationManager.AppSettings; + var fromAddr = settings["fromaddr"]; + var toAddr = settings["toaddr"]; + + var trans = new Transmission(); + + var to = new Recipient + { + Address = new Address + { + Email = toAddr + }, + SubstitutionData = new Dictionary + { + {"firstName", "Jane"} + } + }; + + trans.Recipients.Add(to); + + trans.SubstitutionData["firstName"] = "Oh Ye Of Little Name"; + + trans.Content.From.Email = fromAddr; + trans.Content.Subject = "SparkPost online content example"; + trans.Content.Text = "Greetings {{firstName or 'recipient'}}\nHello from C# land."; + trans.Content.Html = + "

Greetings {{firstName or 'recipient'}}

Hello from C# land.

"; + + Console.Write("Sending mail..."); + + var client = new Client(settings["apikey"]); + client.CustomSettings.SendingMode = SendingModes.Sync; + + var response = client.Transmissions.Send(trans); + + Console.WriteLine("done"); + } + } +} \ No newline at end of file diff --git a/examples/SendInline/Properties/AssemblyInfo.cs b/examples/SendInline/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..228df2b9 --- /dev/null +++ b/examples/SendInline/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("SendInline")] +[assembly: AssemblyDescription("SparkPost C# Send Inline Example")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/examples/SendInline/SendInline.csproj b/examples/SendInline/SendInline.csproj new file mode 100644 index 00000000..7f38b857 --- /dev/null +++ b/examples/SendInline/SendInline.csproj @@ -0,0 +1,51 @@ + + + + Debug + AnyCPU + {8D45D223-E1FE-4652-A37E-09507AC4E107} + Exe + SendInline + SendInline + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + full + true + bin\Release + prompt + 4 + true + + + + + + ..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\SparkPost.1.6.2\lib\net45\SparkPost.dll + + + + + + + + + + app.config + + + + \ No newline at end of file diff --git a/examples/SendInline/packages.config b/examples/SendInline/packages.config new file mode 100644 index 00000000..6a1b8114 --- /dev/null +++ b/examples/SendInline/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/examples/SendTemplate/Program.cs b/examples/SendTemplate/Program.cs new file mode 100644 index 00000000..47c2a69e --- /dev/null +++ b/examples/SendTemplate/Program.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Configuration; + +namespace SparkPost.Examples +{ + internal class Order + { + public int OrderId { get; set; } + public string Desc { get; set; } + public int Total { get; set; } + } + + internal class SendTemplate + { + public static void Main(string[] args) + { + var settings = ConfigurationManager.AppSettings; + var fromAddr = settings["fromaddr"]; + var toAddr = settings["toaddr"]; + + var trans = new Transmission(); + + var to = new Recipient + { + Address = new Address + { + Email = toAddr + }, + SubstitutionData = new Dictionary + { + {"firstName", "Jane"} + } + }; + + trans.Recipients.Add(to); + trans.SubstitutionData["title"] = "Dr"; + trans.SubstitutionData["firstName"] = "Rick"; + trans.SubstitutionData["lastName"] = "Sanchez"; + trans.SubstitutionData["orders"] = new List + { + new Order {OrderId = 101, Desc = "Tomatoes", Total = 5}, + new Order {OrderId = 271, Desc = "Entropy", Total = 314} + }; + + trans.Content.From.Email = fromAddr; + trans.Content.TemplateId = "orderSummary"; + + Console.Write("Sending mail..."); + + var client = new Client(settings["apikey"]); + client.CustomSettings.SendingMode = SendingModes.Sync; + + var response = client.Transmissions.Send(trans); + + Console.WriteLine("done"); + } + } +} \ No newline at end of file diff --git a/examples/SendTemplate/Properties/AssemblyInfo.cs b/examples/SendTemplate/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a48e3ac7 --- /dev/null +++ b/examples/SendTemplate/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("SendTemplate")] +[assembly: AssemblyDescription("SparkPost C# Send Template Example")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/examples/SendTemplate/SendTemplate.csproj b/examples/SendTemplate/SendTemplate.csproj new file mode 100644 index 00000000..866d20e4 --- /dev/null +++ b/examples/SendTemplate/SendTemplate.csproj @@ -0,0 +1,53 @@ + + + + Debug + AnyCPU + {A85DDE10-EBD6-4B58-93D6-185809C73FE8} + Exe + SendTemplate + SendTemplate + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + full + true + bin\Release + prompt + 4 + true + + + + + + ..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\SparkPost.1.6.2\lib\net45\SparkPost.dll + + + + + PreserveNewest + + + + + + + app.config + + + + \ No newline at end of file diff --git a/examples/SendTemplate/packages.config b/examples/SendTemplate/packages.config new file mode 100644 index 00000000..6a1b8114 --- /dev/null +++ b/examples/SendTemplate/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/examples/app.config b/examples/app.config new file mode 100644 index 00000000..a69366c3 --- /dev/null +++ b/examples/app.config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/SparkPost.Acceptance/App.config b/src/SparkPost.Acceptance/App.config new file mode 100644 index 00000000..8f6a4f76 --- /dev/null +++ b/src/SparkPost.Acceptance/App.config @@ -0,0 +1,9 @@ + + + +
+ + + + + \ No newline at end of file diff --git a/src/SparkPost.Acceptance/ClientSteps.cs b/src/SparkPost.Acceptance/ClientSteps.cs new file mode 100644 index 00000000..953633af --- /dev/null +++ b/src/SparkPost.Acceptance/ClientSteps.cs @@ -0,0 +1,15 @@ +using TechTalk.SpecFlow; + +namespace SparkPost.Acceptance +{ + [Binding] + public class ClientSteps + { + [Given(@"my api key is '(.*)'")] + public void GivenMyApiKeyIs(string apiKey) + { + var client = new Client(apiKey); + ScenarioContext.Current.Set(client); + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/MessageEvents.feature b/src/SparkPost.Acceptance/MessageEvents.feature new file mode 100644 index 00000000..36eac841 --- /dev/null +++ b/src/SparkPost.Acceptance/MessageEvents.feature @@ -0,0 +1,8 @@ +Feature: Message Events + +Background: + Given my api key is 'yyy' + +Scenario: Samples + When I ask for samples of 'bounce' + Then it should return a 200 \ No newline at end of file diff --git a/src/SparkPost.Acceptance/MessageEvents.feature.cs b/src/SparkPost.Acceptance/MessageEvents.feature.cs new file mode 100644 index 00000000..14ae0a0c --- /dev/null +++ b/src/SparkPost.Acceptance/MessageEvents.feature.cs @@ -0,0 +1,93 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:2.1.0.0 +// SpecFlow Generator Version:2.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace SparkPost.Acceptance +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Message Events")] + public partial class MessageEventsFeature + { + + private TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "MessageEvents.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Message Events", null, ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + public virtual void FeatureBackground() + { +#line 3 +#line 4 + testRunner.Given("my api key is \'yyy\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Samples")] + public virtual void Samples() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Samples", ((string[])(null))); +#line 6 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 7 + testRunner.When("I ask for samples of \'bounce\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 8 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/SparkPost.Acceptance/MessageEventsSteps.cs b/src/SparkPost.Acceptance/MessageEventsSteps.cs new file mode 100644 index 00000000..61dc4b8d --- /dev/null +++ b/src/SparkPost.Acceptance/MessageEventsSteps.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using TechTalk.SpecFlow; + +namespace SparkPost.Acceptance +{ + [Binding] + public class MessageEventsSteps + { + [When(@"I ask for samples of '(.*)'")] + public void WhenIAskForSamplesOf(string events) + { + var client = ScenarioContext.Current.Get(); + + MessageEventSampleResponse response = null; + + Task.Run(async () => { response = await client.MessageEvents.SamplesOf(events); }).Wait(); + + ScenarioContext.Current.Set(response); + ScenarioContext.Current.Set(response); + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Metrics.feature b/src/SparkPost.Acceptance/Metrics.feature new file mode 100644 index 00000000..f5fc7135 --- /dev/null +++ b/src/SparkPost.Acceptance/Metrics.feature @@ -0,0 +1,14 @@ +Feature: Metrics + +Background: + Given my api key is 'yyy' + +Scenario: Checking for count accepted + When I query my deliverability for count_accepted + Then it should return a 200 + And it should return some metrics count + +Scenario: Bounce reasons + When I query my bounce reasons + Then it should return a 200 + And it should return some metrics count \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Metrics.feature.cs b/src/SparkPost.Acceptance/Metrics.feature.cs new file mode 100644 index 00000000..4788bfab --- /dev/null +++ b/src/SparkPost.Acceptance/Metrics.feature.cs @@ -0,0 +1,115 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:1.9.0.77 +// SpecFlow Generator Version:1.9.0.0 +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace SparkPost.Acceptance +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Metrics")] + public partial class MetricsFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "Metrics.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Metrics", "", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + public virtual void FeatureBackground() + { +#line 3 +#line 4 + testRunner.Given("my api key is \'yyy\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Checking for count accepted")] + public virtual void CheckingForCountAccepted() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Checking for count accepted", ((string[])(null))); +#line 6 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 7 + testRunner.When("I query my deliverability for count_accepted", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 8 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 9 + testRunner.And("it should return some metrics count", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Bounce reasons")] + public virtual void BounceReasons() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Bounce reasons", ((string[])(null))); +#line 11 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 12 + testRunner.When("I query my bounce reasons", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 13 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 14 + testRunner.And("it should return some metrics count", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/SparkPost.Acceptance/MetricsSteps.cs b/src/SparkPost.Acceptance/MetricsSteps.cs new file mode 100644 index 00000000..598f22bf --- /dev/null +++ b/src/SparkPost.Acceptance/MetricsSteps.cs @@ -0,0 +1,51 @@ +using System; +using System.Threading.Tasks; +using Should; +using TechTalk.SpecFlow; + +namespace SparkPost.Acceptance +{ + [Binding] + public class MetricsSteps + { + [When(@"I query my deliverability for (.*)")] + public void WhenIQueryMyDeliverability(string metric) + { + var client = ScenarioContext.Current.Get(); + Response response = null; + Task.Run(async () => + { + response = await client.Metrics.GetDeliverability(new + { + from = DateTime.MinValue, + metrics = metric + }); + }).Wait(); + + ScenarioContext.Current.Set(response); + } + + [When(@"I query my bounce reasons")] + public void y() + { + var client = ScenarioContext.Current.Get(); + Response response = null; + Task.Run(async () => + { + response = await client.Metrics.GetBounceReasons(new + { + from = DateTime.MinValue + }); + }).Wait(); + + ScenarioContext.Current.Set(response); + } + + [Then("it should return some metrics count")] + public void x() + { + var response = ScenarioContext.Current.Get(); + response.ShouldBeType(typeof(GetMetricsResponse)); + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Properties/AssemblyInfo.cs b/src/SparkPost.Acceptance/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..10a3c4eb --- /dev/null +++ b/src/SparkPost.Acceptance/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("SparkPost.Acceptance")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SparkPost.Acceptance")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8f62193b-1c44-4e92-96c7-8ebd610f7669")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/SparkPost.Acceptance/RecipientListSteps.cs b/src/SparkPost.Acceptance/RecipientListSteps.cs new file mode 100644 index 00000000..fa5575b8 --- /dev/null +++ b/src/SparkPost.Acceptance/RecipientListSteps.cs @@ -0,0 +1,109 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using TechTalk.SpecFlow; +using TechTalk.SpecFlow.Assist; + +namespace SparkPost.Acceptance +{ + [Binding] + public class RecipientListSteps + { + private readonly ScenarioContext scenarioContext; + + public RecipientListSteps(ScenarioContext scenarioContext) + { + this.scenarioContext = scenarioContext; + } + + [Given(@"I have a new recipient list as")] + public void GivenIHaveANewRecipientListAs(Table table) + { + var recipientList = table.CreateInstance(); + scenarioContext.Set(recipientList); + } + + [Given(@"I add '(.*)' to the recipient list")] + public void GivenIAddToTheRecipientList(string email) + { + var recipientList = scenarioContext.Get(); + recipientList.Recipients.Add(new Recipient {Address = new Address {Email = email}}); + } + + [Given(@"I clear the recipients on the recipient list")] + public void x() + { + var recipientList = scenarioContext.Get(); + recipientList.Recipients.Clear(); + } + + [Given(@"I do not have a recipient list of id '(.*)'")] + public void GivenIDoNotHaveARecipientListOfId(string id) + { + var client = scenarioContext.Get(); + client.RecipientLists.Delete(id); + } + + [When(@"I create the recipient list")] + public void WhenICreateTheRecipientList() + { + var recipientList = scenarioContext.Get(); + + var client = scenarioContext.Get(); + + SendRecipientListsResponse response = null; + Task.Run(async () => { response = await client.RecipientLists.Create(recipientList); }).Wait(); + + scenarioContext.Set(response); + scenarioContext.Set(response); + } + + [When(@"I retrieve the ""(.*)"" recipient list")] + public void WhenIRetrieveTheRecipientList(string key) + { + var client = scenarioContext.Get(); + + RetrieveRecipientListsResponse response = null; + + Task.Run(async () => + { + response = await client.RecipientLists.Retrieve(key); + }).Wait(); + + scenarioContext.Set(response.RecipientList); + } + + [When(@"I update the recipient list")] + public void WhenIUpdateTheRecipientList() + { + var recipientList = scenarioContext.Get(); + + var client = scenarioContext.Get(); + + UpdateRecipientListResponse response = null; + + Task.Run(async () => + { + response = await client.RecipientLists.Update(recipientList); + }).Wait(); + + scenarioContext.Set(response); + } + + [Then(@"it should have the following recipient list values")] + public void ThenItShouldHaveTheFollowingRecipientListValues(Table table) + { + var recipientList = scenarioContext.Get(); + table.CompareToInstance(recipientList); + } + + [Then(@"it should have the following recipients")] + public void ThenItShouldHaveTheFollowingRecipients(Table table) + { + var recipientLists = scenarioContext.Get() + .Recipients + .Select(x => new {x.Address.Email}); + table.CompareToSet(recipientLists); + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/RecipientLists.feature b/src/SparkPost.Acceptance/RecipientLists.feature new file mode 100644 index 00000000..f1a13566 --- /dev/null +++ b/src/SparkPost.Acceptance/RecipientLists.feature @@ -0,0 +1,61 @@ +Feature: Recipient Lists + +Background: + Given my api key is 'yyy' + +Scenario: Retrieving a recipient list + Given I do not have a recipient list of id 'test-name' + And I have a new recipient list as + | Id | Name | Description | + | test-name | Test Name | Test Description | + And I add 'test@test.com' to the recipient list + And I add 'test2@test.com' to the recipient list + When I create the recipient list + When I retrieve the "test-name" recipient list + Then it should return a 200 + And it should have the following recipients + | Email | + | test@test.com | + | test2@test.com | + And it should have the following recipient list values + | Id | Name | Description | + | test-name | Test Name | Test Description | + +Scenario: Creating a recipient list + Given I do not have a recipient list of id 'test-name' + And I have a new recipient list as + | Id | Name | Description | + | test-name | Test Name | Test Description | + And I add 'test@test.com' to the recipient list + When I create the recipient list + Then it should return a 200 + When I retrieve the "test-name" recipient list + Then it should have the following recipients + | Email | + | test@test.com | + +Scenario: Updating a recipient list + Given I do not have a recipient list of id 'test-name' + And I have a new recipient list as + | Id | Name | Description | + | test-name | Test Name | Test Description | + And I add 'test@test.com' to the recipient list + And I add 'test2@test.com' to the recipient list + When I create the recipient list + Given I have a new recipient list as + | Id | Name | Description | + | test-name | Test Name Again | Test Description Second | + And I clear the recipients on the recipient list + And I add 'test1@test.com' to the recipient list + And I add 'test3@test.com' to the recipient list + When I update the recipient list + Then it should return a 200 + When I retrieve the "test-name" recipient list + Then it should return a 200 + And it should have the following recipient list values + | Id | Name | Description | + | test-name | Test Name Again | Test Description Second | + And it should have the following recipients + | Email | + | test1@test.com | + | test3@test.com | \ No newline at end of file diff --git a/src/SparkPost.Acceptance/RecipientLists.feature.cs b/src/SparkPost.Acceptance/RecipientLists.feature.cs new file mode 100644 index 00000000..cd9357a8 --- /dev/null +++ b/src/SparkPost.Acceptance/RecipientLists.feature.cs @@ -0,0 +1,250 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:2.1.0.0 +// SpecFlow Generator Version:2.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace SparkPost.Acceptance +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Recipient Lists")] + public partial class RecipientListsFeature + { + + private TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "RecipientLists.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Recipient Lists", null, ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + public virtual void FeatureBackground() + { +#line 3 +#line 4 + testRunner.Given("my api key is \'yyy\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Retrieving a recipient list")] + public virtual void RetrievingARecipientList() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Retrieving a recipient list", ((string[])(null))); +#line 6 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 7 + testRunner.Given("I do not have a recipient list of id \'test-name\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { + "Id", + "Name", + "Description"}); + table1.AddRow(new string[] { + "test-name", + "Test Name", + "Test Description"}); +#line 8 + testRunner.And("I have a new recipient list as", ((string)(null)), table1, "And "); +#line 11 + testRunner.And("I add \'test@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 12 + testRunner.And("I add \'test2@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 13 + testRunner.When("I create the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 14 + testRunner.When("I retrieve the \"test-name\" recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 15 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { + "Email"}); + table2.AddRow(new string[] { + "test@test.com"}); + table2.AddRow(new string[] { + "test2@test.com"}); +#line 16 + testRunner.And("it should have the following recipients", ((string)(null)), table2, "And "); +#line hidden + TechTalk.SpecFlow.Table table3 = new TechTalk.SpecFlow.Table(new string[] { + "Id", + "Name", + "Description"}); + table3.AddRow(new string[] { + "test-name", + "Test Name", + "Test Description"}); +#line 20 + testRunner.And("it should have the following recipient list values", ((string)(null)), table3, "And "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Creating a recipient list")] + public virtual void CreatingARecipientList() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Creating a recipient list", ((string[])(null))); +#line 24 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 25 + testRunner.Given("I do not have a recipient list of id \'test-name\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + TechTalk.SpecFlow.Table table4 = new TechTalk.SpecFlow.Table(new string[] { + "Id", + "Name", + "Description"}); + table4.AddRow(new string[] { + "test-name", + "Test Name", + "Test Description"}); +#line 26 + testRunner.And("I have a new recipient list as", ((string)(null)), table4, "And "); +#line 29 + testRunner.And("I add \'test@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 30 + testRunner.When("I create the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 31 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 32 + testRunner.When("I retrieve the \"test-name\" recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden + TechTalk.SpecFlow.Table table5 = new TechTalk.SpecFlow.Table(new string[] { + "Email"}); + table5.AddRow(new string[] { + "test@test.com"}); +#line 33 + testRunner.Then("it should have the following recipients", ((string)(null)), table5, "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Updating a recipient list")] + public virtual void UpdatingARecipientList() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Updating a recipient list", ((string[])(null))); +#line 37 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 38 + testRunner.Given("I do not have a recipient list of id \'test-name\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + TechTalk.SpecFlow.Table table6 = new TechTalk.SpecFlow.Table(new string[] { + "Id", + "Name", + "Description"}); + table6.AddRow(new string[] { + "test-name", + "Test Name", + "Test Description"}); +#line 39 + testRunner.And("I have a new recipient list as", ((string)(null)), table6, "And "); +#line 42 + testRunner.And("I add \'test@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 43 + testRunner.And("I add \'test2@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 44 + testRunner.When("I create the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden + TechTalk.SpecFlow.Table table7 = new TechTalk.SpecFlow.Table(new string[] { + "Id", + "Name", + "Description"}); + table7.AddRow(new string[] { + "test-name", + "Test Name Again", + "Test Description Second"}); +#line 45 + testRunner.Given("I have a new recipient list as", ((string)(null)), table7, "Given "); +#line 48 + testRunner.And("I clear the recipients on the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 49 + testRunner.And("I add \'test1@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 50 + testRunner.And("I add \'test3@test.com\' to the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 51 + testRunner.When("I update the recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 52 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 53 + testRunner.When("I retrieve the \"test-name\" recipient list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 54 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + TechTalk.SpecFlow.Table table8 = new TechTalk.SpecFlow.Table(new string[] { + "Id", + "Name", + "Description"}); + table8.AddRow(new string[] { + "test-name", + "Test Name Again", + "Test Description Second"}); +#line 55 + testRunner.And("it should have the following recipient list values", ((string)(null)), table8, "And "); +#line hidden + TechTalk.SpecFlow.Table table9 = new TechTalk.SpecFlow.Table(new string[] { + "Email"}); + table9.AddRow(new string[] { + "test1@test.com"}); + table9.AddRow(new string[] { + "test3@test.com"}); +#line 58 + testRunner.And("it should have the following recipients", ((string)(null)), table9, "And "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/SparkPost.Acceptance/ResponseSteps.cs b/src/SparkPost.Acceptance/ResponseSteps.cs new file mode 100644 index 00000000..d0fd7a5d --- /dev/null +++ b/src/SparkPost.Acceptance/ResponseSteps.cs @@ -0,0 +1,16 @@ +using Should; +using TechTalk.SpecFlow; + +namespace SparkPost.Acceptance +{ + [Binding] + public class ResponseSteps + { + [Then(@"it should return a (.*)")] + public void ThenItShouldReturnA(int statusCode) + { + var response = ScenarioContext.Current.Get(); + response.StatusCode.GetHashCode().ShouldEqual(statusCode); + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/SparkPost.Acceptance.csproj b/src/SparkPost.Acceptance/SparkPost.Acceptance.csproj new file mode 100644 index 00000000..84bebd8e --- /dev/null +++ b/src/SparkPost.Acceptance/SparkPost.Acceptance.csproj @@ -0,0 +1,132 @@ + + + + + Debug + AnyCPU + {8F62193B-1C44-4E92-96C7-8EBD610F7669} + Library + Properties + SparkPost.Acceptance + SparkPost.Acceptance + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + True + + + ..\packages\Should.1.1.20\lib\Should.dll + True + + + + + + + + + + + ..\packages\SpecFlow.2.1.0\lib\net45\TechTalk.SpecFlow.dll + True + + + + + MessageEvents.feature + True + True + + + + + + Metrics.feature + True + True + + + + Suppressions.feature + True + True + + + Transmissions.feature + True + True + + + True + True + RecipientLists.feature + + + + + + + + + {a5dda3e3-7b3d-46c3-b4bb-c627fba37812} + SparkPost + + + + + + SpecFlowSingleFileGenerator + MessageEvents.feature.cs + + + + SpecFlowSingleFileGenerator + Metrics.feature.cs + + + SpecFlowSingleFileGenerator + Suppressions.feature.cs + + + SpecFlowSingleFileGenerator + Transmissions.feature.cs + + + SpecFlowSingleFileGenerator + RecipientLists.feature.cs + + + + + Always + + + + + \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Suppressions.feature b/src/SparkPost.Acceptance/Suppressions.feature new file mode 100644 index 00000000..327fd3f3 --- /dev/null +++ b/src/SparkPost.Acceptance/Suppressions.feature @@ -0,0 +1,10 @@ +Feature: Suppressions + +Background: + Given my api key is 'yyy' + +Scenario: Adding an email to the suppressions list + Given I have a random email address ending in '@cauthon.com' + When I add my random email address a to my suppressions list + Then it should return a 200 + And my random email address should be on my suppressions list \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Suppressions.feature.cs b/src/SparkPost.Acceptance/Suppressions.feature.cs new file mode 100644 index 00000000..4cdcc176 --- /dev/null +++ b/src/SparkPost.Acceptance/Suppressions.feature.cs @@ -0,0 +1,97 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:2.1.0.0 +// SpecFlow Generator Version:2.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace SparkPost.Acceptance +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Suppressions")] + public partial class SuppressionsFeature + { + + private TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "Suppressions.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Suppressions", null, ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + public virtual void FeatureBackground() + { +#line 3 +#line 4 + testRunner.Given("my api key is \'yyy\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Adding an email to the suppressions list")] + public virtual void AddingAnEmailToTheSuppressionsList() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Adding an email to the suppressions list", ((string[])(null))); +#line 6 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 7 + testRunner.Given("I have a random email address ending in \'@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 8 + testRunner.When("I add my random email address a to my suppressions list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 9 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line 10 + testRunner.And("my random email address should be on my suppressions list", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/SparkPost.Acceptance/SuppressionsSteps.cs b/src/SparkPost.Acceptance/SuppressionsSteps.cs new file mode 100644 index 00000000..b6b03b2b --- /dev/null +++ b/src/SparkPost.Acceptance/SuppressionsSteps.cs @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Should; +using TechTalk.SpecFlow; + +namespace SparkPost.Acceptance +{ + [Binding] + public class SuppressionsSteps + { + private readonly ScenarioContext scenarioContext; + + public SuppressionsSteps(ScenarioContext scenarioContext) + { + this.scenarioContext = scenarioContext; + } + + [Given(@"I have a random email address ending in '(.*)'")] + public void y(string email) + { + scenarioContext["randomemail"] = $"{Guid.NewGuid().ToString().Split('-')[0]}{email}"; + } + + [When(@"I add my random email address a to my suppressions list")] + public void WhenIAddToMySuppressionsList() + { + var email = scenarioContext["randomemail"] as string; + + var client = scenarioContext.Get(); + + UpdateSuppressionResponse response = null; + + Task.Run(async () => { response = await client.Suppressions.CreateOrUpdate(new [] {email}); }).Wait(); + + scenarioContext.Set(response); + scenarioContext.Set(response); + } + + [Then(@"my random email address should be on my suppressions list")] + public void ThenShouldBeOnMySuppressionsList() + { + var email = scenarioContext["randomemail"] as string; + + var client = scenarioContext.Get(); + + ListSuppressionResponse response = null; + + Thread.Sleep(30000); + + Task.Run(async () => + { + response = await client.Suppressions.Retrieve(email); + response.Suppressions.Count().ShouldBeGreaterThan(0); + }).Wait(); + + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/TransmissionSteps.cs b/src/SparkPost.Acceptance/TransmissionSteps.cs new file mode 100644 index 00000000..6c010816 --- /dev/null +++ b/src/SparkPost.Acceptance/TransmissionSteps.cs @@ -0,0 +1,113 @@ +using System.Threading; +using System.Threading.Tasks; +using TechTalk.SpecFlow; +using TechTalk.SpecFlow.Assist; + +namespace SparkPost.Acceptance +{ + [Binding] + public class TransmissionSteps + { + private readonly ScenarioContext scenarioContext; + + public TransmissionSteps(ScenarioContext scenarioContext) + { + this.scenarioContext = scenarioContext; + } + + [Given(@"I have a new transmission")] + public void GivenIHaveANewTransmissionWith() + { + var transmission = new Transmission(); + scenarioContext.Set(transmission); + } + + [Given(@"the transmission is meant to be sent from '(.*)'")] + public void GivenTheTransmissionIsMeantToBeSentfrom(string email) + { + var transmission = scenarioContext.Get(); + transmission.Content.From = new Address {Email = email}; + scenarioContext.Set(transmission); + } + + [Given(@"the transmission is meant to be sent to '(.*)'")] + public void GivenTheTransmissionIsMeantToBeSentTo(string email) + { + var transmission = scenarioContext.Get(); + transmission.Recipients.Add(new Recipient {Address = new Address {Email = email}}); + scenarioContext.Set(transmission); + } + + [Given(@"the transmission content is")] + public void GivenTheTransmissionContentIs(Table table) + { + var transmission = scenarioContext.Get(); + table.FillInstance(transmission.Content); + scenarioContext.Set(transmission); + } + + [Given(@"the transmission template id is set to '(.*)'")] + public void x(string templateId) + { + var transmission = scenarioContext.Get(); + + transmission.Content.TemplateId = templateId; + + scenarioContext.Set(transmission); + } + + [Given(@"the transmission has a text file attachment")] + public void GivenTheTransmissionHasATextFileAttachment() + { + var transmission = scenarioContext.Get(); + + var attachment = File.Create("testtextfile.txt"); + + transmission.Content.Attachments.Add(attachment); + + scenarioContext.Set(transmission); + } + + [Given(@"the transmission is meant to be CCd to '(.*)'")] + public void GivenTheTransmissionIsMeantToBeCCdTo(string email) + { + var transmission = scenarioContext.Get(); + + transmission.Recipients.Add(new Recipient + { + Type = RecipientType.CC, + Address = new Address {Email = email} + }); + + scenarioContext.Set(transmission); + } + + [Given(@"the transmission is meant to be BCCd to '(.*)'")] + public void GivenTheTransmissionIsMeantToBeBCCdTo(string email) + { + var transmission = scenarioContext.Get(); + + transmission.Recipients.Add(new Recipient + { + Type = RecipientType.BCC, + Address = new Address {Email = email} + }); + + scenarioContext.Set(transmission); + } + + [When(@"I send the transmission")] + public void WhenISendTheTransmission() + { + var client = scenarioContext.Get(); + var transmission = scenarioContext.Get(); + + SendTransmissionResponse response = null; + + Task.Run(async () => { response = await client.Transmissions.Send(transmission); }).Wait(); + + scenarioContext.Set(response); + scenarioContext.Set(response); + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Transmissions.feature b/src/SparkPost.Acceptance/Transmissions.feature new file mode 100644 index 00000000..84efa2a4 --- /dev/null +++ b/src/SparkPost.Acceptance/Transmissions.feature @@ -0,0 +1,59 @@ +Feature: Transmissions + +Background: + Given my api key is 'yyy' + +Scenario: Sending a regular email + Given I have a new transmission + And the transmission is meant to be sent from 'darren@cauthon.com' + And the transmission is meant to be sent to 'darren@cauthon.com' + And the transmission content is + | Subject | Html | + | Test Email | this is a test email | + When I send the transmission + Then it should return a 200 + +Scenario: Sending a regular email with an attachment + Given I have a new transmission + And the transmission is meant to be sent from 'darren@cauthon.com' + And the transmission is meant to be sent to 'darren@cauthon.com' + And the transmission has a text file attachment + And the transmission content is + | Subject | Html | + | Test Email with an attachment | this is a test email | + When I send the transmission + Then it should return a 200 + +Scenario: Sending a template email with an attachment, which will be ignored and no attachment will be included + Given I have a new transmission + And the transmission is meant to be sent from 'darren@cauthon.com' + And the transmission is meant to be sent to 'darren@cauthon.com' + And the transmission has a text file attachment + And the transmission template id is set to 'my-first-email' + When I send the transmission + Then it should return a 200 + +Scenario: Using CC/BCC with one direct recipient + Given I have a new transmission + And the transmission is meant to be sent from 'darren@cauthon.com' + And the transmission is meant to be sent to 'darren@cauthon.com' + And the transmission is meant to be CCd to 'darrencauthon@gmail.com' + And the transmission is meant to be BCCd to 'darrencauthon@yahoo.com' + And the transmission content is + | Subject | Html | + | Test Email With CC and BCC (1 recipient) | this is a test email | + When I send the transmission + Then it should return a 200 + +Scenario: Using CC/BCC with two direct recipients + Given I have a new transmission + And the transmission is meant to be sent from 'darren@cauthon.com' + And the transmission is meant to be sent to 'darrencauthon@hotmail.com' + And the transmission is meant to be sent to 'darren@cauthon.com' + And the transmission is meant to be CCd to 'darrencauthon@gmail.com' + And the transmission is meant to be BCCd to 'darrencauthon@yahoo.com' + And the transmission content is + | Subject | Html | + | Test Email With CC and BCC (2 recipients) | this is a test email | + When I send the transmission + Then it should return a 200 \ No newline at end of file diff --git a/src/SparkPost.Acceptance/Transmissions.feature.cs b/src/SparkPost.Acceptance/Transmissions.feature.cs new file mode 100644 index 00000000..78659b53 --- /dev/null +++ b/src/SparkPost.Acceptance/Transmissions.feature.cs @@ -0,0 +1,246 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by SpecFlow (http://www.specflow.org/). +// SpecFlow Version:1.9.0.77 +// SpecFlow Generator Version:1.9.0.0 +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +#region Designer generated code +#pragma warning disable +namespace SparkPost.Acceptance +{ + using TechTalk.SpecFlow; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [NUnit.Framework.TestFixtureAttribute()] + [NUnit.Framework.DescriptionAttribute("Transmissions")] + public partial class TransmissionsFeature + { + + private static TechTalk.SpecFlow.ITestRunner testRunner; + +#line 1 "Transmissions.feature" +#line hidden + + [NUnit.Framework.TestFixtureSetUpAttribute()] + public virtual void FeatureSetup() + { + testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(); + TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Transmissions", "", ProgrammingLanguage.CSharp, ((string[])(null))); + testRunner.OnFeatureStart(featureInfo); + } + + [NUnit.Framework.TestFixtureTearDownAttribute()] + public virtual void FeatureTearDown() + { + testRunner.OnFeatureEnd(); + testRunner = null; + } + + [NUnit.Framework.SetUpAttribute()] + public virtual void TestInitialize() + { + } + + [NUnit.Framework.TearDownAttribute()] + public virtual void ScenarioTearDown() + { + testRunner.OnScenarioEnd(); + } + + public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) + { + testRunner.OnScenarioStart(scenarioInfo); + } + + public virtual void ScenarioCleanup() + { + testRunner.CollectScenarioErrors(); + } + + public virtual void FeatureBackground() + { +#line 3 +#line 4 + testRunner.Given("my api key is \'yyy\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Sending a regular email")] + public virtual void SendingARegularEmail() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Sending a regular email", ((string[])(null))); +#line 6 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 7 + testRunner.Given("I have a new transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 8 + testRunner.And("the transmission is meant to be sent from \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 9 + testRunner.And("the transmission is meant to be sent to \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] { + "Subject", + "Html"}); + table1.AddRow(new string[] { + "Test Email", + "this is a test email"}); +#line 10 + testRunner.And("the transmission content is", ((string)(null)), table1, "And "); +#line 13 + testRunner.When("I send the transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 14 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Sending a regular email with an attachment")] + public virtual void SendingARegularEmailWithAnAttachment() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Sending a regular email with an attachment", ((string[])(null))); +#line 16 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 17 + testRunner.Given("I have a new transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 18 + testRunner.And("the transmission is meant to be sent from \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 19 + testRunner.And("the transmission is meant to be sent to \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 20 + testRunner.And("the transmission has a text file attachment", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] { + "Subject", + "Html"}); + table2.AddRow(new string[] { + "Test Email with an attachment", + "this is a test email"}); +#line 21 + testRunner.And("the transmission content is", ((string)(null)), table2, "And "); +#line 24 + testRunner.When("I send the transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 25 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Sending a template email with an attachment, which will be ignored and no attachm" + + "ent will be included")] + public virtual void SendingATemplateEmailWithAnAttachmentWhichWillBeIgnoredAndNoAttachmentWillBeIncluded() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Sending a template email with an attachment, which will be ignored and no attachm" + + "ent will be included", ((string[])(null))); +#line 27 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 28 + testRunner.Given("I have a new transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 29 + testRunner.And("the transmission is meant to be sent from \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 30 + testRunner.And("the transmission is meant to be sent to \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 31 + testRunner.And("the transmission has a text file attachment", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 32 + testRunner.And("the transmission template id is set to \'my-first-email\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 33 + testRunner.When("I send the transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 34 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Using CC/BCC with one direct recipient")] + public virtual void UsingCCBCCWithOneDirectRecipient() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Using CC/BCC with one direct recipient", ((string[])(null))); +#line 36 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 37 + testRunner.Given("I have a new transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 38 + testRunner.And("the transmission is meant to be sent from \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 39 + testRunner.And("the transmission is meant to be sent to \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 40 + testRunner.And("the transmission is meant to be CCd to \'darrencauthon@gmail.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 41 + testRunner.And("the transmission is meant to be BCCd to \'darrencauthon@yahoo.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + TechTalk.SpecFlow.Table table3 = new TechTalk.SpecFlow.Table(new string[] { + "Subject", + "Html"}); + table3.AddRow(new string[] { + "Test Email With CC and BCC (1 recipient)", + "this is a test email"}); +#line 42 + testRunner.And("the transmission content is", ((string)(null)), table3, "And "); +#line 45 + testRunner.When("I send the transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 46 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Using CC/BCC with two direct recipients")] + public virtual void UsingCCBCCWithTwoDirectRecipients() + { + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Using CC/BCC with two direct recipients", ((string[])(null))); +#line 48 +this.ScenarioSetup(scenarioInfo); +#line 3 +this.FeatureBackground(); +#line 49 + testRunner.Given("I have a new transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line 50 + testRunner.And("the transmission is meant to be sent from \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 51 + testRunner.And("the transmission is meant to be sent to \'darrencauthon@hotmail.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 52 + testRunner.And("the transmission is meant to be sent to \'darren@cauthon.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 53 + testRunner.And("the transmission is meant to be CCd to \'darrencauthon@gmail.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line 54 + testRunner.And("the transmission is meant to be BCCd to \'darrencauthon@yahoo.com\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden + TechTalk.SpecFlow.Table table4 = new TechTalk.SpecFlow.Table(new string[] { + "Subject", + "Html"}); + table4.AddRow(new string[] { + "Test Email With CC and BCC (2 recipients)", + "this is a test email"}); +#line 55 + testRunner.And("the transmission content is", ((string)(null)), table4, "And "); +#line 58 + testRunner.When("I send the transmission", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line 59 + testRunner.Then("it should return a 200", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + this.ScenarioCleanup(); + } + } +} +#pragma warning restore +#endregion diff --git a/src/SparkPost.Acceptance/packages.config b/src/SparkPost.Acceptance/packages.config new file mode 100644 index 00000000..139ce5c9 --- /dev/null +++ b/src/SparkPost.Acceptance/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/SparkPost.Acceptance/testtextfile.txt b/src/SparkPost.Acceptance/testtextfile.txt new file mode 100644 index 00000000..a2f808c9 --- /dev/null +++ b/src/SparkPost.Acceptance/testtextfile.txt @@ -0,0 +1 @@ +This is a text file. \ No newline at end of file diff --git a/src/SparkPost.Tests/ClientTests.cs b/src/SparkPost.Tests/ClientTests.cs index 79bf393a..d5001cd6 100644 --- a/src/SparkPost.Tests/ClientTests.cs +++ b/src/SparkPost.Tests/ClientTests.cs @@ -1,4 +1,6 @@ -using System.Net.Http; +using System; +using System.Net.Http; +using AutoMoq.Helpers; using NUnit.Framework; using Should; @@ -46,6 +48,43 @@ public void It_should_default_to_async() { client.CustomSettings.SendingMode.ShouldEqual(SendingModes.Async); } + + [Test] + public void it_should_have_inbound_domains() + { + client.InboundDomains.ShouldNotBeNull(); + } + + [Test] + public void It_should_set_any_subaccount_id_passed_to_it() + { + (new Client(Guid.NewGuid().ToString(), 1234)) + .SubaccountId.ShouldEqual(1234); + } + } + + [TestFixture] + public class UserAgentTests : AutoMoqTestFixture + { + [SetUp] + public void Setup() + { + ResetSubject(); + } + + [Test] + public void It_should_default_to_the_library_version() + { + Subject.UserAgent.ShouldEqual($"csharp-sparkpost/1.14.0"); + } + + [Test] + public void It_should_allow_the_user_agent_to_be_changed() + { + var userAgent = Guid.NewGuid().ToString(); + Subject.UserAgent = userAgent; + Subject.UserAgent.ShouldEqual(userAgent); + } } } } \ No newline at end of file diff --git a/src/SparkPost.Tests/DataMapperTests.cs b/src/SparkPost.Tests/DataMapperTests.cs index 238b2693..3a6e54e3 100644 --- a/src/SparkPost.Tests/DataMapperTests.cs +++ b/src/SparkPost.Tests/DataMapperTests.cs @@ -3,6 +3,7 @@ using System.Linq; using NUnit.Framework; using Should; +using SparkPost.ValueMappers; namespace SparkPost.Tests { @@ -258,6 +259,16 @@ public void metadata() .CastAs>()[key].ShouldEqual(value); } + [Test] + public void do_not_alter_the_keys_passed_to_metadata() + { + var key = "TEST"; + var value = Guid.NewGuid().ToString(); + transmission.Metadata[key] = value; + mapper.ToDictionary(transmission)["metadata"] + .CastAs>()[key].ShouldEqual(value); + } + [Test] public void do_not_include_empty_metadata() { @@ -323,14 +334,18 @@ public void Setup() private Transmission transmission; private DataMapper mapper; - [Test] - public void It_should_set_the_CC_Header_for_the_cc_emails() + [TestCase(true)] + [TestCase(false)] + public void It_should_set_the_CC_Header_for_only_the_cc_emails(bool useTo) { var recipient1 = new Recipient {Type = RecipientType.CC, Address = new Address {Email = Guid.NewGuid().ToString()}}; - var recipient2 = new Recipient {Type = RecipientType.To, Address = new Address {Email = Guid.NewGuid().ToString()}}; + var recipient2 = new Recipient {Type = RecipientType.BCC, Address = new Address { Email = Guid.NewGuid().ToString()}}; var recipient3 = new Recipient {Type = RecipientType.CC, Address = new Address {Email = Guid.NewGuid().ToString()}}; + var recipient4 = useTo + ? new Recipient { Type = RecipientType.To, Address = new Address { Email = Guid.NewGuid().ToString() } } + : new Recipient(); - transmission.Recipients = new List {recipient1, recipient2, recipient3}; + transmission.Recipients = new List {recipient1, recipient2, recipient3, recipient4}; var cc = mapper.ToDictionary(transmission) ["content"] @@ -339,17 +354,21 @@ public void It_should_set_the_CC_Header_for_the_cc_emails() .CastAs>() ["CC"]; - cc.ShouldEqual("<" + recipient1.Address.Email + ">,<" + recipient3.Address.Email + ">"); + cc.ShouldEqual(recipient1.Address.Email + ", " + recipient3.Address.Email); } - - [Test] - public void It_should_not_overwrite_any_existing_headers() + + [TestCase(true)] + [TestCase(false)] + public void It_should_not_overwrite_any_existing_headers(bool useTo) { var key = Guid.NewGuid().ToString(); var value = Guid.NewGuid().ToString(); var recipient1 = new Recipient {Type = RecipientType.CC, Address = new Address {Email = Guid.NewGuid().ToString()}}; - transmission.Recipients = new List {recipient1}; + var recipient2 = useTo + ? new Recipient { Type = RecipientType.To, Address = new Address() } + : new Recipient(); + transmission.Recipients = new List {recipient1, recipient2}; transmission.Content.Headers[key] = value; @@ -361,15 +380,19 @@ public void It_should_not_overwrite_any_existing_headers() [key].ShouldEqual(value); } - [Test] - public void It_should_not_set_the_cc_if_there_are_no_cc_emails() + [TestCase(true)] + [TestCase(false)] + public void It_should_not_set_the_cc_if_there_are_no_cc_emails(bool useTo) { var key = Guid.NewGuid().ToString(); var value = Guid.NewGuid().ToString(); - var recipient1 = new Recipient {Type = RecipientType.To, Address = new Address {Email = Guid.NewGuid().ToString()}}; + var recipient1 = useTo + ? new Recipient { Type = RecipientType.To, Address = new Address { Email = Guid.NewGuid().ToString() } } + : new Recipient(); var recipient2 = new Recipient {Type = RecipientType.BCC, Address = new Address {Email = Guid.NewGuid().ToString()}}; - transmission.Recipients = new List {recipient1, recipient2}; + var recipient3 = new Recipient { Type = RecipientType.BCC, Address = new Address { Email = Guid.NewGuid().ToString() } }; + transmission.Recipients = new List {recipient1, recipient2, recipient3}; transmission.Content.Headers[key] = value; @@ -382,10 +405,13 @@ public void It_should_not_set_the_cc_if_there_are_no_cc_emails() .ShouldBeFalse(); } - [Test] - public void It_should_not_set_a_header_value_if_there_are_no_ccs() + [TestCase(true)] + [TestCase(false)] + public void It_should_not_set_a_header_value_if_there_are_no_ccs(bool useTo) { - var recipient1 = new Recipient {Type = RecipientType.To, Address = new Address {Email = Guid.NewGuid().ToString()}}; + var recipient1 = useTo + ? new Recipient { Type = RecipientType.To, Address = new Address { Email = Guid.NewGuid().ToString() } } + : new Recipient(); var recipient2 = new Recipient {Type = RecipientType.BCC, Address = new Address {Email = Guid.NewGuid().ToString()}}; transmission.Recipients = new List {recipient1, recipient2}; @@ -396,13 +422,17 @@ public void It_should_not_set_a_header_value_if_there_are_no_ccs() .ShouldBeFalse(); } - [Test] - public void It_should_ignore_empty_ccs() + [TestCase(true)] + [TestCase(false)] + public void It_should_ignore_empty_ccs(bool useTo) { var recipient1 = new Recipient {Type = RecipientType.CC, Address = new Address {Email = ""}}; var recipient2 = new Recipient {Type = RecipientType.CC, Address = new Address {Email = null}}; var recipient3 = new Recipient {Type = RecipientType.CC, Address = new Address {Email = " "}}; - transmission.Recipients = new List {recipient1, recipient2, recipient3}; + var toRecipient = useTo + ? new Recipient { Type = RecipientType.To, Address = new Address() } + : new Recipient(); + transmission.Recipients = new List {recipient1, recipient2, recipient3, toRecipient}; mapper.ToDictionary(transmission) ["content"] @@ -411,11 +441,15 @@ public void It_should_ignore_empty_ccs() .ShouldBeFalse(); } - [Test] - public void It_should_ignore_any_cc_recipients_with_no_address() + [TestCase(true)] + [TestCase(false)] + public void It_should_ignore_any_cc_recipients_with_no_address(bool useTo) { var recipient1 = new Recipient {Type = RecipientType.CC, Address = null}; - transmission.Recipients = new List {recipient1}; + var toRecipient = useTo + ? new Recipient { Type = RecipientType.To, Address = new Address() } + : new Recipient(); + transmission.Recipients = new List {recipient1, toRecipient}; mapper.ToDictionary(transmission) ["content"] @@ -424,6 +458,108 @@ public void It_should_ignore_any_cc_recipients_with_no_address() .ShouldBeFalse(); } + [Test] + public void It_should_set_the_name_and_header_to_fields() + { + var toName = Guid.NewGuid().ToString(); + var toEmail = Guid.NewGuid().ToString(); + + var toRecipient = new Recipient { Type = RecipientType.To, Address = new Address(toEmail, toName) }; + var ccRecipient = new Recipient { Type = RecipientType.CC, Address = new Address() }; + var bccRecipient = new Recipient { Type = RecipientType.BCC, Address = new Address() }; + transmission.Recipients = new List() { toRecipient, ccRecipient, bccRecipient }; + + var addresses = mapper.ToDictionary(transmission) + ["recipients"] + .CastAs>>() + .Select(r => r["address"]) + .Cast>(); + + foreach (var address in addresses) + { + address["name"].ShouldEqual(toName); + address["header_to"].ShouldEqual(toEmail); + } + } + + [TestCase("Bob Jones", "bob@jones.com", "Bob Jones ")] + [TestCase(null, "bob@jones.com", "bob@jones.com")] + [TestCase("", "bob@jones.com", "bob@jones.com")] + [TestCase("Jones, Bob", "bob@jones.com", "\"Jones, Bob\" ")] + public void It_should_format_addresses_correctly(string name, string address, string result) + { + var recipient1 = new Recipient { Type = RecipientType.To, Address = new Address() }; + var recipient2 = new Recipient { Type = RecipientType.CC, Address = new Address(address, name) }; + transmission.Recipients = new List { recipient1, recipient2 }; + + mapper.ToDictionary(transmission) + ["content"] + .CastAs>() + ["headers"] + .CastAs>() + ["CC"] + .ShouldEqual(result); + } + + [TestCase("Jones, Bob", "bob@jones.com ", "\"Jones, Bob\" ")] + [TestCase("Jones, Bob", " bob@jones.com", "\"Jones, Bob\" ")] + public void It_should_handle_white_space_in_the_email(string name, string address, string result) + { + var recipient1 = new Recipient { Type = RecipientType.To, Address = new Address() }; + var recipient2 = new Recipient { Type = RecipientType.CC, Address = new Address(address, name) }; + transmission.Recipients = new List { recipient1, recipient2 }; + + mapper.ToDictionary(transmission) + ["content"] + .CastAs>() + ["headers"] + .CastAs>() + ["CC"] + .ShouldEqual(result); + } + + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void It_should_use_new_or_legacy_handling(int numOfTos) + { + var ccAddress = Guid.NewGuid().ToString(); + transmission.Recipients.Add(new Recipient { Type = RecipientType.CC, Address = new Address(ccAddress) }); + + for (int i = 0; i < numOfTos; ++i) + { + transmission.Recipients.Add(new Recipient { Type = RecipientType.To, Address = new Address("bob@example.com") }); + } + + var ccHeader = mapper.ToDictionary(transmission) + ["content"] + .CastAs>() + ["headers"] + .CastAs>() + ["CC"]; + + if (numOfTos == 1) + ccHeader.ShouldEqual(ccAddress); + else + ccHeader.ShouldEqual($"<{ccAddress}>"); + } + + [Test] + public void It_should_use_legacy_handling_if_to_address_is_null() + { + var ccAddress = Guid.NewGuid().ToString(); + transmission.Recipients.Add(new Recipient { Type = RecipientType.CC, Address = new Address(ccAddress) }); + transmission.Recipients.Add(new Recipient { Type = RecipientType.To, Address = null }); + + var ccHeader = mapper.ToDictionary(transmission) + ["content"] + .CastAs>() + ["headers"] + .CastAs>() + ["CC"]; + + ccHeader.ShouldEqual($"<{ccAddress}>"); + } } [TestFixture] @@ -872,5 +1008,304 @@ public void ComplianceStatus() dataMapper.ToDictionary(subaccount)["compliance_status"].ShouldEqual(subaccount.ComplianceStatus); } } + + [TestFixture] + public class AnythingTests + { + [Test] + public void It_should_map_anything_using_our_conventions() + { + var dataMapper = new DataMapper(); + + var dateTime = new DateTime(2016, 1, 2, 3, 4, 5); + + var result = dataMapper.CatchAll(new {FirstName = "Test1", LastName = "Test2", TheDate = dateTime}); + + result["first_name"].ShouldEqual("Test1"); + result["last_name"].ShouldEqual("Test2"); + ((string)result["the_date"]).Substring(0, 16).ShouldEqual("2016-01-02T03:04"); + } + } + + [TestFixture] + public class RelayWebhookTests + { + [SetUp] + public void Setup() + { + relayWebhook = new RelayWebhook(); + mapper = new DataMapper("v1"); + } + + private RelayWebhook relayWebhook; + private DataMapper mapper; + + [Test] + public void name() + { + var value = Guid.NewGuid().ToString(); + relayWebhook.Name = value; + mapper.ToDictionary(relayWebhook)["name"].ShouldEqual(value); + } + + [Test] + public void match_domain() + { + var value = Guid.NewGuid().ToString(); + relayWebhook.Match = new RelayWebhookMatch {Domain = value}; + mapper.ToDictionary(relayWebhook)["match"] + .CastAs>() + ["domain"].ShouldEqual(value); + } + + [Test] + public void match_protocol() + { + var value = Guid.NewGuid().ToString(); + relayWebhook.Match = new RelayWebhookMatch {Protocol = value}; + mapper.ToDictionary(relayWebhook)["match"] + .CastAs>() + ["protocol"].ShouldEqual(value); + } + } + + [TestFixture] + public class SendingDomainTests + { + private DataMapper mapper; + private SendingDomain sendingDomain; + + [SetUp] + public void Setup() + { + sendingDomain = new SendingDomain(); + mapper = new DataMapper("v1"); + } + + [Test] + public void Matches_on_status() + { + sendingDomain.Status = new SendingDomainStatus(); + sendingDomain.Status.DkimStatus = DkimStatus.Pending; + mapper.ToDictionary(sendingDomain)["status"] + .CastAs>() + ["dkim_status"] + .CastAs() + .ShouldEqual("pending"); + } + + [Test] + public void Null_status_return_null() + { + sendingDomain.Status = null; + var dictionary = mapper.ToDictionary(sendingDomain); + dictionary + .ContainsKey("status") + .ShouldBeFalse(); + } + + [Test] + public void Matches_on_dkim() + { + var publicKey = Guid.NewGuid().ToString(); + sendingDomain.Dkim = new Dkim { PublicKey = publicKey }; + mapper.ToDictionary(sendingDomain)["dkim"] + .CastAs>() + ["public_key"] + .CastAs() + .ShouldEqual(publicKey); + } + + [Test] + public void Null_dkim_is_is_not_returned() + { + sendingDomain.Dkim = null; + mapper.ToDictionary(sendingDomain) + .ContainsKey("dkim") + .ShouldBeFalse(); + } + } + + [TestFixture] + public class MetricsQueryTests + { + private DataMapper _mapper; + private MetricsQuery _query; + private string _timeFormat = "yyyy-MM-ddTHH:mm"; + + [SetUp] + public void Setup() + { + _query = new MetricsQuery(); + _mapper = new DataMapper("v1"); + } + + [Test] + public void from() + { + var from = DateTime.Parse("2013-11-29 14:26"); + _query.From = from; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["from"].CastTo(), Is.EqualTo(from.ToString(_timeFormat))); + } + + [Test] + public void to() + { + var to = DateTime.Parse("2003-08-13 12:15"); + _query.To = to; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["to"].CastTo(), Is.EqualTo(to.ToString(_timeFormat))); + } + + [Test] + public void timezone() + { + var tz = Guid.NewGuid().ToString(); + _query.Timezone = tz; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["timezone"].CastTo(), Is.EqualTo(tz)); + } + + [Test] + public void precision() + { + var p = Guid.NewGuid().ToString(); + _query.Precision = p; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["precision"].CastTo(), Is.EqualTo(p)); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void campaigns(params string[] list) + { + _query.Campaigns = list; + CheckList(list, "campaigns"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void domains(params string[] list) + { + _query.Domains = list; + CheckList(list, "domains"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void templates(params string[] list) + { + _query.Templates = list; + CheckList(list, "templates"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void sendingips(params string[] list) + { + _query.SendingIps = list; + CheckList(list, "sending_ips"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void ippools(params string[] list) + { + _query.IpPools = list; + CheckList(list, "ip_pools"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void sendingdomains(params string[] list) + { + _query.SendingDomains = list; + CheckList(list, "sending_domains"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void subaccounts(params string[] list) + { + _query.Subaccounts = list; + CheckList(list, "subaccounts"); + } + + [TestCase("apple")] + [TestCase("apple", "banana", "carrot")] + public void metrics(params string[] list) + { + _query.Metrics = list; + CheckList(list, "metrics"); + } + + private void CheckList(IList list, string k) + { + var cat = String.Join(",", list); + var dict = _mapper.CatchAll(_query); + Assert.That(dict[k].CastTo(), Is.EqualTo(cat)); + } + } + + [TestFixture] + public class MetricsResourceQueryTests + { + private DataMapper _mapper; + private MetricsResourceQuery _query; + private string _timeFormat = "yyyy-MM-ddTHH:mm"; + + [SetUp] + public void Setup() + { + _query = new MetricsResourceQuery(); + _mapper = new DataMapper("v1"); + } + + [Test] + public void from() + { + var from = DateTime.Parse("2013-11-29 14:26"); + _query.From = from; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["from"].CastTo(), Is.EqualTo(from.ToString(_timeFormat))); + } + + [Test] + public void to() + { + var to = DateTime.Parse("2003-08-13 12:15"); + _query.To = to; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["to"].CastTo(), Is.EqualTo(to.ToString(_timeFormat))); + } + + [Test] + public void timezone() + { + var tz = Guid.NewGuid().ToString(); + _query.Timezone = tz; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["timezone"].CastTo(), Is.EqualTo(tz)); + } + + [Test] + public void match() + { + var p = Guid.NewGuid().ToString(); + _query.Match = p; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["match"].CastTo(), Is.EqualTo(p)); + } + + [Test] + public void limit() + { + var r = new Random().Next(); + _query.Limit = r; + var dict = _mapper.CatchAll(_query); + Assert.That(dict["limit"].CastTo(), Is.EqualTo(r)); + } + } } } \ No newline at end of file diff --git a/src/SparkPost.Tests/FileTests.cs b/src/SparkPost.Tests/FileTests.cs new file mode 100644 index 00000000..a1ceed91 --- /dev/null +++ b/src/SparkPost.Tests/FileTests.cs @@ -0,0 +1,53 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SparkPost.Tests +{ + [TestFixture] + public class FileTests + { + [Test] + public void It_should_create_correct_type() + { + byte[] content = null; + Assert.That(File.Create(content), Is.InstanceOf()); + Assert.That(File.Create(content), Is.InstanceOf()); + } + + [TestCase("This is some test data.")] + [TestCase("This is some other data.")] + public void It_should_encode_data_correctly(string s) + { + var b = GetBytes(s); + var attach = File.Create(b); + Assert.That(attach.Data, Is.EqualTo(EncodeString(s))); + } + + [TestCase("foo.png", "image/png")] + [TestCase("foo.txt", "text/plain")] + [TestCase("sf", "application/octet-stream")] + [TestCase("", "application/octet-stream")] + public void It_should_set_name_and_type_correctly(string filename, string mimeType) + { + var b = GetBytes("Some Test Data"); + var attach = File.Create(b, filename); + Assert.That(attach.Name, Is.EqualTo(filename)); + Assert.That(attach.Type, Is.EqualTo(mimeType)); + } + + private byte[] GetBytes(string input) + { + return Encoding.ASCII.GetBytes(input); + } + + private string EncodeString(string input) + { + return Convert.ToBase64String(GetBytes(input)); + } + + } +} diff --git a/src/SparkPost.Tests/MessageEventsQueryTests.cs b/src/SparkPost.Tests/MessageEventsQueryTests.cs new file mode 100644 index 00000000..9c3186ab --- /dev/null +++ b/src/SparkPost.Tests/MessageEventsQueryTests.cs @@ -0,0 +1,61 @@ +using NUnit.Framework; +using Should; + +namespace SparkPost.Tests +{ + public class MessageEventsQueryTests + { + [TestFixture] + public class Defaults + { + [Test] + public void It_should_have_a_default_build_list() + { + new MessageEventsQuery().BounceClasses.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_defualt_campaign_ids_list() + { + new MessageEventsQuery().CampaignIds.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_default_friendly_froms_list() + { + new MessageEventsQuery().FriendlyFroms.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_default_message_ids_list() + { + new MessageEventsQuery().MessageIds.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_recipients_list() + { + new MessageEventsQuery().Recipients.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_a_Subaccounts_list() + { + new MessageEventsQuery().Subaccounts.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_TemplateIds_list() + { + new MessageEventsQuery().TemplateIds.ShouldNotBeNull(); + } + + [Test] + public void It_should_have_Transmissions_list() + { + new MessageEventsQuery().TransmissionIds.ShouldNotBeNull(); + } + + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Tests/MetricsQueryTests.cs b/src/SparkPost.Tests/MetricsQueryTests.cs new file mode 100644 index 00000000..2e841daf --- /dev/null +++ b/src/SparkPost.Tests/MetricsQueryTests.cs @@ -0,0 +1,51 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SparkPost.Tests +{ + [TestFixture] + public class MetricsQueryTests + { + private MetricsQuery _query; + + [SetUp] + public void Setup() + { + _query = new MetricsQuery(); + } + + private void Check(IList list) + { + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.Empty); + } + + [Test] + public void It_should_have_a_default_campaigns_list() => Check(_query.Campaigns); + + [Test] + public void It_should_have_a_default_domains_list() => Check(_query.Domains); + + [Test] + public void It_should_have_a_default_metrics_list() => Check(_query.Metrics); + + [Test] + public void It_should_have_a_default_templates_list() => Check(_query.Templates); + + [Test] + public void It_should_have_a_default_sending_ips_list() => Check(_query.SendingIps); + + [Test] + public void It_should_have_a_default_ip_pools_list() => Check(_query.IpPools); + + [Test] + public void It_should_have_a_default_sending_domains_list() => Check(_query.SendingDomains); + + [Test] + public void It_should_have_a_default_subaccounts_list() => Check(_query.Subaccounts); + } +} diff --git a/src/SparkPost.Tests/RelayWebhookTests.cs b/src/SparkPost.Tests/RelayWebhookTests.cs new file mode 100644 index 00000000..710e8585 --- /dev/null +++ b/src/SparkPost.Tests/RelayWebhookTests.cs @@ -0,0 +1,24 @@ +using NUnit.Framework; +using Should; + +namespace SparkPost.Tests +{ + public class RelayWebhookTests + { + [TestFixture] + public class DefaultTests + { + [Test] + public void It_should_initialize_match() + { + (new RelayWebhook()).Match.ShouldNotBeNull(); + } + + [Test] + public void It_should_initialize_match_protocol() + { + (new RelayWebhook()).Match.Protocol.ShouldEqual("SMTP"); + } + } + } +} \ No newline at end of file diff --git a/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs b/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs index a7f43522..ba50ece3 100644 --- a/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs +++ b/src/SparkPost.Tests/RequestSenders/AsyncRequestSenderTests.cs @@ -131,7 +131,7 @@ public class AsyncTesting : AsyncRequestSender { private Func responseBuilder; - public AsyncTesting(IClient client) : base(client) + public AsyncTesting(IClient client) : base(client, null) { } diff --git a/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs b/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs index ecdba772..95296398 100644 --- a/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs +++ b/src/SparkPost.Tests/RequestSenders/RequestSenderTests.cs @@ -22,7 +22,7 @@ public void Setup() request = new Request(); - async = new Mock(null); + async = new Mock(null, null); sync = new Mock(null); Mocker.SetInstance(client); diff --git a/src/SparkPost.Tests/SparkPost.Tests.csproj b/src/SparkPost.Tests/SparkPost.Tests.csproj index 86fd49f1..5a2d99f7 100644 --- a/src/SparkPost.Tests/SparkPost.Tests.csproj +++ b/src/SparkPost.Tests/SparkPost.Tests.csproj @@ -67,10 +67,26 @@ False ..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll + False + + + ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll + False + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll True + + ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll + False + + + ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll + False + ..\packages\Should.1.1.20\lib\Should.dll True @@ -87,7 +103,10 @@ + + + @@ -101,6 +120,7 @@ + @@ -116,7 +136,9 @@ - + + +