summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SendGrid/Example/Example.csproj5
-rw-r--r--SendGrid/Example/Program.cs47
-rw-r--r--SendGrid/Example/packages.config1
-rw-r--r--SendGrid/SendGrid.sln20
-rw-r--r--SendGrid/UnitTests/Properties/AssemblyInfo.cs36
-rw-r--r--SendGrid/UnitTests/SendGridTests.cs73
-rw-r--r--SendGrid/UnitTests/SendGridTests.csproj100
-rw-r--r--SendGrid/UnitTests/app.config11
-rw-r--r--SendGrid/UnitTests/packages.config4
9 files changed, 276 insertions, 21 deletions
diff --git a/SendGrid/Example/Example.csproj b/SendGrid/Example/Example.csproj
index 60bede7..786d6fb 100644
--- a/SendGrid/Example/Example.csproj
+++ b/SendGrid/Example/Example.csproj
@@ -45,6 +45,11 @@
</DefineConstants>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
<Reference Include="SendGrid.SmtpApi, Version=1.3.1.0, Culture=neutral, PublicKeyToken=2ae73662c35d80e4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SendGrid.SmtpApi.1.3.1\lib\net40\SendGrid.SmtpApi.dll</HintPath>
diff --git a/SendGrid/Example/Program.cs b/SendGrid/Example/Program.cs
index 3e222a1..57e59a0 100644
--- a/SendGrid/Example/Program.cs
+++ b/SendGrid/Example/Program.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Mail;
+using Newtonsoft.Json.Linq;
using SendGrid.Resources;
namespace Example
@@ -14,36 +15,40 @@ namespace Example
{
String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
var client = new SendGrid.Client(apiKey);
+ string _api_key_id;
// GET
- HttpResponseMessage response = client.ApiKeys.Get();
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ HttpResponseMessage responseGet = client.ApiKeys.Get();
+ Console.WriteLine(responseGet.StatusCode);
+ Console.WriteLine(responseGet.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("These are your current API Keys. Press any key to continue.");
Console.ReadKey();
-
+
// POST
- /*
- HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey5");
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ HttpResponseMessage responsePost = client.ApiKeys.Post("CSharpTestKey");
+ string rawString = responsePost.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ _api_key_id = jsonObject.api_key_id.ToString();
+ Console.WriteLine(responsePost.StatusCode);
+ Console.WriteLine(responsePost.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("API Key created. Press any key to continue.");
Console.ReadKey();
- */
- // DELETE
- /*
- HttpResponseMessage response = client.ApiKeys.Delete("<api_key_id>");
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ // PATCH
+ HttpResponseMessage responsePatch = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched");
+ Console.WriteLine(responsePatch.StatusCode);
+ Console.WriteLine(responsePatch.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("API Key patched. Press any key to continue.");
Console.ReadKey();
- */
- // PATCH
- /*
- HttpResponseMessage response = client.ApiKeys.Patch("<api_key_id>", "CSharpTestKey7");
- Console.WriteLine(response.StatusCode);
- Console.WriteLine(response.Content.ReadAsStringAsync().Result);
+ // DELETE
+ Console.WriteLine("Deleting API Key, please wait.");
+ client.ApiKeys.Delete(_api_key_id);
+ HttpResponseMessage responseFinal = client.ApiKeys.Get();
+ Console.WriteLine(responseFinal.StatusCode);
+ Console.WriteLine(responseFinal.Content.ReadAsStringAsync().Result);
+ Console.WriteLine("API Key Deleted, press any key to end");
Console.ReadKey();
- */
// SEND EMAIL
/*
diff --git a/SendGrid/Example/packages.config b/SendGrid/Example/packages.config
index 030933b..8aa9f7b 100644
--- a/SendGrid/Example/packages.config
+++ b/SendGrid/Example/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="SendGrid.SmtpApi" version="1.3.1" targetFramework="net45" />
</packages> \ No newline at end of file
diff --git a/SendGrid/SendGrid.sln b/SendGrid/SendGrid.sln
index 8e75d76..7b84ae9 100644
--- a/SendGrid/SendGrid.sln
+++ b/SendGrid/SendGrid.sln
@@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail", "SendGridMail\Mail.c
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendGrid", "SendGrid\SendGrid.csproj", "{1C318867-440B-4EB9-99E3-C0CC2C556962}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendGridTests", "UnitTests\SendGridTests.csproj", "{2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
BuildNet45|Any CPU = BuildNet45|Any CPU
@@ -94,6 +96,24 @@ Global
{1C318867-440B-4EB9-99E3-C0CC2C556962}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1C318867-440B-4EB9-99E3-C0CC2C556962}.Release|x86.ActiveCfg = Release|Any CPU
{1C318867-440B-4EB9-99E3-C0CC2C556962}.Release|x86.Build.0 = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.BuildNet45|Any CPU.ActiveCfg = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.BuildNet45|Any CPU.Build.0 = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.BuildNet45|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.BuildNet45|Mixed Platforms.Build.0 = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.BuildNet45|x86.ActiveCfg = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.BuildNet45|x86.Build.0 = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Debug|x86.Build.0 = Debug|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Release|x86.ActiveCfg = Release|Any CPU
+ {2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/SendGrid/UnitTests/Properties/AssemblyInfo.cs b/SendGrid/UnitTests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..74f470d
--- /dev/null
+++ b/SendGrid/UnitTests/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("UnitTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("UnitTests")]
+[assembly: AssemblyCopyright("Copyright © 2015")]
+[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("2be80f7d-ebb3-47f5-8ccb-b0f634d51849")]
+
+// 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/SendGrid/UnitTests/SendGridTests.cs b/SendGrid/UnitTests/SendGridTests.cs
new file mode 100644
index 0000000..a387935
--- /dev/null
+++ b/SendGrid/UnitTests/SendGridTests.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Net;
+using System.Net.Http;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Newtonsoft.Json.Linq;
+using SendGrid;
+
+namespace SendGridTests
+{
+ public class Base
+ {
+ static string _baseUri = "https://api.sendgrid.com/";
+ static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User);
+ public Client client = new Client(_apiKey, _baseUri);
+ }
+
+ [TestClass]
+ public class ApiKeys : Base
+ {
+ private static string _api_key_id = "";
+
+ [TestMethod]
+ public void ApiKeysIntegrationTest()
+ {
+ TestGet();
+ TestPost();
+ TestPatch();
+ TestDelete();
+ }
+
+ private void TestGet()
+ {
+ HttpResponseMessage response = client.ApiKeys.Get();
+ Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
+ string rawString = response.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ string jsonString = jsonObject.result.ToString();
+ Assert.IsNotNull(jsonString);
+ }
+
+ private void TestPost()
+ {
+ HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey");
+ Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
+ string rawString = response.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ string api_key = jsonObject.api_key.ToString();
+ _api_key_id = jsonObject.api_key_id.ToString();
+ string name = jsonObject.name.ToString();
+ Assert.IsNotNull(api_key);
+ Assert.IsNotNull(_api_key_id);
+ Assert.IsNotNull(name);
+ }
+
+ private void TestPatch()
+ {
+ HttpResponseMessage response = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched");
+ Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
+ string rawString = response.Content.ReadAsStringAsync().Result;
+ dynamic jsonObject = JObject.Parse(rawString);
+ _api_key_id = jsonObject.api_key_id.ToString();
+ string name = jsonObject.name.ToString();
+ Assert.IsNotNull(_api_key_id);
+ Assert.IsNotNull(name);
+ }
+
+ private void TestDelete()
+ {
+ HttpResponseMessage response = client.ApiKeys.Delete(_api_key_id);
+ Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
+ }
+ }
+}
diff --git a/SendGrid/UnitTests/SendGridTests.csproj b/SendGrid/UnitTests/SendGridTests.csproj
new file mode 100644
index 0000000..5eb0337
--- /dev/null
+++ b/SendGrid/UnitTests/SendGridTests.csproj
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{2BE80F7D-EBB3-47F5-8CCB-B0F634D51849}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>UnitTests</RootNamespace>
+ <AssemblyName>UnitTests</AssemblyName>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
+ <IsCodedUITest>False</IsCodedUITest>
+ <TestProjectType>UnitTest</TestProjectType>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Net" />
+ <Reference Include="System.Net.Http" />
+ </ItemGroup>
+ <Choose>
+ <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ </ItemGroup>
+ </When>
+ <Otherwise>
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
+ </ItemGroup>
+ </Otherwise>
+ </Choose>
+ <ItemGroup>
+ <Compile Include="SendGridTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\SendGrid\SendGrid.csproj">
+ <Project>{1c318867-440b-4eb9-99e3-c0cc2c556962}</Project>
+ <Name>SendGrid</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Choose>
+ <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+ <Private>False</Private>
+ </Reference>
+ </ItemGroup>
+ </When>
+ </Choose>
+ <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/SendGrid/UnitTests/app.config b/SendGrid/UnitTests/app.config
new file mode 100644
index 0000000..195db1f
--- /dev/null
+++ b/SendGrid/UnitTests/app.config
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
+ <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+</configuration> \ No newline at end of file
diff --git a/SendGrid/UnitTests/packages.config b/SendGrid/UnitTests/packages.config
new file mode 100644
index 0000000..64b5d8e
--- /dev/null
+++ b/SendGrid/UnitTests/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
+</packages> \ No newline at end of file