diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE new file mode 100644 index 000000000..87c0676c7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE @@ -0,0 +1,17 @@ +#### Issue Summary + +A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, code examples. + + +#### Steps to Reproduce + +1. This is the first step +2. This is the second step +3. Further steps, etc. + +Any other information you want to share that is relevant to the issue being reported. Especially, why do you consider this to be a bug? What do you expect to happen instead? + +#### Technical details: + +* sendgrid-csharp Version: master (latest commit: [commit number]) +* .NET Version: 4.5.2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 17ba00d00..bf1bcac12 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ SendGrid/packages/ SendGrid/TestResult.xml SendGrid/SendGrid.sln.VisualState.xml *.pfx -*.PublicKey \ No newline at end of file +*.PublicKey +SendGrid/.vs/config/applicationhost.config \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 44bc924cd..c7e643b34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,7 @@ install: - nuget restore SendGrid/SendGrid.sln - nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner script: -- xbuild /p:Configuration=BuildNet45 SendGrid/SendGrid.sln -- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe SendGrid/Tests/bin/BuildNet45/Tests.dll +- xbuild /p:Configuration=Release /p:DebugSymbols=False /p:TargetFrameworkVersion="v4.5" SendGrid/SendGrid.sln - mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe SendGrid/UnitTest/bin/Release/UnitTest.dll notifications: hipchat: diff --git a/CHANGELOG.md b/CHANGELOG.md index dd42d96f3..d1795ae47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,37 +1,43 @@ # Change Log All notable changes to this project will be documented in this file. +## [7.0.0] - 2016-06-13 +### Added +- Breaking change to support the v3 Web API +- New HTTP client +- v3 Mail Send helper + ## [6.3.4] - 2015-12-15 -###Added +### Added - Implemented the global stats /asm/stats endpoint [GET] ## [6.3.3] - 2015-12-14 -###Added +### Added - Implemented the global suppressions /asm/suppressions/global endpoint [GET, POST, DELETE] ## [6.3.2] - 2015-12-11 -###Added +### Added - Implemented the suppressions /asm/groups/:group_id/suppressions endpoint [GET, POST, DELETE] ## [6.3.1] - 2015-12-10 -###Added +### Added - Implemented the unsubscribe groups /asm/groups endpoint [GET, POST, DELETE] ## [6.3.0] - 2015-11-24 -###Added +### Added - Send emails using API Key ## [6.2.0] - 2015-11-18 -###Added +### Added - Added support for using the Web API v3 endpoints - Implemented the api_keys endpoint [GET, POST, PATCH, DELETE] ## [6.1.0] - 2015-4-27 -###Added +### Added - Added support for sending via API keys in addition to credentials. Pass an API Key string to the Web transport constructor ## [6.0.1] - 2015-4-24 -###Fixed +### Fixed - Fixed the endpoint URL. (⌒_⌒;) ## [6.0.0] - 2015-4-22 @@ -56,7 +62,6 @@ Deliver method. All other changes are backwards compatible. ### Fixed - Invalid Protocol Exception in Mono due to the way the endpoint URL was being assigned (thanks @mdymel, @rbarinov) - - Connections were not being reused. This was causing degraded performance with multiple threads open. Performance should be much better. (with help from @gatesvp) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..ee4c4acbe --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,179 @@ +Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies. + +- [CLAs and CCLAs](#cla) +- [Roadmap & Milestones](#roadmap) +- [Feature Request](#feature_request) +- [Submit a Bug Report](#submit_a_bug_report) +- [Improvements to the Codebase](#improvements_to_the_codebase) +- [Understanding the Code Base](#understanding_the_codebase) +- [Testing](#testing) +- [Style Guidelines & Naming Conventions](#style_guidelines_and_naming_conventions) +- [Creating a Pull Request](#creating_a_pull_request) + + +We use [Milestones](https://github.com/sendgrid/sendgrid-csharp/milestones) to help define current roadmaps, please feel free to grab an issue from the current milestone. Please indicate that you have begun work on it to avoid collisions. Once a PR is made, community review, comments, suggestions and additional PRs are welcomed and encouraged. + + +## CLAs and CCLAs + +Before you get started, SendGrid requires that a SendGrid Contributor License Agreement (CLA) or a SendGrid Company Contributor Licensing Agreement (CCLA) be filled out by every contributor to a SendGrid open source project. + +Our goal with the CLA and CCLA is to clarify the rights of our contributors and reduce other risks arising from inappropriate contributions. The CLA also clarifies the rights SendGrid holds in each contribution and helps to avoid misunderstandings over what rights each contributor is required to grant to SendGrid when making a contribution. In this way the CLA and CCLA encourage broad participation by our open source community and help us build strong open source projects, free from any individual contributor withholding or revoking rights to any contribution. + +SendGrid does not merge a pull request made against a SendGrid open source project until that pull request is associated with a signed CLA (or CCLA). Copies of the CLA and CCLA are available [here](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view). + +You may submit your completed [CLA or CCLA](https://drive.google.com/a/sendgrid.com/file/d/0B0PlcM9qA91LN2VEUTJWU2RIVXc/view) to SendGrid at [dx@sendgrid.com](mailto:dx@sendgrid.com). SendGrid will then confirm you are ready to begin making contributions. + +There are a few ways to contribute, which we'll enumerate below: + + +## Feature Request + +If you'd like to make a feature request, please read this section. + +The GitHub issue tracker is the preferred channel for library feature requests, but please respect the following restrictions: + +- Please **search for existing issues** in order to ensure we don't have duplicate bugs/feature requests. +- Please be respectful and considerate of others when commenting on issues + + +## Submit a Bug Report + +Note: DO NOT include your credentials in ANY code examples, descriptions, or media you make public. + +A software bug is a demonstrable issue in the code base. In order for us to diagnose the issue and respond as quickly as possible, please add as much detail as possible into your bug report. + +Before you decide to create a new issue, please try the following: + +1. Check the Github issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post. +2. Update to the latest version of this code and check if issue has already been fixed +3. Copy and fill in the Bug Report Template we have provided below + +### Please use our Bug Report Template + +In order to make the process easier, we've included a [sample bug report template](https://github.com/sendgrid/sendgrid-csharp/.github/ISSUE_TEMPLATE) (borrowed from [Ghost](https://github.com/TryGhost/Ghost/)). The template uses [GitHub flavored markdown](https://help.github.com/articles/github-flavored-markdown/) for formatting. + + +## Improvements to the Codebase + +We welcome direct contributions to the sendgrid-csharp code base. Thank you! + +### Development Environment ### + +#### Install and Run Locally #### + +##### Prerequisites ##### + +- .NET 4.5.2 +- [SendGrid.CSharp.HTTP.Client](https://www.nuget.org/packages/SendGrid.CSharp.HTTP.Client/) +- [Newtonsoft.Json](http://www.newtonsoft.com/json) + +##### Initial setup: ##### + +```bash +git clone https://github.com/sendgrid/sendgrid-csharp.git +``` + +Open `sendgrid-csharp/SendGrid/SendGrid.sln` + +## Environment Variables + +First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-csharp). + +Next, update your Environment (user space) with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys). + +##### Execute: ##### + +- Check out the documentation for [Web API v3 endpoints](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html). +- Review the corresponding [examples](https://github.com/sendgrid/sendgrid-csharp/blob/v3beta/examples). +- You can add your test code to our [Example Project](https://github.com/sendgrid/sendgrid-csharp/blob/v3beta/SendGrid/Example/Example.cs). + + +## Understanding the Code Base + +**/examples** + +Examples that demonstrate usage. + +**/Example/Example.cs** + +A working example project for testing. + +**/SendGrid/SendGrid.cs** + +The main interface to the SendGrid API is the class `SendGridAPIClient`. + +**/UnitTest** + +Unit tests + + +## Testing + +All PRs require passing tests before the PR will be reviewed. + +All test files are in the [`UnitTest`](https://github.com/sendgrid/sendgrid-csharp/tree/v3beta/SendGrid/UnitTest) directory. + +For the purposes of contributing to this repo, please update the [`UnitTest.cs`](https://github.com/sendgrid/sendgrid-csharp/tree/v3beta/test/SendGrid/UnitTest/UnitTest.cs) file with unit tests as you modify the code. + + + + +## Style Guidelines & Naming Conventions + +Generally, we follow the style guidelines as suggested by the official language. However, we ask that you conform to the styles that already exist in the library. If you wish to deviate, please explain your reasoning. In this case, we generally follow the [C# Naming Conventions](https://msdn.microsoft.com/library/ms229045(v=vs.100).aspx) and the suggestions provided by the Visual Studio IDE. + +## Creating a Pull Request + +1. [Fork](https://help.github.com/fork-a-repo/) the project, clone your fork, + and configure the remotes: + + ```bash + # Clone your fork of the repo into the current directory + git clone https://github.com/sendgrid/sendgrid-csharp + # Navigate to the newly cloned directory + cd sendgrid-python + # Assign the original repo to a remote called "upstream" + git remote add upstream https://github.com/sendgrid/sendgrid-csharp + ``` + +2. If you cloned a while ago, get the latest changes from upstream: + + ```bash + git checkout + git pull upstream + ``` + +3. Create a new topic branch (off the main project development branch) to + contain your feature, change, or fix: + + ```bash + git checkout -b + ``` + +4. Commit your changes in logical chunks. Please adhere to these [git commit + message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) + or your code is unlikely be merged into the main project. Use Git's + [interactive rebase](https://help.github.com/articles/interactive-rebase) + feature to tidy up your commits before making them public. + +4a. Create tests. + +4b. Create or update the example code that demonstrates the functionality of this change to the code. + +5. Locally merge (or rebase) the upstream development branch into your topic branch: + + ```bash + git pull [--rebase] upstream master + ``` + +6. Push your topic branch up to your fork: + + ```bash + git push origin + ``` + +7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/) + with a clear title and description against the `master` branch. All tests must be passing before we will review the PR. + +If you have any additional questions, please feel free to [email](mailto:dx@sendgrid.com) us or create an issue in this repo. \ No newline at end of file diff --git a/MIT.LICENSE b/LICENSE.txt similarity index 95% rename from MIT.LICENSE rename to LICENSE.txt index 585f8b37c..7f9d53708 100644 --- a/MIT.LICENSE +++ b/LICENSE.txt @@ -1,21 +1,21 @@ -The MIT License (MIT) - -Copyright (c) 2016 SendGrid - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +The MIT License (MIT) + +Copyright (c) 2012-2016 SendGrid, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index db53ba085..638008b91 100644 --- a/README.md +++ b/README.md @@ -1,366 +1,134 @@ -# Special Announcement +[![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-csharp.png?branch=master)](https://travis-ci.org/sendgrid/sendgrid-csharp) -We have released a [v3 beta branch](https://github.com/sendgrid/sendgrid-csharp/tree/v3beta) for this library that supports our new v3 Mail Send endpoint which is in open beta. The v3/mail/send/beta endpoint is not a production endpoint, so you should not integrate with it for your production email sending. However, when we make this an officially released feature it will be available at v3/mail//send. +**This library allows you to quickly and easily use the SendGrid Web API via C Sharp with .NET.** -Please try it out and let us know what you think about the endpoint and the library in the [issues area of this repo](https://github.com/sendgrid/sendgrid-csharp/issues), all of your feedback will be taken into account to influence the endpoint and this library. +# Announcements -Beginning with v3/mail/send/beta, the new version of our library will only support v3 endpoints.. Once this endpoint is out of beta, we will update the endpoint, removing the “/beta” from the URI. At this point, the v3 beta branch will be merged to master and will be our official library going forward. This means that we will no longer formally support the v2 mail.send.json endpoint in any of our libraries. +**BREAKING CHANGE as of 2016.06.14** -So long as you are not automatically pulling new versions of the library into your production code base, your integration will not break regardless of which endpoint you’re using. By the way, don't pull new versions into your production code base, because breaking changes break things. +Version `7.0.0` is a breaking change for the entire library. -The /api/mail.send.json endpoint, known as v2 mail send, is NOT going away. It will continue to work as it always has, happily sending your emails along as if nothing happened. +Version 7.0.0 brings you full support for all Web API v3 endpoints. We +have the following resources to get you started quickly: -[![BuildStatus](https://travis-ci.org/sendgrid/sendgrid-csharp.png?branch=master)](https://travis-ci.org/sendgrid/sendgrid-csharp) +- [SendGrid + Documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) +- [Usage + Documentation](https://github.com/sendgrid/sendgrid-csharp/tree/master/USAGE.md) +- [Example + Code](https://github.com/sendgrid/sendgrid-csharp/tree/master/Example) + +Thank you for your continued support! + +All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/sendgrid-csharp/blob/master/CHANGELOG.md). -See the [changelog](https://github.com/sendgrid/sendgrid-csharp/blob/master/CHANGELOG.md) for updates. +# Installation -#Requirements +## Setup Environment Variables -As of 4.0.0, this library requires .NET 4.5 and above. [Fork with .NET 4.0 support](https://www.nuget.org/packages/SendGrid.Net40/) +First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-csharp). -#Installation +Next, update your Environment (user space) with your [SENDGRID_API_KEY](https://app.sendgrid.com/settings/api_keys). + +## Install Package To use SendGrid in your C# project, you can either download the SendGrid C# .NET libraries directly from our Github repository or, if you have the NuGet package manager installed, you can grab them automatically. ``` -PM> Install-Package SendGrid +PM> Install-Package SendGrid ``` -Once you have the SendGrid libraries properly referenced in your project, you can include calls to them in your code. +Once you have the SendGrid libraries properly referenced in your project, you can include calls to them in your code. For a sample implementation, check the [Example](https://github.com/sendgrid/sendgrid-csharp/tree/master/SendGrid/Example) folder. Add the following namespaces to use the library: ```csharp using System; -using System.Net; -using System.Net.Mail; +using System.Web.Script.Serialization; using SendGrid; ``` -#How to: Create an email - -Use the static **new SendGridMessage** constructor to create an email message that is of type **SendGridMessage**. Once the message is created, you can use **SendGridMessage** properties and methods to set values including the email sender, the email recipient, and the subject and body of the email. - -The following example demonstrates how to create an email object and populate it: - -```csharp -// Create the email object first, then add the properties. -var myMessage = new SendGridMessage(); - -// Add the message properties. -myMessage.From = new MailAddress("john@example.com"); - -// Add multiple addresses to the To field. -List recipients = new List -{ - @"Jeff Smith ", - @"Anna Lidman ", - @"Peter Saddow " -}; - -myMessage.AddTo(recipients); - -myMessage.Subject = "Testing the SendGrid Library"; - -//Add the HTML and Text bodies -myMessage.Html = "

Hello World!

"; -myMessage.Text = "Hello World plain text!"; -``` - -#How to: Send an Email - -After creating an email message, you can send it using the Web API provided by SendGrid. - -Sending email requires that you supply your SendGrid account credentials (username and password) OR a SendGrid API Key. API Key is the preferred method. API Keys are in beta. To configure API keys, visit https://sendgrid.com/beta/settings/api_keys - -To send an email message, use the **DeliverAsync** method on the **Web** transport class, which calls the SendGrid Web API. The following example shows how to send a message. - -```csharp -// Create the email object first, then add the properties. -SendGridMessage myMessage = new SendGridMessage(); -myMessage.AddTo("anna@example.com"); -myMessage.From = new MailAddress("john@example.com", "John Smith"); -myMessage.Subject = "Testing the SendGrid Library"; -myMessage.Text = "Hello World!"; - -// Create a Web transport, using API Key -var transportWeb = new Web("This string is a SendGrid API key"); - -// Send the email. -transportWeb.DeliverAsync(myMessage); -// NOTE: If your developing a Console Application, use the following so that the API call has time to complete -// transportWeb.DeliverAsync(myMessage).Wait(); -``` - -#How to: Add an Attachment +## Dependencies -Attachments can be added to a message by calling the **AddAttachment** method and specifying the name and path of the file you want to attach, or by passing a stream. You can include multiple attachments by calling this method once for each file you wish to attach. The following example demonstrates adding an attachment to a message: +- The SendGrid Service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-csharp)) +- [SendGrid.CSharp.HTTP.Client](https://github.com/sendgrid/csharp-http-client) -```csharp -SendGridMessage myMessage = new SendGridMessage(); -myMessage.AddTo("anna@example.com"); -myMessage.From = new MailAddress("john@example.com", "John Smith"); -myMessage.Subject = "Testing the SendGrid Library"; -myMessage.Text = "Hello World!"; +# Quick Start -myMessage.AddAttachment(@"C:\file1.txt"); -``` - -You can also add attachments from the data's **Stream**. It can be done by calling the same method as above, **AddAttachment**, but by passing in the Stream of the data, and the filename you want it to show as in the message. +## Hello Email ```csharp -SendGridMessage myMessage = new SendGridMessage(); -myMessage.AddTo("anna@example.com"); -myMessage.From = new MailAddress("john@example.com", "John Smith"); -myMessage.Subject = "Testing the SendGrid Library"; -myMessage.Text = "Hello World!"; +using System; +using SendGrid; -using (var attachmentFileStream = new FileStream(@"C:\file.txt", FileMode.Open)) +namespace Example { - message.AddAttachment(attachmentFileStream, "My Cool File.txt"); + internal class Example + { + private static void Main() + { + String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); + dynamic sg = new SendGrid.SendGridAPIClient(apiKey); + + Email from = new Email("test@example.com"); + String subject = "Hello World from the SendGrid CSharp Library"; + Email to = new Email("test@example.com"); + Content content = new Content("text/plain", "Textual content"); + Mail mail = new Mail(from, subject, to, content); + + dynamic response = sg.client.mail.send.post(requestBody: mail.Get()); + } + } } ``` -#How to: Use filters to enable footers, tracking, analytics and templates - -SendGrid provides additional email functionality through the use of filters. These are settings that can be added to an email message to enable specific functionality such as click tracking, Google analytics, subscription tracking, and so on. For a full list of filters, see [Filter Settings](https://sendgrid.com/docs/API_Reference/SMTP_API/apps.html). - -Filters can be applied to **SendGrid** email messages using methods implemented as part of the **SendGrid** class. Before you can enable filters on an email message, you must first initialize the list of available filters by calling the **InitializeFilters** method. - -The following examples demonstrate the footer and click tracking filters: - -##Footer -```csharp -// Create the email object first, then add the properties. -SendGridMessage myMessage = new SendGridMessage(); -myMessage.AddTo("anna@example.com"); -myMessage.From = new MailAddress("john@example.com", "John Smith"); -myMessage.Subject = "Testing the SendGrid Library"; -myMessage.Text = "Hello World!"; - -// Add a footer to the message. -myMessage.EnableFooter("PLAIN TEXT FOOTER", "

HTML FOOTER

"); -``` - -##Click tracking -```csharp -// Create the email object first, then add the properties. -SendGridMessage myMessage = new SendGridMessage(); -myMessage.AddTo("anna@example.com"); -myMessage.From = new MailAddress("john@example.com", "John Smith"); -myMessage.Subject = "Testing the SendGrid Library"; -myMessage.Html = "

Hello World Link!

"; -myMessage.Text = "Hello World!"; - -// true indicates that links in plain text portions of the email -// should also be overwritten for link tracking purposes. -myMessage.EnableClickTracking(true); -``` - -##Template -```csharp -// Create the email object first, then add the properties. -SendGridMessage myMessage = new SendGridMessage(); -myMessage.AddTo("anna@example.com"); -myMessage.From = new MailAddress("john@example.com", "John Smith"); -myMessage.Subject = "Testing the SendGrid Library"; -myMessage.Text = "Hello World!"; - -// Enable template engine, you must send the template id - myMessage.EnableTemplateEngine("template id"); -``` - -#How to: Use the [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) - -Note: We have just begun to implement support for these endpoints and therefore only the following endpoints are currently supported. This functionality is located in the "SendGrid" project. - -## API Keys ## - -Please refer to [our documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html) for further details. - -List all API Keys belonging to the authenticated user [GET] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -// Leave off .Result for an asyncronous call -HttpResponseMessage responseGet = client.ApiKeys.Get().Result; -``` - -Generate a new API Key for the authenticated user [POST] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var apiKeyName = "CSharpTestKey"; -// Leave off .Result for an asyncronous call -HttpResponseMessage responsePost = client.ApiKeys.Post(apiKeyName).Result; -``` - -Update the name of an existing API Key [PATCH] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var apiKeyName = "CSharpTestKey"; -var apiKeyId = ""; -// Leave off .Result for an asyncronous call -HttpResponseMessage responsePatch = client.ApiKeys.Patch(apiKeyId, apiKeyName).Result; -``` - -Revoke an existing API Key [DELETE] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var apiKeyId = ""; -// Leave off .Result for an asyncronous call -HttpResponseMessage responseDelete = client.ApiKeys.Delete(apiKeyId).Result; -``` - -## Unsubscribe Groups ## - -Please refer to [our documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/groups.html) for further details. - -Retrieve all suppression groups associated with the user. [GET] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -// Leave off .Result for an asyncronous call -HttpResponseMessage responseGet = client.ApiKeys.Get().Result; -``` - -Get information on a single suppression group. [GET] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -// Leave off .Result for an asyncronous call -HttpResponseMessage responseGet = client.UnsubscribeGroups.Get().Result; -``` - -Create a new suppression group. [POST] - -There is a limit of 25 groups per user. - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var unsubscribeGroupName = "CSharpTestUnsubscribeGroup"; -var unsubscribeGroupDescription = "CSharp test Unsubscribe Group description."; -var unsubscribeGroupIsDefault = false; -// Leave off .Result for an asyncronous call -HttpResponseMessage responsePost = client.UnsubscribeGroups.Post(unsubscribeGroupName, unsubscribeGroupDescription, unsubscribeGroupIsDefault ).Result; -``` - -Delete a suppression group. [DELETE] - -You can only delete groups that have not been attached to sent mail in the last 60 days. If a recipient uses the “one-click unsubscribe” option on an email associated with a deleted group, that recipient will be added to the global suppression list. +## General v3 Web API Usage ```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var unsubscribeGroupId = ""; -// Leave off .Result for an asyncronous call -HttpResponseMessage responseDelete = client.UnsubscribeGroups.Delete(unsubscribeGroupId).Result; -``` - -## Suppressions ## - -Please refer to [our documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/suppressions.html) for further details. - -Get suppressed addresses for a given group. [GET] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -// Leave off .Result for an asyncronous call -int groupId = ; -HttpResponseMessage responseGet = client.Suppressions.Get(groupId).Result; -``` - -Add recipient addresses to the suppressions list for a given group. [POST] - -If the group has been deleted, this request will add the address to the global suppression. - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -string[] emails = { "example@example.com", "example2@example.com" }; -// Leave off .Result for an asyncronous call -HttpResponseMessage responsePost = client.Suppressions.Post(groupID, emails).Result; -``` - -Delete a recipient email from the suppressions list for a group. [DELETE] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var groupId = ""; -// Leave off .Result for an asyncronous call -HttpResponseMessage responseDelete1 = client.Suppressions.Delete(groupId, "example@example.com").Result; -``` - -## Global Suppressions ## - -Please refer to [our documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Suppression_Management/global_suppressions.html) for further details. - -Check if a recipient address is in the global suppressions group. [GET] +using System; +using SendGrid; -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -// Leave off .Result for an asyncronous call -string email = "example@example.com"; -HttpResponseMessage responseGet = client.GlobalSuppressions.Get(email).Result; +namespace Example +{ + internal class Example + { + private static void Main() + { + String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); + dynamic sg = new SendGrid.SendGridAPIClient(apiKey); + dynamic response = sg.client.api_keys.get(queryParams: queryParams); + } + } +} ``` -Add recipient addresses to the global suppression group. [POST] +# Usage -If the group has been deleted, this request will add the address to the global suppression. +- [SendGrid Docs](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) +- [Usage Docs](https://github.com/sendgrid/sendgrid-csharp/tree/master/USAGE.md) +- [Example Code](https://github.com/sendgrid/sendgrid-csharp/tree/master/SendGrid/Example) +- [v3 Web API Mail Send Helper](https://github.com/sendgrid/sendgrid-csharp/tree/master/SendGrid/SendGrid/Helpers/Mail) -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -string[] emails = { "example@example.com", "example2@example.com" }; -// Leave off .Result for an asyncronous call -HttpResponseMessage responsePost = client.GlobalSuppressions.Post(emails).Result; -``` +## Roadmap -Delete a recipient email from the global suppressions group. [DELETE] +If you are intersted in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/sendgrid-csharp/milestones). We would love to hear your feedback. -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -string email = "example@example.com"; -// Leave off .Result for an asyncronous call -HttpResponseMessage responseDelete1 = client.GlobalSuppressions.Delete(email).Result; -``` - -## Global Stats ## +## How to Contribute -Please refer to [our documentation](https://sendgrid.com/docs/API_Reference/Web_API_v3/Stats/global.html) for further details. +We encourage contribution to our library, please see our [CONTRIBUTING](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md) guide for details. -Global Stats provide all of your user’s email statistics for a given date range. [GET] - -```csharp -String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); -var client = new SendGrid.Client(apiKey); -var startDate = "2015-11-01"; // required -var endDate = "2015-12-01"; -var aggregatedBy = "day"; // "week" or "month" are also options -// Leave off .Result for an asyncronous call -HttpResponseMessage responseGet = client.GlobalStats.Get(startDate, endDate, aggregatedBy).Result; -``` +Quick links: -#How to: Testing +- [Feature Request](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#feature_request) +- [Bug Reports](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#submit_a_bug_report) +- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#cla) +- [Improvements to the Codebase](https://github.com/sendgrid/sendgrid-csharp/tree/master/CONTRIBUTING.md#improvements_to_the_codebase) -* Load the solution (We have tested using the Visual Studio Community Edition) -* In the Test Explorer, click "Run All". Tests for the Mail Send v2 endpoint are in the "Tests" project, while the tests for the v3 endpoints are in the "UnitTests" project. Selecting "Run All" from the Test Explorer will run the tests in both projects. +# About -You can also test the code by building and running our "Example" project. It will run through the examples using an interactive console. You will need your API key to run the examples against your account. +sendgrid-csharp is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). -[SendGrid Documentation](http://www.sendgrid.com/docs) +sendgrid-csharp is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-csharp are trademarks of SendGrid, Inc. -This readme adapted from [How to Send Email Using SendGrid with Windows Azure](http://www.windowsazure.com/en-us/develop/net/how-to-guides/sendgrid-email-service/) +![SendGrid Logo] +(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png) diff --git a/SendGrid/Example/Example.cs b/SendGrid/Example/Example.cs new file mode 100644 index 000000000..5155e9d88 --- /dev/null +++ b/SendGrid/Example/Example.cs @@ -0,0 +1,329 @@ +using System; +using System.Collections.Generic; +using System.Web.Script.Serialization; +using SendGrid.Helpers.Mail; + +namespace Example +{ + internal class Example + { + private static void Main() + { + // v3 Mail Helper + HelloEmail(); // this will actually send an email + KitchenSink(); // this will only send an email if you set SandBox Mode to false + + // v3 Web API + ApiKeys(); + + } + + private static void HelloEmail() + { + String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); + dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com"); + + Email from = new Email("test@example.com"); + String subject = "Hello World from the SendGrid CSharp Library"; + Email to = new Email("test@example.com"); + Content content = new Content("text/plain", "Textual content"); + Mail mail = new Mail(from, subject, to, content); + Email email = new Email("test2@example.com"); + mail.Personalization[0].AddTo(email); + + String ret = mail.Get(); + + string requestBody = ret; + dynamic response = sg.client.mail.send.beta.post(requestBody: requestBody); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine(ret); + Console.ReadLine(); + + } + + private static void KitchenSink() + { + String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); + dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com"); + + Mail mail = new Mail(); + + Email email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + mail.From = email; + + mail.Subject = "Hello World from the SendGrid CSharp Library"; + + Personalization personalization = new Personalization(); + email = new Email(); + email.Name = "Example User"; + email.Address = "test1@example.com"; + personalization.AddTo(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test2@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test3@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test4@example.com"; + personalization.AddBcc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test5@example.com"; + personalization.AddBcc(email); + personalization.Subject = "Thank you for signing up, %name%"; + personalization.AddHeader("X-Test", "True"); + personalization.AddHeader("X-Mock", "True"); + personalization.AddSubstitution("%name%", "Example User"); + personalization.AddSubstitution("%city%", "Denver"); + personalization.AddCustomArgs("marketing", "false"); + personalization.AddCustomArgs("transactional", "true"); + personalization.SendAt = 1461775051; + mail.AddPersonalization(personalization); + + personalization = new Personalization(); + email = new Email(); + email.Name = "Example User"; + email.Address = "test1@example.com"; + personalization.AddTo(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test2@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test3@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test4@example.com"; + personalization.AddBcc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test5@example.com"; + personalization.AddBcc(email); + personalization.Subject = "Thank you for signing up, %name%"; + personalization.AddHeader("X-Test", "True"); + personalization.AddHeader("X-Mock", "True"); + personalization.AddSubstitution("%name%", "Example User"); + personalization.AddSubstitution("%city%", "Denver"); + personalization.AddCustomArgs("marketing", "false"); + personalization.AddCustomArgs("transactional", "true"); + personalization.SendAt = 1461775051; + mail.AddPersonalization(personalization); + + Content content = new Content(); + content.Type = "text/plain"; + content.Value = "Textual content"; + mail.AddContent(content); + content = new Content(); + content.Type = "text/html"; + content.Value = "HTML content"; + mail.AddContent(content); + content = new Content(); + content.Type = "text/calendar"; + content.Value = "Party Time!!"; + mail.AddContent(content); + + Attachment attachment = new Attachment(); + attachment.Content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"; + attachment.Type = "application/pdf"; + attachment.Filename = "balance_001.pdf"; + attachment.Disposition = "attachment"; + attachment.ContentId = "Balance Sheet"; + mail.AddAttachment(attachment); + + attachment = new Attachment(); + attachment.Content = "BwdW"; + attachment.Type = "image/png"; + attachment.Filename = "banner.png"; + attachment.Disposition = "inline"; + attachment.ContentId = "Banner"; + mail.AddAttachment(attachment); + + mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"; + + mail.AddHeader("X-Day", "Monday"); + mail.AddHeader("X-Month", "January"); + + mail.AddSection("%section1", "Substitution for Section 1 Tag"); + mail.AddSection("%section2", "Substitution for Section 2 Tag"); + + mail.AddCategory("customer"); + mail.AddCategory("vip"); + + mail.AddCustomArgs("campaign", "welcome"); + mail.AddCustomArgs("sequence", "2"); + + ASM asm = new ASM(); + asm.GroupId = 3; + List groups_to_display = new List() + { + 1, 4, 5 + }; + asm.GroupsToDisplay = groups_to_display; + mail.Asm = asm; + + mail.SendAt = 1461775051; + + mail.SetIpPoolId = "23"; + + // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) + // mail.BatchId = "some_batch_id"; + + MailSettings mailSettings = new MailSettings(); + BCCSettings bccSettings = new BCCSettings(); + bccSettings.Enable = true; + bccSettings.Email = "test@example.com"; + mailSettings.BccSettings = bccSettings; + BypassListManagement bypassListManagement = new BypassListManagement(); + bypassListManagement.Enable = true; + mailSettings.BypassListManagement = bypassListManagement; + FooterSettings footerSettings = new FooterSettings(); + footerSettings.Enable = true; + footerSettings.Text = "Some Footer Text"; + footerSettings.Html = "Some HTML Here"; + mailSettings.FooterSettings = footerSettings; + SandboxMode sandboxMode = new SandboxMode(); + sandboxMode.Enable = true; + mailSettings.SandboxMode = sandboxMode; + SpamCheck spamCheck = new SpamCheck(); + spamCheck.Enable = true; + spamCheck.Threshold = 1; + spamCheck.PostToUrl = "https://gotchya.example.com"; + mailSettings.SpamCheck = spamCheck; + mail.MailSettings = mailSettings; + + TrackingSettings trackingSettings = new TrackingSettings(); + ClickTracking clickTracking = new ClickTracking(); + clickTracking.Enable = true; + clickTracking.EnableText = false; + trackingSettings.ClickTracking = clickTracking; + OpenTracking openTracking = new OpenTracking(); + openTracking.Enable = true; + openTracking.SubstitutionTag = "Optional tag to replace with the open image in the body of the message"; + trackingSettings.OpenTracking = openTracking; + SubscriptionTracking subscriptionTracking = new SubscriptionTracking(); + subscriptionTracking.Enable = true; + subscriptionTracking.Text = "text to insert into the text/plain portion of the message"; + subscriptionTracking.Html = "HTML to insert into the text/html portion of the message"; + subscriptionTracking.SubstitutionTag = "text to insert into the text/plain portion of the message"; + trackingSettings.SubscriptionTracking = subscriptionTracking; + Ganalytics ganalytics = new Ganalytics(); + ganalytics.Enable = true; + ganalytics.UtmCampaign = "some campaign"; + ganalytics.UtmContent = "some content"; + ganalytics.UtmMedium = "some medium"; + ganalytics.UtmSource = "some source"; + ganalytics.UtmTerm = "some term"; + trackingSettings.Ganalytics = ganalytics; + mail.TrackingSettings = trackingSettings; + + email = new Email(); + email.Address = "test@example.com"; + mail.ReplyTo = email; + + String ret = mail.Get(); + + string requestBody = ret; + dynamic response = sg.client.mail.send.beta.post(requestBody: requestBody); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine(ret); + Console.ReadLine(); + } + + private static void ApiKeys() + { + String apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); + dynamic sg = new SendGrid.SendGridAPIClient(apiKey, "https://api.sendgrid.com"); + + string queryParams = @"{ + 'limit': 100 + }"; + dynamic response = sg.client.api_keys.get(queryParams: queryParams); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine("\n\nPress any key to continue to POST."); + Console.ReadLine(); + + // POST + string requestBody = @"{ + 'name': 'My API Key 5', + 'scopes': [ + 'mail.send', + 'alerts.create', + 'alerts.read' + ] + }"; + response = sg.client.api_keys.post(requestBody: requestBody); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + JavaScriptSerializer jss = new JavaScriptSerializer(); + var ds_response = jss.Deserialize>(response.Body.ReadAsStringAsync().Result); + string api_key_id = ds_response["api_key_id"]; + + Console.WriteLine("\n\nPress any key to continue to GET single."); + Console.ReadLine(); + + // GET Single + response = sg.client.api_keys._(api_key_id).get(); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine("\n\nPress any key to continue to PATCH."); + Console.ReadLine(); + + // PATCH + requestBody = @"{ + 'name': 'A New Hope' + }"; + response = sg.client.api_keys._(api_key_id).patch(requestBody: requestBody); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine("\n\nPress any key to continue to PUT."); + Console.ReadLine(); + + // PUT + requestBody = @"{ + 'name': 'A New Hope', + 'scopes': [ + ' user.profile.read', + ' user.profile.update' + ] + }"; + response = sg.client.api_keys._(api_key_id).put(requestBody: requestBody); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Body.ReadAsStringAsync().Result); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine("\n\nPress any key to continue to DELETE."); + Console.ReadLine(); + + // DELETE + response = sg.client.api_keys._(api_key_id).delete(); + Console.WriteLine(response.StatusCode); + Console.WriteLine(response.Headers.ToString()); + + Console.WriteLine("\n\nPress any key to exit."); + Console.ReadLine(); + + } + } +} diff --git a/SendGrid/Example/Example.csproj b/SendGrid/Example/Example.csproj index 786d6fb25..98044fa6b 100644 --- a/SendGrid/Example/Example.csproj +++ b/SendGrid/Example/Example.csproj @@ -1,5 +1,5 @@  - + Debug x86 @@ -8,7 +8,7 @@ Properties Example Example - v4.5 + v4.5.2 512 @@ -46,8 +46,12 @@ - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + True + + + ..\packages\SendGrid.CSharp.HTTP.Client.2.0.1\lib\SendGrid.CSharp.HTTP.Client.dll True @@ -61,9 +65,8 @@ - + - @@ -75,10 +78,6 @@ - - {3c687bef-ff50-44ad-8315-2d4237281af8} - Mail - {1c318867-440b-4eb9-99e3-c0cc2c556962} SendGrid @@ -87,7 +86,7 @@ - - \ No newline at end of file diff --git a/SendGrid/SendGridMail/Properties/AssemblyInfo.cs b/SendGrid/SendGridMail/Properties/AssemblyInfo.cs deleted file mode 100644 index 540b5e92e..000000000 --- a/SendGrid/SendGridMail/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,62 +0,0 @@ -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("SendGridMail")] -[assembly: AssemblyDescription("A client library for interfacing with the SendGridMessage API")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("SendGridMessage")] -[assembly: AssemblyProduct("SendGridMail")] -[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("193fa200-8430-4206-aacd-2d2bb2dfa6cf")] - -#if (BUILD) -[assembly: InternalsVisibleTo("Tests," + "" + - "PublicKey=0024000004800000940000000602000000240000525341310004000001000100812ec26a66c8e0" + - "8c790704ac4b46bcc9da9f4bca4da0ec7c06ce6dcd73baeb2c5525f36a237b253e80e16febb4c0" + - "52f50734d5e1cf3bf478d9c88f0f69df53b47306419182983bc35c33c3bafb5e90b9bd7aa7b9a9" + - "da09abe3667d50db891012e077e4b9aefe9799a58222fa67127c230219755d7670073c7463d90c" + - "f9e79dba")] -#elif (DEBUG) -[assembly: InternalsVisibleTo("Tests," + "" + - "PublicKey=0024000004800000940000000602000000240000525341310004000001000100812ec26a66c8e0" + - "8c790704ac4b46bcc9da9f4bca4da0ec7c06ce6dcd73baeb2c5525f36a237b253e80e16febb4c0" + - "52f50734d5e1cf3bf478d9c88f0f69df53b47306419182983bc35c33c3bafb5e90b9bd7aa7b9a9" + - "da09abe3667d50db891012e077e4b9aefe9799a58222fa67127c230219755d7670073c7463d90c" + - "f9e79dba")] -#else -[assembly: InternalsVisibleTo("Tests," + "" + - "PublicKey=0024000004800000940000000602000000240000525341310004000001000100812ec26a66c8e0" + - "8c790704ac4b46bcc9da9f4bca4da0ec7c06ce6dcd73baeb2c5525f36a237b253e80e16febb4c0" + - "52f50734d5e1cf3bf478d9c88f0f69df53b47306419182983bc35c33c3bafb5e90b9bd7aa7b9a9" + - "da09abe3667d50db891012e077e4b9aefe9799a58222fa67127c230219755d7670073c7463d90c" + - "f9e79dba")] -#endif -// 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("6.3.4")] -[assembly: AssemblyFileVersion("6.3.4")] \ No newline at end of file diff --git a/SendGrid/SendGridMail/SendGrid.cs b/SendGrid/SendGridMail/SendGrid.cs deleted file mode 100644 index 1581f40a8..000000000 --- a/SendGrid/SendGridMail/SendGrid.cs +++ /dev/null @@ -1,550 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Net.Mail; -using System.Net.Mime; -using System.Text.RegularExpressions; -using SendGrid.SmtpApi; - -namespace SendGrid -{ - public class SendGridMessage : ISendGrid - { - #region constants/vars - - //apps list and settings - private static readonly Dictionary Filters = InitializeFilters(); - private readonly MailMessage _message; - private static readonly Regex TemplateTest = new Regex(@"<%\s*body\s*%>", RegexOptions.Compiled | RegexOptions.IgnoreCase); - private static readonly Regex TextUnsubscribeTest = new Regex(@"<%\s*%>", RegexOptions.Compiled); - private static readonly Regex HtmlUnsubscribeTest = new Regex(@"<%\s*([^\s%]+\s?)+\s*%>", RegexOptions.Compiled); - private const string SinkHost = "sink.sendgrid.net"; - - #endregion - - #region Initialization and Constructors - - /// - /// Creates an instance of SendGrid's custom message object - /// - /// - public SendGridMessage() : this(new Header()) - { - - } - - public SendGridMessage(IHeader header) - { - _message = new MailMessage(); - Header = header; - Headers = new Dictionary(); - } - - public SendGridMessage(MailAddress from, MailAddress[] to, - String subject, String html, String text, IHeader header = null) : this() - { - From = from; - To = to; - - _message.Subject = subject; - - Text = text; - Html = html; - } - - private static Dictionary InitializeFilters() - { - return - new Dictionary - { - {"Gravatar", "gravatar"}, - {"OpenTracking", "opentrack"}, - {"ClickTracking", "clicktrack"}, - {"SpamCheck", "spamcheck"}, - {"Unsubscribe", "subscriptiontrack"}, - {"Footer", "footer"}, - {"GoogleAnalytics", "ganalytics"}, - {"Template", "template"}, - {"Templates","templates"}, - {"Bcc", "bcc"}, - {"BypassListManagement", "bypass_list_management"} - }; - } - - #endregion - - #region Properties - - public MailAddress From - { - get { return _message.From; } - set { if (value != null) _message.From = value; } - } - - public MailAddress[] ReplyTo - { - get { return _message.ReplyToList.ToArray(); } - set - { - _message.ReplyToList.Clear(); - foreach (var replyTo in value) - { - _message.ReplyToList.Add(replyTo); - } - } - } - - public MailAddress[] To - { - get - { - if (_sendToSink) - { - return _message.To - .Select(ma => new MailAddress(string.Format("{0}_at_{1}@{2}", ma.User, ma.Host, SinkHost), ma.DisplayName)) - .ToArray(); - } - return _message.To.ToArray(); - } - set - { - _message.To.Clear(); - foreach (var mailAddress in value) - { - _message.To.Add(mailAddress); - } - } - } - - public MailAddress[] Cc - { - get { return _message.CC.ToArray(); } - set - { - _message.CC.Clear(); - foreach (var mailAddress in value) - { - _message.CC.Add(mailAddress); - } - } - } - - public MailAddress[] Bcc - { - get { return _message.Bcc.ToArray(); } - set - { - _message.Bcc.Clear(); - foreach (var mailAddress in value) - { - _message.Bcc.Add(mailAddress); - } - } - } - - public String Subject - { - get { return _message.Subject; } - set { if (value != null) _message.Subject = value; } - } - - public Dictionary Headers { get; set; } - public IHeader Header { get; set; } - public String Html { get; set; } - public String Text { get; set; } - - #endregion - - #region Methods for setting data - - private List _attachments = new List(); - private Dictionary _streamedAttachments = new Dictionary(); - private Dictionary _contentImages = new Dictionary(); - private bool _sendToSink; - - public void AddTo(String address) - { - var mailAddress = new MailAddress(address); - _message.To.Add(mailAddress); - } - - public void AddTo(IEnumerable addresses) - { - if (addresses == null) return; - - foreach (var address in addresses.Where(address => address != null)) - AddTo(address); - } - - public void AddTo(IDictionary> addresssInfo) - { - foreach (var mailAddress in from address in addresssInfo.Keys let table = addresssInfo[address] select new MailAddress(address, table.ContainsKey("DisplayName") ? table["DisplayName"] : null)) - { - _message.To.Add(mailAddress); - } - } - - public void AddCc(string address) - { - var mailAddress = new MailAddress(address); - _message.CC.Add(mailAddress); - } - - public void AddCc(MailAddress address) - { - _message.CC.Add(address); - } - - public void AddBcc(string address) - { - var mailAddress = new MailAddress(address); - _message.Bcc.Add(mailAddress); - } - - public void AddBcc(MailAddress address) - { - _message.Bcc.Add(address); - } - - public Dictionary StreamedAttachments - { - get { return _streamedAttachments; } - set { _streamedAttachments = value; } - } - - public String[] Attachments - { - get { return _attachments.ToArray(); } - set { _attachments = value.ToList(); } - } - - public void EmbedImage(String filename, String cid) { - _contentImages[filename] = cid; - } - - public IDictionary GetEmbeddedImages() { - return new Dictionary(_contentImages); - } - - public void AddSubstitution(String replacementTag, List substitutionValues) - { - //let the system complain if they do something bad, since the function returns null - Header.AddSubstitution(replacementTag, substitutionValues); - } - - public void AddSection(String replacementTag, String sectionValue) - { - Header.AddSection(replacementTag, sectionValue); - } - - public void AddUniqueArgs(IDictionary identifiers) - { - Header.AddUniqueArgs(identifiers); - } - - public void SetAsmGroupId(int id) - { - Header.SetAsmGroupId(id); - } - - public void SetIpPool(string pool) - { - Header.SetIpPool(pool); - } - - public void SetSendAt(DateTime sendTime) - { - Header.SetSendAt(sendTime); - } - - public void SetSendEachAt(IEnumerable sendTimes) - { - Header.SetSendEachAt(sendTimes); - } - - public void SetCategory(String category) - { - Header.SetCategory(category); - } - - public void SetCategories(IEnumerable categories) - { - Header.SetCategories(categories); - } - - public void AddAttachment(Stream stream, String name) - { - var ms = new MemoryStream(); - stream.CopyTo(ms); - ms.Seek(0, SeekOrigin.Begin); - StreamedAttachments[name] = ms; - } - - public void EmbedStreamImage(Stream stream, String name) - { - var ms = new MemoryStream(); - stream.CopyTo(ms); - ms.Seek(0, SeekOrigin.Begin); - StreamedAttachments[name] = ms; - - _contentImages[name] = name; - } - - public void AddAttachment(String filePath) - { - _attachments.Add(filePath); - } - - public IEnumerable GetRecipients() - { - var tos = _message.To.ToList(); - var ccs = _message.CC.ToList(); - var bccs = _message.Bcc.ToList(); - - var rcpts = tos.Union(ccs.Union(bccs)).Select(address => address.Address); - return rcpts; - } - - public void AddHeaders(IDictionary headers) - { - headers.Keys.ToList().ForEach(key => Headers[key] = headers[key]); - } - - public void SendToSink(bool value = true) - { - _sendToSink = value; - } - - #endregion - - #region SMTP API Functions - - public void DisableGravatar() - { - Header.DisableFilter(Filters["Gravatar"]); - } - - public void DisableOpenTracking() - { - Header.DisableFilter(Filters["OpenTracking"]); - } - - public void DisableClickTracking() - { - Header.DisableFilter(Filters["ClickTracking"]); - } - - public void DisableSpamCheck() - { - Header.DisableFilter(Filters["SpamCheck"]); - } - - public void DisableUnsubscribe() - { - Header.DisableFilter(Filters["Unsubscribe"]); - } - - public void DisableFooter() - { - Header.DisableFilter(Filters["Footer"]); - } - - public void DisableGoogleAnalytics() - { - Header.DisableFilter(Filters["GoogleAnalytics"]); - } - - public void DisableTemplate() - { - Header.DisableFilter(Filters["Template"]); - } - - public void DisableBcc() - { - Header.DisableFilter(Filters["Bcc"]); - } - - public void DisableBypassListManagement() - { - Header.DisableFilter(Filters["BypassListManagement"]); - } - - public void EnableGravatar() - { - Header.EnableFilter(Filters["Gravatar"]); - } - - public void EnableOpenTracking() - { - Header.EnableFilter(Filters["OpenTracking"]); - } - - public void EnableClickTracking(bool includePlainText = false) - { - var filter = Filters["ClickTracking"]; - - Header.EnableFilter(filter); - if (includePlainText) - { - Header.AddFilterSetting(filter, new List {"enable_text"}, "1"); - } - } - - public void EnableSpamCheck(int score = 5, string url = null) - { - var filter = Filters["SpamCheck"]; - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"maxscore"}, score.ToString(CultureInfo.InvariantCulture)); - Header.AddFilterSetting(filter, new List {"url"}, url); - } - - public void EnableUnsubscribe(string text, string html) - { - var filter = Filters["Unsubscribe"]; - - if (!TextUnsubscribeTest.IsMatch(text)) - { - throw new Exception("Missing substitution replacementTag in text"); - } - - if (!HtmlUnsubscribeTest.IsMatch(html)) - { - throw new Exception("Missing substitution replacementTag in html"); - } - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"text/plain"}, text); - Header.AddFilterSetting(filter, new List {"text/html"}, html); - } - - public void EnableUnsubscribe(string replace) - { - var filter = Filters["Unsubscribe"]; - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"replace"}, replace); - } - - public void EnableFooter(string text = null, string html = null) - { - var filter = Filters["Footer"]; - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"text/plain"}, text); - Header.AddFilterSetting(filter, new List {"text/html"}, html); - } - - public void EnableGoogleAnalytics(string source, string medium, string term, string content = null, - string campaign = null) - { - var filter = Filters["GoogleAnalytics"]; - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"utm_source"}, source); - Header.AddFilterSetting(filter, new List {"utm_medium"}, medium); - Header.AddFilterSetting(filter, new List {"utm_term"}, term); - Header.AddFilterSetting(filter, new List {"utm_content"}, content); - Header.AddFilterSetting(filter, new List {"utm_campaign"}, campaign); - } - - public void EnableTemplate(string html) - { - var filter = Filters["Template"]; - - if (!TemplateTest.IsMatch(html)) - { - throw new Exception("Missing <% body %> tag in template HTML"); - } - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"text/html"}, html); - } - - public void EnableTemplateEngine(string templateId) - { - var filter = Filters["Templates"]; - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List { "template_id" }, templateId); - } - - public void EnableBcc(string email) - { - var filter = Filters["Bcc"]; - - Header.EnableFilter(filter); - Header.AddFilterSetting(filter, new List {"email"}, email); - } - - public void EnableBypassListManagement() - { - Header.EnableFilter(Filters["BypassListManagement"]); - } - - #endregion - - public MailMessage CreateMimeMessage() - { - var smtpapi = Header.JsonString(); - - if (!String.IsNullOrEmpty(smtpapi)) - _message.Headers.Add("X-Smtpapi", smtpapi); - - Headers.Keys.ToList().ForEach(k => _message.Headers.Add(k, Headers[k])); - - _message.Attachments.Clear(); - _message.AlternateViews.Clear(); - - if (Attachments != null) - { - foreach (var attachment in Attachments) - { - _message.Attachments.Add(new Attachment(attachment, MediaTypeNames.Application.Octet)); - } - } - - if (StreamedAttachments != null) - { - foreach (var attachment in StreamedAttachments) - { - attachment.Value.Position = 0; - _message.Attachments.Add(new Attachment(attachment.Value, attachment.Key)); - } - } - - if (Text != null) - { - var plainView = AlternateView.CreateAlternateViewFromString(Text, null, "text/plain"); - _message.AlternateViews.Add(plainView); - } - - if (Html == null) return _message; - - var htmlView = AlternateView.CreateAlternateViewFromString(Html, null, "text/html"); - _message.AlternateViews.Add(htmlView); - - //message.SubjectEncoding = Encoding.GetEncoding(charset); - //message.BodyEncoding = Encoding.GetEncoding(charset); - - return _message; - } - - /// - /// Helper function lets us look at the mime before it is sent - /// - /// directory in which we store this mime message - internal void SaveMessage(String directory) - { - var client = new SmtpClient("localhost") - { - DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory, - PickupDirectoryLocation = @"C:\temp" - }; - var msg = CreateMimeMessage(); - client.Send(msg); - } - } -} \ No newline at end of file diff --git a/SendGrid/SendGridMail/SendGridMail.pfx b/SendGrid/SendGridMail/SendGridMail.pfx deleted file mode 100644 index 867e49967..000000000 Binary files a/SendGrid/SendGridMail/SendGridMail.pfx and /dev/null differ diff --git a/SendGrid/SendGridMail/StreamedFileBody.cs b/SendGrid/SendGridMail/StreamedFileBody.cs deleted file mode 100644 index 125fe240b..000000000 --- a/SendGrid/SendGridMail/StreamedFileBody.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace SendGridMail -{ - public class StreamedFileBody - { - private string _name; - private string _filename; - private byte[] _content; - - public StreamedFileBody(MemoryStream stream, String name) - { - if (stream == null) throw new ArgumentException("Invalid attachment stream"); - if (String.IsNullOrEmpty(name)) throw new ArgumentException("Invalid attachment name"); - - _name = "files[" + Path.GetFileName(name) + "]"; - _filename = name; - _content = stream.ToArray(); - } - - public byte[] GetContent(string boundry) - { - var bytes = new List(); - - string paramBoundry = "--" + boundry + "\r\n"; - string stringParam = "Content-Disposition: form-data; name=\"" + _name + "\"; filename=\"" + _filename + "\"\r\n"; - string paramEnd = "Content-Type: image/png\r\n\r\n"; - - bytes.AddRange(Encoding.ASCII.GetBytes(paramBoundry + stringParam + paramEnd)); - bytes.AddRange(_content); - bytes.AddRange(Encoding.ASCII.GetBytes("\r\n")); - return bytes.ToArray(); - } - } -} diff --git a/SendGrid/SendGridMail/Transport/ErrorChecker.cs b/SendGrid/SendGridMail/Transport/ErrorChecker.cs deleted file mode 100644 index 035d2b80c..000000000 --- a/SendGrid/SendGridMail/Transport/ErrorChecker.cs +++ /dev/null @@ -1,57 +0,0 @@ -namespace SendGrid -{ - using System; - using System.IO; - using System.Net; - using System.Net.Http; - using System.Threading.Tasks; - using System.Xml; - - using Exceptions; - - public static class ErrorChecker - { - public static void CheckForErrors(HttpResponseMessage response) - { - CheckForErrors(response, response.Content.ReadAsStreamAsync().Result); - } - - public static async Task CheckForErrorsAsync(HttpResponseMessage response) - { - CheckForErrors(response, await response.Content.ReadAsStreamAsync()); - } - - private static void CheckForErrors(HttpResponseMessage response, Stream stream) - { - if (response.StatusCode != HttpStatusCode.OK) - { - using (var reader = XmlReader.Create(stream)) - { - while (reader.Read()) - { - if (!reader.IsStartElement()) - { - continue; - } - - switch (reader.Name) - { - case "result": - continue; - case "message": - continue; - case "errors": - reader.ReadToFollowing("error"); - var message = reader.ReadElementContentAsString("error", reader.NamespaceURI); - throw new InvalidApiRequestException(response.StatusCode, new[] { message }, response.ReasonPhrase); - case "error": - throw new ProtocolViolationException(); - default: - throw new ArgumentException("Unknown element: " + reader.Name); - } - } - } - } - } - } -} \ No newline at end of file diff --git a/SendGrid/SendGridMail/Transport/ITransport.cs b/SendGrid/SendGridMail/Transport/ITransport.cs deleted file mode 100644 index 94a2d7f33..000000000 --- a/SendGrid/SendGridMail/Transport/ITransport.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Threading.Tasks; - - -namespace SendGrid -{ - /// - /// Encapsulates the transport mechanism so that it can be used in a generic way, - /// regardless of the transport type - /// - public interface ITransport - { - /// - /// Asynchronously delivers a message using the protocol of the derived class - /// - /// the message to be delivered - Task DeliverAsync(ISendGrid message); - } -} \ No newline at end of file diff --git a/SendGrid/SendGridMail/Transport/Web.cs b/SendGrid/SendGridMail/Transport/Web.cs deleted file mode 100644 index dbf5d28cb..000000000 --- a/SendGrid/SendGridMail/Transport/Web.cs +++ /dev/null @@ -1,186 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Reflection; -using System.Threading.Tasks; -using SendGrid.SmtpApi; - -// ReSharper disable MemberCanBePrivate.Global -namespace SendGrid -{ - public class Web : ITransport - { - #region Properties - - //TODO: Make this configurable - public const String Endpoint = "https://api.sendgrid.com/api/mail.send.xml"; - private readonly NetworkCredential _credentials; - private readonly HttpClient _client; - private readonly string _apiKey; - - #endregion - - /// - /// Creates a new Web interface for sending mail - /// - /// The API Key with which to send - public Web(string apiKey) - : this(apiKey, null, TimeSpan.FromSeconds(100)) { } - - /// - /// Creates a new Web interface for sending mail - /// - /// SendGridMessage user parameters - public Web(NetworkCredential credentials) - : this(null, credentials, TimeSpan.FromSeconds(100)) { } - - /// - /// Creates a new Web interface for sending mail. - /// - /// The API Key with which to send - /// SendGridMessage user parameters - /// HTTP request timeout - public Web(string apiKey, NetworkCredential credentials, TimeSpan httpTimeout) - { - _credentials = credentials; - _client = new HttpClient(); - _apiKey = apiKey; - - var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - if (credentials == null) - { - _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey); - } - _client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "sendgrid/" + version + ";csharp"); - _client.Timeout = httpTimeout; - } - - /// - /// Asynchronously delivers a message over SendGrid's Web interface - /// - /// - public async Task DeliverAsync(ISendGrid message) - { - var content = new MultipartFormDataContent(); - AttachFormParams(message, content); - AttachFiles(message, content); - var response = await _client.PostAsync(Endpoint, content); - await ErrorChecker.CheckForErrorsAsync(response); - } - - #region Support Methods - - private void AttachFormParams(ISendGrid message, MultipartFormDataContent content) - { - var formParams = FetchFormParams(message); - foreach (var keyValuePair in formParams) - { - content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key); - } - } - - private void AttachFiles(ISendGrid message, MultipartFormDataContent content) - { - var files = FetchFileBodies(message); - foreach (var file in files) - { - var fs = new FileStream(file.Key, FileMode.Open, FileAccess.Read); - var fileContent = new StreamContent(fs); - - fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") - { - Name = "files[" + Path.GetFileName(file.Key) + "]", - FileName = Path.GetFileName(file.Key) - }; - - fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); - content.Add(fileContent); - } - - var streamingFiles = FetchStreamingFileBodies(message); - foreach (var file in streamingFiles) - { - var stream = file.Value; - var fileContent = new StreamContent(stream); - - fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") - { - Name = "files[" + Path.GetFileName(file.Key) + "]", - FileName = Path.GetFileName(file.Key) - }; - - fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream"); - content.Add(fileContent); - } - } - - internal List> FetchFormParams(ISendGrid message) - { - var result = new List> - { - new KeyValuePair("headers", - message.Headers.Count == 0 ? null : Utils.SerializeDictionary(message.Headers)), - new KeyValuePair("replyto", - message.ReplyTo.Length == 0 ? null : message.ReplyTo.ToList().First().Address), - new KeyValuePair("from", message.From.Address), - new KeyValuePair("fromname", message.From.DisplayName), - new KeyValuePair("subject", message.Subject), - new KeyValuePair("text", message.Text), - new KeyValuePair("html", message.Html), - new KeyValuePair("x-smtpapi", message.Header.JsonString() ?? "") - }; - - //If the API key is not specified, use the username and password - if (_credentials != null) - { - var creds = new List> - { - new KeyValuePair("api_user", _credentials.UserName), - new KeyValuePair("api_key", _credentials.Password) - }; - result.AddRange(creds); - } - - if (message.To != null) - { - result = result.Concat(message.To.ToList().Select(a => new KeyValuePair("to[]", a.Address))) - .Concat(message.To.ToList().Select(a => new KeyValuePair("toname[]", a.DisplayName))) - .ToList(); - } - - if (message.Cc != null) - { - result.AddRange(message.Cc.Select(c => new KeyValuePair("cc[]", c.Address))); - } - - if (message.Bcc != null) - { - result.AddRange(message.Bcc.Select(c => new KeyValuePair("bcc[]", c.Address))); - } - - if (message.GetEmbeddedImages().Count > 0) { - result = result.Concat(message.GetEmbeddedImages().ToList().Select(x => new KeyValuePair(string.Format("content[{0}]", x.Key), x.Value))) - .ToList(); - } - return result.Where(r => !String.IsNullOrEmpty(r.Value)).ToList(); - } - - internal IEnumerable> FetchStreamingFileBodies(ISendGrid message) - { - return message.StreamedAttachments.Select(kvp => kvp).ToList(); - } - - internal List> FetchFileBodies(ISendGrid message) - { - return message.Attachments == null - ? new List>() - : message.Attachments.Select(name => new KeyValuePair(name, new FileInfo(name))).ToList(); - } - - #endregion - } -} diff --git a/SendGrid/SendGridMail/Web/IWebApi.cs b/SendGrid/SendGridMail/Web/IWebApi.cs deleted file mode 100644 index 52d4cb2f9..000000000 --- a/SendGrid/SendGridMail/Web/IWebApi.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace SendGridMail.Web -{ - interface IWebApi - { - String user { get; set; } - String pass { get; set; } - - String GetBounces(int date, String days, DateTime start_date, DateTime end_date, int limit, int offset, int type, String email); - void DeleteBounces(DateTime start_date, DateTime end_date, String type, String email); - String GetBlocks(int days, DateTime start_date, DateTime end_date, String email); - void DeleteBlocks(String email); - String GetEmailParse(String hostname, String url); - void SetEmailParse(String hostname, String url); - void EditEmailParse(String hostname, String url); - void DeleteEmailParse(String hostname); - String GetNotificationUrl(); - void SetNotificationUrl(String url); - void DeleteNotificationUrl(); - String GetFilter(); - void ActivateFilter(String name); - void DeactivateFilter(String name); - void SetupFilter(String user, String password, Dictionary args); - String GetFilterSettings(String name); - void GetInvalidEmails(int date, int days, DateTime start_date, DateTime end_date, int limit, int offset, String email); - void DeleteInvalidEmails(DateTime start_date, DateTime end_date, String email); - String CountInvalidEmails(DateTime start_date, DateTime end_date); - String GetProfile(); - void UpdateProfile(String First_name, String last_name, String address, String city, String state, String country, int zip, int phone, String website); - void SetUsername(String username); - void SetPassword(String password, String confpass); - void SetEmail(String email); - String GetSpamReports(int date, int days, DateTime start_date, DateTime end_date, int limit, int offset, String email); - void DeleteSpamReports(DateTime start_date, DateTime end_date, String email); - String GetStats(int days, DateTime start_date, DateTime end_date); - String GetAggregateStats(); - String GetCategoryStats(); - String GetCategoryStats(String category, int days, DateTime start_date, DateTime end_date); - String GetUnsubscribes(int date, int days, DateTime start_date, DateTime end_date, int limit, int offset, String email); - void DeleteUnsubscribes(DateTime start_date, DateTime end_date, String email); - void AddUnsubscribes(String email); - } -} diff --git a/SendGrid/SendGridMail/app.config b/SendGrid/SendGridMail/app.config deleted file mode 100644 index 67113e621..000000000 --- a/SendGrid/SendGridMail/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/SendGrid/SendGridMail/nuget/Sendgrid.2.1.1.nuspec b/SendGrid/SendGridMail/nuget/Sendgrid.2.1.1.nuspec deleted file mode 100644 index a6cc5f951..000000000 --- a/SendGrid/SendGridMail/nuget/Sendgrid.2.1.1.nuspec +++ /dev/null @@ -1,24 +0,0 @@ - - - - Sendgrid - 2.1.1 - SendGrid - CJ Buchmann, Tyler Bischel, Eric Becking, Brandon West - CJ Buchmann, Tyler Bischel, Eric Becking, Brandon West - https://github.com/sendgrid/sendgrid-csharp/blob/master/MIT.LICENSE - https://github.com/sendgrid/sendgrid-csharp - false - Basic C# client library and examples for using SendGrid API's to send mail. Github repo located at : https://github.com/sendgrid/sendgrid-csharp - BREAKING CHANGE: Deprecates SMTP transport and adds dependency on smtpapi package for building headers. - -For an example of how to continue using SMTP, see https://github.com/sendgrid/smtpapi-csharp - Copyright 2014 - SendGrid Email Mail Microsoft Azure - - - - - - - \ No newline at end of file diff --git a/SendGrid/SendGridMail/nuget/lib/SendGridMail.dll b/SendGrid/SendGridMail/nuget/lib/SendGridMail.dll deleted file mode 100644 index 47d8c95f2..000000000 Binary files a/SendGrid/SendGridMail/nuget/lib/SendGridMail.dll and /dev/null differ diff --git a/SendGrid/SendGridMail/packages.config b/SendGrid/SendGridMail/packages.config deleted file mode 100644 index 030933bbe..000000000 --- a/SendGrid/SendGridMail/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/SendGrid/SendGridMail/sendgrid-csharp.snk b/SendGrid/SendGridMail/sendgrid-csharp.snk deleted file mode 100644 index aff294450..000000000 Binary files a/SendGrid/SendGridMail/sendgrid-csharp.snk and /dev/null differ diff --git a/SendGrid/Tests/Properties/AssemblyInfo.cs b/SendGrid/Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 8b518a986..000000000 --- a/SendGrid/Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -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("Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Tests")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[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("ce0ad7f8-ecce-46c6-a057-f7aa74bb3518")] - -// 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.2.0")] -[assembly: AssemblyFileVersion("1.2.0")] \ No newline at end of file diff --git a/SendGrid/Tests/TestSendgrid.cs b/SendGrid/Tests/TestSendgrid.cs deleted file mode 100644 index 3ce0c6efd..000000000 --- a/SendGrid/Tests/TestSendgrid.cs +++ /dev/null @@ -1,418 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net.Mail; -using NUnit.Framework; -using SendGrid.SmtpApi; -using SendGrid; - -namespace Tests -{ - [TestFixture] - internal class TestSendgrid - { - [Test] - public void CreateMimeMessage() - { - var message = new SendGridMessage(); - var attachment = Path.GetTempFileName(); - var text = "this is a test"; - var html = "This<\b> is a better test"; - var headers = new KeyValuePair("custom", "header"); - message.AddAttachment(attachment); - message.Text = text; - message.Html = html; - message.AddTo("foo@bar.com"); - message.From = new MailAddress("foo@bar.com"); - message.AddHeaders(new Dictionary {{headers.Key, headers.Value}}); - message.EnableGravatar(); - - var mime = message.CreateMimeMessage(); - - var sr = new StreamReader(mime.AlternateViews[0].ContentStream); - var result = sr.ReadToEnd(); - Assert.AreEqual(text, result); - - sr = new StreamReader(mime.AlternateViews[1].ContentStream); - result = sr.ReadToEnd(); - Assert.AreEqual(html, result); - - result = mime.Headers.Get(headers.Key); - Assert.AreEqual(headers.Value, result); - - result = mime.Headers.Get("X-Smtpapi"); - var expected = "{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"1\"}}}}"; - Assert.AreEqual(expected, result); - - result = mime.Attachments[0].Name; - Assert.AreEqual(Path.GetFileName(attachment), result); - } - - [Test] - public void DisableBcc() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableBcc(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"bcc\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableBypassListManagement() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableBypassListManagement(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"bypass_list_management\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableClickTracking() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableClickTracking(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"clicktrack\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableFooter() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableFooter(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"footer\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableGoogleAnalytics() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableGoogleAnalytics(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"ganalytics\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableSpamCheck() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableSpamCheck(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"spamcheck\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableTemplate() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableTemplate(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"template\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void DisableUnsubscribe() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableUnsubscribe(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void EnableBcc() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - var email = "somebody@someplace.com"; - sendgrid.EnableBcc(email); - - var json = header.JsonString(); - Assert.AreEqual( - "{\"filters\" : {\"bcc\" : {\"settings\" : {\"enable\" : \"1\",\"email\" : \"" + email + "\"}}}}", - json); - } - - [Test] - public void EnableBypassListManagement() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.EnableBypassListManagement(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"bypass_list_management\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json); - } - - [Test] - public void EnableClickTracking() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - sendgrid.EnableClickTracking(true); - - var json = header.JsonString(); - Assert.AreEqual( - "{\"filters\" : {\"clicktrack\" : {\"settings\" : {\"enable\" : \"1\",\"enable_text\" : \"1\"}}}}", - json); - } - - [Test] - public void EnableFooter() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - var text = "My Text"; - var html = "

hello, <% name %>

"; - var escHtml = "

hello, <% name %><\\/p><\\/body>"; - - sendgrid.EnableFooter(text, html); - - var json = header.JsonString(); - Assert.AreEqual( - "{\"filters\" : {\"footer\" : {\"settings\" : {\"enable\" : \"1\",\"text\\/plain\" : \"" + text + - "\",\"text\\/html\" : \"" + escHtml + "\"}}}}", json); - } - - [Test] - public void EnableGoogleAnalytics() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - var source = "SomeDomain.com"; - var medium = "Email"; - var term = "keyword1, keyword2, keyword3"; - var content = "PG, PG13"; - var campaign = "my_campaign"; - - sendgrid.EnableGoogleAnalytics(source, medium, term, content, campaign); - - var jsonSource = "\"utm_source\" : \"SomeDomain.com\""; - var jsonMedium = "\"utm_medium\" : \"" + medium + "\""; - var jsonTerm = "\"utm_term\" : \"" + term + "\""; - var jsonContent = "\"utm_content\" : \"" + content + "\""; - var jsonCampaign = "\"utm_campaign\" : \"" + campaign + "\""; - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"ganalytics\" : {\"settings\" : {\"enable\" : \"1\"," + - jsonSource + "," + jsonMedium + "," + jsonTerm + "," + jsonContent + "," + jsonCampaign + - "}}}}", - json); - } - - [Test] - public void EnableGravatar() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.EnableGravatar(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json); - } - - [Test] - public void EnableOpenTracking() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.EnableOpenTracking(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"opentrack\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json); - } - - [Test] - public void EnableSpamCheck() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - var score = 5; - var url = "http://www.example.com"; - sendgrid.EnableSpamCheck(score, url); - - var json = header.JsonString(); - Assert.AreEqual( - "{\"filters\" : {\"spamcheck\" : {\"settings\" : {\"enable\" : \"1\",\"maxscore\" : \"5\",\"url\" : \"http:\\/\\/www.example.com\"}}}}", - json); - } - - [Test] - public void EnableTemplate() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - var html = "<% body %>"; - - var escHtml = "<% body %>"; - sendgrid.EnableTemplate(html); - - var json = header.JsonString(); - Assert.AreEqual( - "{\"filters\" : {\"template\" : {\"settings\" : {\"enable\" : \"1\",\"text\\/html\" : \"" + escHtml + - "\"}}}}", json); - - escHtml = "bad"; - Assert.Throws(() => sendgrid.EnableTemplate(escHtml)); - } - - [Test] - public void EnableUnsubscribe() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - var text = "<% %>"; - var html = "<% name %>"; - - var jsonText = "\"text\\/plain\" : \"" + text + "\""; - var jsonHtml = "\"text\\/html\" : \"" + html + "\""; - - sendgrid.EnableUnsubscribe(text, html); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"1\"," + - jsonText + "," + jsonHtml + "}}}}", json); - - header = new Header(); - sendgrid = new SendGridMessage(header); - - var replace = "John"; - var jsonReplace = "\"replace\" : \"" + replace + "\""; - - sendgrid.EnableUnsubscribe(replace); - - json = header.JsonString(); - Assert.AreEqual( - "{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"1\"," + jsonReplace + "}}}}", - json); - - text = "bad"; - html = "<% name %>"; - Assert.Throws(() => sendgrid.EnableUnsubscribe(text, html)); - - text = "<% %>"; - html = "bad"; - Assert.Throws(() => sendgrid.EnableUnsubscribe(text, html)); - } - - [Test] - public void TestDisableGravatar() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableGravatar(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"gravatar\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void TestDisableOpenTracking() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.DisableOpenTracking(); - - var json = header.JsonString(); - Assert.AreEqual("{\"filters\" : {\"opentrack\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json); - } - - [Test] - public void TestAddSection() - { - var header = new Header(); - var sendgrid = new SendGridMessage(header); - - sendgrid.AddSection("tag", "value"); - - var json = header.JsonString(); - Assert.AreEqual("{\"section\" : {\"tag\" : \"value\"}}", json); - } - - [Test] - public void TestSendToSink() - { - // Arrange - - var message = new SendGridMessage(); - message.To = new[] - { - new MailAddress("foo@bar.com", "Foo Bar"), - }; - message.AddTo("foo1@bar1.com"); - - // Act - - message.SendToSink(); - - // Assert - - Assert.AreEqual("foo_at_bar.com@sink.sendgrid.net", message.To[0].Address); - Assert.AreEqual("Foo Bar", message.To[0].DisplayName); - - Assert.AreEqual("foo1_at_bar1.com@sink.sendgrid.net", message.To[1].Address); - Assert.AreEqual("", message.To[1].DisplayName); - } - - [Test] - public void TestSendToSinkOff() - { - // Arrange - - var message = new SendGridMessage(); - message.To = new[] - { - new MailAddress("foo@bar.com", "Foo Bar"), - }; - message.AddTo("foo1@bar1.com"); - message.SendToSink(); - - // Act - - message.SendToSink(false); - - // Assert - - Assert.AreEqual("foo@bar.com", message.To[0].Address); - Assert.AreEqual("Foo Bar", message.To[0].DisplayName); - - Assert.AreEqual("foo1@bar1.com", message.To[1].Address); - Assert.AreEqual("", message.To[1].DisplayName); - } - } -} diff --git a/SendGrid/Tests/Tests.csproj b/SendGrid/Tests/Tests.csproj deleted file mode 100644 index ff31ea6e2..000000000 --- a/SendGrid/Tests/Tests.csproj +++ /dev/null @@ -1,123 +0,0 @@ - - - - false - True - full - False - bin\BuildNet45\ - BUILD;TRACE - prompt - 4 - false - - - True - full - False - bin\Debug\ - TRACE, DEBUG - prompt - 4 - false - - - true - sendgrid-csharp.snk - True - bin\Release\ - TRACE - prompt - 4 - false - - - ..\ - true - {0319E73A-7039-4858-B047-1EDF88BB6BD1} - v4.5 - - Debug - AnyCPU - Tests - - - TRACE, BUILD - false - - - Library - - - true - - - sendgrid-csharp.snk - - - - - - ..\packages\Moq.4.2.1402.2112\lib\net40\Moq.dll - - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - True - - - ..\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.3\lib\nunit.framework.dll - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll - False - - - ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - False - - - ..\packages\SendGrid.SmtpApi.1.3.1\lib\net40\SendGrid.SmtpApi.dll - - - - - - - - - - - - - - Designer - - - Designer - - - - - - {3C687BEF-FF50-44AD-8315-2D4237281AF8} - Mail - - - {1c318867-440b-4eb9-99e3-c0cc2c556962} - SendGrid - - - - - - - - \ No newline at end of file diff --git a/SendGrid/Tests/Transport/TestErrorChecker.cs b/SendGrid/Tests/Transport/TestErrorChecker.cs deleted file mode 100644 index f1780646f..000000000 --- a/SendGrid/Tests/Transport/TestErrorChecker.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace Transport -{ - #region Using Directives - - using System; - using System.Net; - using System.Net.Http; - - using Exceptions; - - using NUnit.Framework; - - using SendGrid; - - #endregion - - [TestFixture] - public class TestErrorChecker - { - private const string BadUsernameOrPasswordResponseMessage = "errorBad username / password"; - - [Test] - [ExpectedException(typeof(InvalidApiRequestException))] - public void WhenHttpResponseContainsBadUserErrorItIsDetectedAndAInvalidApiRequestIsThrown() - { - var response = new HttpResponseMessage(HttpStatusCode.BadRequest) - { - Content = new StringContent(BadUsernameOrPasswordResponseMessage) - }; - - ErrorChecker.CheckForErrors(response); - } - } -} \ No newline at end of file diff --git a/SendGrid/Tests/Transport/TestWebApi.cs b/SendGrid/Tests/Transport/TestWebApi.cs deleted file mode 100644 index ecb1ad8ee..000000000 --- a/SendGrid/Tests/Transport/TestWebApi.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Mail; -using Moq; -using NUnit.Framework; -using SendGrid; - -namespace Transport -{ - [TestFixture] - internal class TestWebApi - { - private const string TestUsername = "username"; - private const string TestPassword = "password"; - private const string TestApiKey = "apikey"; - - [Test] - public void TestFetchFileBodies() - { - TestFetchFileBodiesHelper(new Web(new NetworkCredential(TestUsername, TestPassword))); - TestFetchFileBodiesHelper(new Web(TestApiKey)); - } - - public void TestFetchFileBodiesHelper(Web webApi) - { - // Test using credentials - var message = new Mock(); - var attachments = new[] {"foo", "bar", "foobar"}; - message.SetupProperty(foo => foo.Attachments, null); - var result = webApi.FetchFileBodies(message.Object); - Assert.AreEqual(0, result.Count); - - message.SetupProperty(foo => foo.Attachments, attachments); - result = webApi.FetchFileBodies(message.Object); - Assert.AreEqual(attachments.Count(), result.Count); - for (var index = 0; index < attachments.Length; index++) - Assert.AreEqual(result[index].Value.Name, attachments[index]); - } - - [Test] - public void TestFetchFormParams() - { - TestFetchFormParamsHelper(new Web(new NetworkCredential(TestUsername, TestPassword)), true); - TestFetchFormParamsHelper(new Web(TestApiKey), false); - } - - public void TestFetchFormParamsHelper(Web webApi, bool credentials) - { - // Test Variables - const string toAddress = "foobar@outlook.com"; - const string ccAddress = "cc@outlook.com"; - const string bcc1Address = "bcc1@outlook.com"; - const string bcc2Address = "bcc2@outlook.com"; - MailAddress[] bccAddresses = {new MailAddress(bcc1Address), new MailAddress(bcc2Address)}; - const string fromAddress = "test@outlook.com"; - const string subject = "Test Subject"; - const string textBody = "Test Text Body"; - const string htmlBody = "

Test HTML Body

"; - const string headerKey = "headerkey"; - var testHeader = new Dictionary { { headerKey, "headervalue" } }; - const string categoryName = "Example Category"; - - var message = new SendGridMessage(); - message.AddTo(toAddress); - message.AddCc(ccAddress); - message.Bcc = bccAddresses; - message.From = new MailAddress(fromAddress); - message.Subject = subject; - message.Text = textBody; - message.Html = htmlBody; - message.AddHeaders(testHeader); - message.Header.SetCategory(categoryName); - - var result = webApi.FetchFormParams(message); - if (credentials) - { - Assert.True(result.Any(r => r.Key == "api_user" && r.Value == TestUsername)); - Assert.True(result.Any(r => r.Key == "api_key" && r.Value == TestPassword)); - } - Assert.True(result.Any(r => r.Key == "to[]" && r.Value == toAddress)); - Assert.True(result.Any(r => r.Key == "cc[]" && r.Value == ccAddress)); - Assert.True(result.Any(r => r.Key == "bcc[]" && r.Value == bcc1Address)); - Assert.True(result.Any(r => r.Key == "bcc[]" && r.Value == bcc2Address)); - Assert.True(result.Any(r => r.Key == "from" && r.Value == fromAddress)); - Assert.True(result.Any(r => r.Key == "subject" && r.Value == subject)); - Assert.True(result.Any(r => r.Key == "text" && r.Value == textBody)); - Assert.True(result.Any(r => r.Key == "html" && r.Value == htmlBody)); - Assert.True( - result.Any( - r => r.Key == "headers" && r.Value == String.Format("{{\"{0}\":\"{1}\"}}", headerKey, testHeader[headerKey]))); - Assert.True( - result.Any(r => r.Key == "x-smtpapi" && r.Value == String.Format("{{\"category\" : \"{0}\"}}", categoryName))); - } - } -} diff --git a/SendGrid/Tests/app.config b/SendGrid/Tests/app.config deleted file mode 100644 index 199cd2d49..000000000 --- a/SendGrid/Tests/app.config +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/SendGrid/Tests/packages.config b/SendGrid/Tests/packages.config deleted file mode 100644 index 8b08e529f..000000000 --- a/SendGrid/Tests/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/SendGrid/Tests/sendgrid-csharp.snk b/SendGrid/Tests/sendgrid-csharp.snk deleted file mode 100644 index aff294450..000000000 Binary files a/SendGrid/Tests/sendgrid-csharp.snk and /dev/null differ diff --git a/SendGrid/UnitTest/Properties/AssemblyInfo.cs b/SendGrid/UnitTest/Properties/AssemblyInfo.cs index 8eb53f612..ba41e5ebb 100644 --- a/SendGrid/UnitTest/Properties/AssemblyInfo.cs +++ b/SendGrid/UnitTest/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// 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("UnitTest")] @@ -14,8 +14,8 @@ [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 +// 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)] @@ -25,12 +25,12 @@ // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// 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")] +[assembly: AssemblyVersion("7.0.0.0")] +[assembly: AssemblyFileVersion("7.0.0.0")] diff --git a/SendGrid/UnitTest/UnitTest.cs b/SendGrid/UnitTest/UnitTest.cs index 11f55cd8d..67bcf3006 100644 --- a/SendGrid/UnitTest/UnitTest.cs +++ b/SendGrid/UnitTest/UnitTest.cs @@ -1,282 +1,5013 @@ using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using NUnit.Framework; -using Newtonsoft.Json.Linq; -using SendGrid; -using Newtonsoft.Json; +using SendGrid.Helpers.Mail; +using System.Collections.Generic; +using System.Net; namespace UnitTest { + // Test the building of the v3/mail/send request body [TestFixture] - public class APIKeys + public class Mail { - static string _baseUri = "https://api.sendgrid.com/"; static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); - public Client client = new Client(_apiKey, _baseUri); - private static string _api_key_id = ""; + public dynamic sg = new SendGrid.SendGridAPIClient(_apiKey); + + // Base case for sending an email + [Test] + public void TestHelloEmail() + { + SendGrid.Helpers.Mail.Mail mail = new SendGrid.Helpers.Mail.Mail(); + + Email email = new Email(); + email.Address = "test@example.com"; + mail.From = email; + + Personalization personalization = new Personalization(); + email = new Email(); + email.Address = "test@example.com"; + personalization.AddTo(email); + mail.AddPersonalization(personalization); + + mail.Subject = "Hello World from the SendGrid CSharp Library"; + + Content content = new Content(); + content.Type = "text/plain"; + content.Value = "Textual content"; + mail.AddContent(content); + content = new Content(); + content.Type = "text/html"; + content.Value = "HTML content"; + mail.AddContent(content); + + String ret = mail.Get(); + Assert.AreEqual(ret, "{\"from\":{\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid CSharp Library\",\"personalizations\":[{\"to\":[{\"email\":\"test@example.com\"}]}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Textual content\"},{\"type\":\"text/html\",\"value\":\"HTML content\"}]}"); + } + + // All paramaters available for sending an email + [Test] + public void TestKitchenSink() + { + SendGrid.Helpers.Mail.Mail mail = new SendGrid.Helpers.Mail.Mail(); + + Email email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + mail.From = email; + + mail.Subject = "Hello World from the SendGrid CSharp Library"; + + Personalization personalization = new Personalization(); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddTo(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddBcc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddBcc(email); + personalization.Subject = "Thank you for signing up, %name%"; + personalization.AddHeader("X-Test", "True"); + personalization.AddHeader("X-Mock", "True"); + personalization.AddSubstitution("%name%", "Example User"); + personalization.AddSubstitution("%city%", "Denver"); + personalization.AddCustomArgs("marketing", "false"); + personalization.AddCustomArgs("transactional", "true"); + personalization.SendAt = 1461775051; + mail.AddPersonalization(personalization); + + personalization = new Personalization(); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddTo(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddCc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddBcc(email); + email = new Email(); + email.Name = "Example User"; + email.Address = "test@example.com"; + personalization.AddBcc(email); + personalization.Subject = "Thank you for signing up, %name%"; + personalization.AddHeader("X-Test", "True"); + personalization.AddHeader("X-Mock", "True"); + personalization.AddSubstitution("%name%", "Example User"); + personalization.AddSubstitution("%city%", "Denver"); + personalization.AddCustomArgs("marketing", "false"); + personalization.AddCustomArgs("transactional", "true"); + personalization.SendAt = 1461775051; + mail.AddPersonalization(personalization); + + Content content = new Content(); + content.Type = "text/plain"; + content.Value = "Textual content"; + mail.AddContent(content); + content = new Content(); + content.Type = "text/html"; + content.Value = "HTML content"; + mail.AddContent(content); + content = new Content(); + content.Type = "text/calendar"; + content.Value = "Party Time!!"; + mail.AddContent(content); + + Attachment attachment = new Attachment(); + attachment.Content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12"; + attachment.Type = "application/pdf"; + attachment.Filename = "balance_001.pdf"; + attachment.Disposition = "attachment"; + attachment.ContentId = "Balance Sheet"; + mail.AddAttachment(attachment); + + attachment = new Attachment(); + attachment.Content = "BwdW"; + attachment.Type = "image/png"; + attachment.Filename = "banner.png"; + attachment.Disposition = "inline"; + attachment.ContentId = "Banner"; + mail.AddAttachment(attachment); + + mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932"; + + mail.AddHeader("X-Day", "Monday"); + mail.AddHeader("X-Month", "January"); + + mail.AddSection("%section1", "Substitution for Section 1 Tag"); + mail.AddSection("%section2", "Substitution for Section 2 Tag"); + + mail.AddCategory("customer"); + mail.AddCategory("vip"); + + mail.AddCustomArgs("campaign", "welcome"); + mail.AddCustomArgs("sequence", "2"); + + ASM asm = new ASM(); + asm.GroupId = 3; + List groups_to_display = new List() + { + 1, 4, 5 + }; + asm.GroupsToDisplay = groups_to_display; + mail.Asm = asm; + + mail.SendAt = 1461775051; + + mail.SetIpPoolId = "23"; + + // This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) + // mail.BatchId = "some_batch_id"; + + MailSettings mailSettings = new MailSettings(); + BCCSettings bccSettings = new BCCSettings(); + bccSettings.Enable = true; + bccSettings.Email = "test@example.com"; + mailSettings.BccSettings = bccSettings; + BypassListManagement bypassListManagement = new BypassListManagement(); + bypassListManagement.Enable = true; + mailSettings.BypassListManagement = bypassListManagement; + FooterSettings footerSettings = new FooterSettings(); + footerSettings.Enable = true; + footerSettings.Text = "Some Footer Text"; + footerSettings.Html = "Some HTML Here"; + mailSettings.FooterSettings = footerSettings; + SandboxMode sandboxMode = new SandboxMode(); + sandboxMode.Enable = true; + mailSettings.SandboxMode = sandboxMode; + SpamCheck spamCheck = new SpamCheck(); + spamCheck.Enable = true; + spamCheck.Threshold = 1; + spamCheck.PostToUrl = "https://gotchya.example.com"; + mailSettings.SpamCheck = spamCheck; + mail.MailSettings = mailSettings; + + TrackingSettings trackingSettings = new TrackingSettings(); + ClickTracking clickTracking = new ClickTracking(); + clickTracking.Enable = true; + clickTracking.EnableText = false; + trackingSettings.ClickTracking = clickTracking; + OpenTracking openTracking = new OpenTracking(); + openTracking.Enable = true; + openTracking.SubstitutionTag = "Optional tag to replace with the open image in the body of the message"; + trackingSettings.OpenTracking = openTracking; + SubscriptionTracking subscriptionTracking = new SubscriptionTracking(); + subscriptionTracking.Enable = true; + subscriptionTracking.Text = "text to insert into the text/plain portion of the message"; + subscriptionTracking.Html = "HTML to insert into the text/html portion of the message"; + subscriptionTracking.SubstitutionTag = "text to insert into the text/plain portion of the message"; + trackingSettings.SubscriptionTracking = subscriptionTracking; + Ganalytics ganalytics = new Ganalytics(); + ganalytics.Enable = true; + ganalytics.UtmCampaign = "some campaign"; + ganalytics.UtmContent = "some content"; + ganalytics.UtmMedium = "some medium"; + ganalytics.UtmSource = "some source"; + ganalytics.UtmTerm = "some term"; + trackingSettings.Ganalytics = ganalytics; + mail.TrackingSettings = trackingSettings; + + email = new Email(); + email.Address = "test@example.com"; + mail.ReplyTo = email; + + String ret = mail.Get(); + Assert.AreEqual(ret, "{\"from\":{\"name\":\"Example User\",\"email\":\"test@example.com\"},\"subject\":\"Hello World from the SendGrid CSharp Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Thank you for signing up, %name%\",\"headers\":{\"X-Test\":\"True\",\"X-Mock\":\"True\"},\"substitutions\":{\"%name%\":\"Example User\",\"%city%\":\"Denver\"},\"custom_args\":{\"marketing\":\"false\",\"transactional\":\"true\"},\"send_at\":1461775051},{\"to\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test@example.com\"},{\"name\":\"Example User\",\"email\":\"test@example.com\"}],\"subject\":\"Thank you for signing up, %name%\",\"headers\":{\"X-Test\":\"True\",\"X-Mock\":\"True\"},\"substitutions\":{\"%name%\":\"Example User\",\"%city%\":\"Denver\"},\"custom_args\":{\"marketing\":\"false\",\"transactional\":\"true\"},\"send_at\":1461775051}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Textual content\"},{\"type\":\"text/html\",\"value\":\"HTML content\"},{\"type\":\"text/calendar\",\"value\":\"Party Time!!\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"headers\":{\"X-Day\":\"Monday\",\"X-Month\":\"January\"},\"sections\":{\"%section1\":\"Substitution for Section 1 Tag\",\"%section2\":\"Substitution for Section 2 Tag\"},\"categories\":[\"customer\",\"vip\"],\"custom_args\":{\"campaign\":\"welcome\",\"sequence\":\"2\"},\"send_at\":1461775051,\"asm\":{\"group_id\":3,\"groups_to_display\":[1,4,5]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"test@example.com\"},\"bypass_list_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Some Footer Text\",\"html\":\"Some HTML Here\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://gotchya.example.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"HTML to insert into the text/html portion of the message\",\"substitution_tag\":\"text to insert into the text/plain portion of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_medium\":\"some medium\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some campaign\"}},\"reply_to\":{\"email\":\"test@example.com\"}}"); + } + } + + [TestFixture] + public class v3WebAPI + { [Test] - public void ApiKeysIntegrationTest() + public void test_access_settings_activity_get() { - TestGet(); - TestPost(); - TestPatch(); - TestDelete(); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.access_settings.activity.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestGet() + [Test] + public void test_access_settings_whitelist_post() { - HttpResponseMessage response = client.ApiKeys.Get().Result; - 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); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'ips': [ + { + 'ip': '192.168.1.1' + }, + { + 'ip': '192.*.*.*' + }, + { + 'ip': '192.168.1.3/32' + } + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.access_settings.whitelist.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } - private void TestPost() + [Test] + public void test_access_settings_whitelist_get() { - HttpResponseMessage response = client.ApiKeys.Post("CSharpTestKey").Result; - 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); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.access_settings.whitelist.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestPatch() + [Test] + public void test_access_settings_whitelist_delete() { - HttpResponseMessage response = client.ApiKeys.Patch(_api_key_id, "CSharpTestKeyPatched").Result; - 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); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'ids': [ + 1, + 2, + 3 + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.access_settings.whitelist.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); } - private void TestDelete() + [Test] + public void test_access_settings_whitelist__rule_id__get() { - HttpResponseMessage response = client.ApiKeys.Delete(_api_key_id).Result; - Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var rule_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.access_settings.whitelist._(rule_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } [Test] - public void TestGetOnce() + public void test_access_settings_whitelist__rule_id__delete() { - var responseGet = client.ApiKeys.Get().Result; + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var rule_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.access_settings.whitelist._(rule_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); } [Test] - public void TestGetTenTimes() + public void test_api_keys_post() { - HttpResponseMessage responseGet; - for (int i = 0; i < 10; i++) - { - responseGet = client.ApiKeys.Get().Result; + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'My API Key', + 'scopes': [ + 'mail.send', + 'alerts.create', + 'alerts.read' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.api_keys.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } [Test] - public void TestGetTenTimesAsync() + public void test_api_keys_get() { - Task[] tasks = new Task[10]; - for (int i = 0; i < 10; i++) - { - tasks[i] = client.ApiKeys.Get(); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; } - Task.WaitAll(tasks); + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.api_keys.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - } - [TestFixture] - public class UnsubscribeGroups - { - static string _baseUri = "https://api.sendgrid.com/"; - static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); - public Client client = new Client(_apiKey, _baseUri); - private static string _unsubscribe_groups_key_id = ""; + [Test] + public void test_api_keys__api_key_id__put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'A New Hope', + 'scopes': [ + 'user.profile.read', + 'user.profile.update' + ] +}"; + var api_key_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.api_keys._(api_key_id).put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } [Test] - public void UnsubscribeGroupsIntegrationTest() + public void test_api_keys__api_key_id__patch() { - int unsubscribeGroupId = 69; + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'A New Hope' +}"; + var api_key_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.api_keys._(api_key_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } - TestGet(); - TestGetUnique(unsubscribeGroupId); - TestPost(); - TestDelete(); + [Test] + public void test_api_keys__api_key_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var api_key_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.api_keys._(api_key_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestGet() + [Test] + public void test_api_keys__api_key_id__delete() { - HttpResponseMessage response = client.UnsubscribeGroups.Get().Result; - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JsonConvert.DeserializeObject(rawString); - Assert.IsNotNull(jsonObject); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var api_key_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.api_keys._(api_key_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); } - private void TestGetUnique(int unsubscribeGroupId) + [Test] + public void test_asm_groups_post() { - HttpResponseMessage response = client.UnsubscribeGroups.Get(unsubscribeGroupId).Result; - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JsonConvert.DeserializeObject(rawString); - Assert.IsNotNull(jsonObject); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'description': 'Suggestions for products our users might like.', + 'is_default': true, + 'name': 'Product Suggestions' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.asm.groups.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } - private void TestPost() + [Test] + public void test_asm_groups_get() { - HttpResponseMessage response = client.UnsubscribeGroups.Post("C Sharp Unsubscribes", "Testing the C Sharp Library", false).Result; - Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JObject.Parse(rawString); - string name = jsonObject.name.ToString(); - string description = jsonObject.description.ToString(); - _unsubscribe_groups_key_id = jsonObject.id.ToString(); - bool is_default = jsonObject.is_default; - Assert.IsNotNull(name); - Assert.IsNotNull(description); - Assert.IsNotNull(_unsubscribe_groups_key_id); - Assert.IsNotNull(is_default); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'id': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.asm.groups.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestDelete() + [Test] + public void test_asm_groups__group_id__patch() { - HttpResponseMessage response = client.UnsubscribeGroups.Delete(_unsubscribe_groups_key_id).Result; - Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'description': 'Suggestions for items our users might like.', + 'id': 103, + 'name': 'Item Suggestions' +}"; + var group_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.asm.groups._(group_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } - } + [Test] + public void test_asm_groups__group_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var group_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.asm.groups._(group_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } - [TestFixture] - public class Suppressions - { - static string _baseUri = "https://api.sendgrid.com/"; - static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); - public Client client = new Client(_apiKey, _baseUri); + [Test] + public void test_asm_groups__group_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var group_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.asm.groups._(group_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } [Test] - public void SuppressionsIntegrationTest() + public void test_asm_groups__group_id__suppressions_post() { - int unsubscribeGroupId = 69; + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'recipient_emails': [ + 'test1@example.com', + 'test2@example.com' + ] +}"; + var group_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.asm.groups._(group_id).suppressions.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } - TestGet(unsubscribeGroupId); - string[] emails = { "example@example.com", "example2@example.com" }; - TestPost(unsubscribeGroupId, emails); - TestDelete(unsubscribeGroupId, "example@example.com"); - TestDelete(unsubscribeGroupId, "example2@example.com"); + [Test] + public void test_asm_groups__group_id__suppressions_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var group_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.asm.groups._(group_id).suppressions.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestGet(int unsubscribeGroupId) + [Test] + public void test_asm_groups__group_id__suppressions__email__delete() { - HttpResponseMessage response = client.Suppressions.Get(unsubscribeGroupId).Result; - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JsonConvert.DeserializeObject(rawString); - Assert.IsNotNull(jsonObject); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var group_id = "test_url_param"; + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.asm.groups._(group_id).suppressions._(email).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); } - private void TestPost(int unsubscribeGroupId, string[] emails) + [Test] + public void test_asm_suppressions_get() { - HttpResponseMessage response = client.Suppressions.Post(unsubscribeGroupId, emails).Result; - Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JObject.Parse(rawString); - string recipient_emails = jsonObject.recipient_emails.ToString(); - Assert.IsNotNull(recipient_emails); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.asm.suppressions.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestDelete(int unsubscribeGroupId, string email) + [Test] + public void test_asm_suppressions_global_post() { - HttpResponseMessage response = client.Suppressions.Delete(unsubscribeGroupId, email).Result; - Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'recipient_emails': [ + 'test1@example.com', + 'test2@example.com' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.asm.suppressions.global.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } - } + [Test] + public void test_asm_suppressions_global__email__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.asm.suppressions.global._(email).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } - [TestFixture] - public class GlobalSuppressions - { - static string _baseUri = "https://api.sendgrid.com/"; - static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); - public Client client = new Client(_apiKey, _baseUri); + [Test] + public void test_asm_suppressions_global__email__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.asm.suppressions.global._(email).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } [Test] - public void GlobalSuppressionsIntegrationTest() + public void test_asm_suppressions__email__get() { - string email = "example3@example.com"; + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.asm.suppressions._(email).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } - TestGet(email); - string[] emails = { "example1@example.com", "example2@example.com" }; - TestPost(emails); - TestDelete("example1@example.com"); - TestDelete("example2@example.com"); + [Test] + public void test_browsers_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'browsers': 'test_string', + 'end_date': '2016-04-01', + 'limit': 'test_string', + 'offset': 'test_string', + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.browsers.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestGet(string email) + [Test] + public void test_campaigns_post() { - HttpResponseMessage response = client.GlobalSuppressions.Get(email).Result; - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JsonConvert.DeserializeObject(rawString); - Assert.IsNotNull(jsonObject); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'categories': [ + 'spring line' + ], + 'custom_unsubscribe_url': '', + 'html_content': '

Check out our spring line!

', + 'ip_pool': 'marketing', + 'list_ids': [ + 110, + 124 + ], + 'plain_content': 'Check out our spring line!', + 'segment_ids': [ + 110 + ], + 'sender_id': 124451, + 'subject': 'New Products for Spring!', + 'suppression_group_id': 42, + 'title': 'March Newsletter' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.campaigns.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } - private void TestPost(string[] emails) + [Test] + public void test_campaigns_get() { - HttpResponseMessage response = client.GlobalSuppressions.Post(emails).Result; - Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JObject.Parse(rawString); - string recipient_emails = jsonObject.recipient_emails.ToString(); - Assert.IsNotNull(recipient_emails); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 0, + 'offset': 0 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.campaigns.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - private void TestDelete(string email) + [Test] + public void test_campaigns__campaign_id__patch() { - HttpResponseMessage response = client.GlobalSuppressions.Delete(email).Result; - Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'categories': [ + 'summer line' + ], + 'html_content': '

Check out our summer line!

', + 'plain_content': 'Check out our summer line!', + 'subject': 'New Products for Summer!', + 'title': 'May Newsletter' +}"; + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.campaigns._(campaign_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); } - } - [TestFixture] - public class GlobalStats - { - static string _baseUri = "https://api.sendgrid.com/"; - static string _apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY"); - public Client client = new Client(_apiKey, _baseUri); + [Test] + public void test_campaigns__campaign_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.campaigns._(campaign_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_campaigns__campaign_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.campaigns._(campaign_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_campaigns__campaign_id__schedules_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'send_at': 1489451436 +}"; + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.campaigns._(campaign_id).schedules.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_campaigns__campaign_id__schedules_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'send_at': 1489771528 +}"; + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.campaigns._(campaign_id).schedules.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_campaigns__campaign_id__schedules_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.campaigns._(campaign_id).schedules.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_campaigns__campaign_id__schedules_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.campaigns._(campaign_id).schedules.delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_campaigns__campaign_id__schedules_now_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.campaigns._(campaign_id).schedules.now.post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_campaigns__campaign_id__schedules_test_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'to': 'your.email@example.com' +}"; + var campaign_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.campaigns._(campaign_id).schedules.test.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_categories_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'category': 'test_string', + 'limit': 1, + 'offset': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.categories.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_categories_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'categories': 'test_string', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.categories.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_categories_stats_sums_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'sort_by_direction': 'asc', + 'sort_by_metric': 'test_string', + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.categories.stats.sums.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_clients_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.clients.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_clients__client_type__stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'start_date': '2016-01-01' +}"; + var client_type = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.clients._(client_type).stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_custom_fields_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'pet', + 'type': 'text' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.contactdb.custom_fields.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_contactdb_custom_fields_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.custom_fields.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_custom_fields__custom_field_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var custom_field_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.custom_fields._(custom_field_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_custom_fields__custom_field_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var custom_field_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "202"); + dynamic response = sg.client.contactdb.custom_fields._(custom_field_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Accepted); + } + + [Test] + public void test_contactdb_lists_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'your list name' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.contactdb.lists.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_contactdb_lists_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.lists.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_lists_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"[ + 1, + 2, + 3, + 4 +]"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.contactdb.lists.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_contactdb_lists__list_id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'newlistname' +}"; + string queryParams = @"{ + 'list_id': 0 +}"; + var list_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.lists._(list_id).patch(requestBody: data, queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_lists__list_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'list_id': 0 +}"; + var list_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.lists._(list_id).get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_lists__list_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'delete_contacts': 'true' +}"; + var list_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "202"); + dynamic response = sg.client.contactdb.lists._(list_id).delete(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Accepted); + } + + [Test] + public void test_contactdb_lists__list_id__recipients_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"[ + 'recipient_id1', + 'recipient_id2' +]"; + var list_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.contactdb.lists._(list_id).recipients.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_contactdb_lists__list_id__recipients_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'list_id': 0, + 'page': 1, + 'page_size': 1 +}"; + var list_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.lists._(list_id).recipients.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } [Test] - public void GlobalStatsIntegrationTest() + public void test_contactdb_lists__list_id__recipients__recipient_id__post() { - string startDate = "2015-11-01"; - string endDate = "2015-12-01"; - string aggregatedBy = "day"; - TestGet(startDate); - TestGet(startDate, endDate); - TestGet(startDate, endDate, aggregatedBy); - aggregatedBy = "week"; - TestGet(startDate, endDate, aggregatedBy); - aggregatedBy = "month"; - TestGet(startDate, endDate, aggregatedBy); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var list_id = "test_url_param"; + var recipient_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); } - private void TestGet(string startDate, string endDate=null, string aggregatedBy=null) + [Test] + public void test_contactdb_lists__list_id__recipients__recipient_id__delete() { - HttpResponseMessage response = client.GlobalStats.Get(startDate, endDate, aggregatedBy).Result; - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - string rawString = response.Content.ReadAsStringAsync().Result; - dynamic jsonObject = JsonConvert.DeserializeObject(rawString); - Assert.IsNotNull(jsonObject); + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'list_id': 0, + 'recipient_id': 0 +}"; + var list_id = "test_url_param"; + var recipient_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); } + + [Test] + public void test_contactdb_recipients_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"[ + { + 'email': 'jones@example.com', + 'first_name': 'Guy', + 'last_name': 'Jones' + } +]"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.contactdb.recipients.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_contactdb_recipients_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"[ + { + 'age': 25, + 'email': 'example@example.com', + 'first_name': '', + 'last_name': 'User' + }, + { + 'age': 25, + 'email': 'example2@example.com', + 'first_name': 'Example', + 'last_name': 'User' + } +]"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.contactdb.recipients.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_contactdb_recipients_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'page': 1, + 'page_size': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_recipients_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"[ + 'recipient_id1', + 'recipient_id2' +]"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_recipients_billable_count_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients.billable_count.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_recipients_count_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients.count.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_recipients_search_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + '{field_name}': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients.search.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_recipients__recipient_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var recipient_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients._(recipient_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_recipients__recipient_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var recipient_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.contactdb.recipients._(recipient_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_contactdb_recipients__recipient_id__lists_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var recipient_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.recipients._(recipient_id).lists.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_reserved_fields_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.reserved_fields.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_segments_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'conditions': [ + { + 'and_or': '', + 'field': 'last_name', + 'operator': 'eq', + 'value': 'Miller' + }, + { + 'and_or': 'and', + 'field': 'last_clicked', + 'operator': 'gt', + 'value': '01/02/2015' + }, + { + 'and_or': 'or', + 'field': 'clicks.campaign_identifier', + 'operator': 'eq', + 'value': '513' + } + ], + 'list_id': 4, + 'name': 'Last Name Miller' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.segments.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_segments_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.segments.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_segments__segment_id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'conditions': [ + { + 'and_or': '', + 'field': 'last_name', + 'operator': 'eq', + 'value': 'Miller' + } + ], + 'list_id': 5, + 'name': 'The Millers' +}"; + string queryParams = @"{ + 'segment_id': 'test_string' +}"; + var segment_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.segments._(segment_id).patch(requestBody: data, queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_segments__segment_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'segment_id': 0 +}"; + var segment_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.segments._(segment_id).get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_contactdb_segments__segment_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'delete_contacts': 'true' +}"; + var segment_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.contactdb.segments._(segment_id).delete(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_contactdb_segments__segment_id__recipients_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'page': 1, + 'page_size': 1 +}"; + var segment_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.contactdb.segments._(segment_id).recipients.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_devices_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.devices.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_geo_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'country': 'US', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.geo.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'exclude_whitelabels': 'true', + 'ip': 'test_string', + 'limit': 1, + 'offset': 1, + 'subuser': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_assigned_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.assigned.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_pools_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'marketing' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.pools.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_pools_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.pools.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_pools__pool_name__put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'new_pool_name' +}"; + var pool_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.pools._(pool_name).put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_pools__pool_name__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var pool_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.pools._(pool_name).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_pools__pool_name__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var pool_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.ips.pools._(pool_name).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_ips_pools__pool_name__ips_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'ip': '0.0.0.0' +}"; + var pool_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.ips.pools._(pool_name).ips.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_ips_pools__pool_name__ips__ip__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var pool_name = "test_url_param"; + var ip = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.ips.pools._(pool_name).ips._(ip).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_ips_warmup_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'ip': '0.0.0.0' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.warmup.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_warmup_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.warmup.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_warmup__ip_address__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var ip_address = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips.warmup._(ip_address).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_ips_warmup__ip_address__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var ip_address = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.ips.warmup._(ip_address).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_ips__ip_address__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var ip_address = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.ips._(ip_address).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_batch_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.mail.batch.post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_mail_batch__batch_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var batch_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail.batch._(batch_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_send_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'asm': { + 'group_id': 1, + 'groups_to_display': [ + 1, + 2, + 3 + ] + }, + 'attachments': [ + { + 'content': '[BASE64 encoded content block here]', + 'content_id': 'ii_139db99fdb5c3704', + 'disposition': 'inline', + 'filename': 'file1.jpg', + 'name': 'file1', + 'type': 'jpg' + } + ], + 'batch_id': '[YOUR BATCH ID GOES HERE]', + 'categories': [ + 'category1', + 'category2' + ], + 'content': [ + { + 'type': 'text/html', + 'value': '

Hello, world!

' + } + ], + 'custom_args': { + 'New Argument 1': 'New Value 1', + 'activationAttempt': '1', + 'customerAccountNumber': '[CUSTOMER ACCOUNT NUMBER GOES HERE]' + }, + 'from': { + 'email': 'sam.smith@example.com', + 'name': 'Sam Smith' + }, + 'headers': {}, + 'ip_pool_name': '[YOUR POOL NAME GOES HERE]', + 'mail_settings': { + 'bcc': { + 'email': 'ben.doe@example.com', + 'enable': true + }, + 'bypass_list_management': { + 'enable': true + }, + 'footer': { + 'enable': true, + 'html': '

Thanks
The SendGrid Team

', + 'text': 'Thanks,/n The SendGrid Team' + }, + 'sandbox_mode': { + 'enable': false + }, + 'spam_check': { + 'enable': true, + 'post_to_url': 'http://example.com/compliance', + 'threshold': 3 + } + }, + 'personalizations': [ + { + 'bcc': [ + { + 'email': 'sam.doe@example.com', + 'name': 'Sam Doe' + } + ], + 'cc': [ + { + 'email': 'jane.doe@example.com', + 'name': 'Jane Doe' + } + ], + 'custom_args': { + 'New Argument 1': 'New Value 1', + 'activationAttempt': '1', + 'customerAccountNumber': '[CUSTOMER ACCOUNT NUMBER GOES HERE]' + }, + 'headers': { + 'X-Accept-Language': 'en', + 'X-Mailer': 'MyApp' + }, + 'send_at': 1409348513, + 'subject': 'Hello, World!', + 'substitutions': { + 'sub': { + '%name%': [ + 'John', + 'Jane', + 'Sam' + ] + } + }, + 'to': [ + { + 'email': 'john.doe@example.com', + 'name': 'John Doe' + } + ] + } + ], + 'reply_to': { + 'email': 'sam.smith@example.com', + 'name': 'Sam Smith' + }, + 'sections': { + 'section': { + ':sectionName1': 'section 1 text', + ':sectionName2': 'section 2 text' + } + }, + 'send_at': 1409348513, + 'subject': 'Hello, World!', + 'template_id': '[YOUR TEMPLATE ID GOES HERE]', + 'tracking_settings': { + 'click_tracking': { + 'enable': true, + 'enable_text': true + }, + 'ganalytics': { + 'enable': true, + 'utm_campaign': '[NAME OF YOUR REFERRER SOURCE]', + 'utm_content': '[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]', + 'utm_medium': '[NAME OF YOUR MARKETING MEDIUM e.g. email]', + 'utm_name': '[NAME OF YOUR CAMPAIGN]', + 'utm_term': '[IDENTIFY PAID KEYWORDS HERE]' + }, + 'open_tracking': { + 'enable': true, + 'substitution_tag': '%opentrack' + }, + 'subscription_tracking': { + 'enable': true, + 'html': 'If you would like to unsubscribe and stop receiving these emails <% clickhere %>.', + 'substitution_tag': '<%click here%>', + 'text': 'If you would like to unsubscribe and stop receiveing these emails <% click here %>.' + } + } +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "202"); + dynamic response = sg.client.mail.send.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Accepted); + } + + [Test] + public void test_mail_settings_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 1, + 'offset': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_address_whitelist_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'list': [ + 'email1@example.com', + 'example.com' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.address_whitelist.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_address_whitelist_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.address_whitelist.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_bcc_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': 'email@example.com', + 'enabled': false +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.bcc.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_bcc_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.bcc.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_bounce_purge_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'hard_bounces': 5, + 'soft_bounces': 5 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.bounce_purge.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_bounce_purge_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.bounce_purge.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_footer_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'html_content': '...', + 'plain_content': '...' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.footer.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_footer_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.footer.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_forward_bounce_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': 'example@example.com', + 'enabled': true +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.forward_bounce.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_forward_bounce_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.forward_bounce.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_forward_spam_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': '', + 'enabled': false +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.forward_spam.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_forward_spam_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.forward_spam.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_plain_content_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': false +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.plain_content.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_plain_content_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.plain_content.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_spam_check_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'max_score': 5, + 'url': 'url' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.spam_check.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_spam_check_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.spam_check.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_template_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'html_content': '<% body %>' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.template.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mail_settings_template_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mail_settings.template.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_mailbox_providers_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 1, + 'mailbox_providers': 'test_string', + 'offset': 1, + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.mailbox_providers.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_partner_settings_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 1, + 'offset': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.partner_settings.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_partner_settings_new_relic_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enable_subuser_statistics': true, + 'enabled': true, + 'license_key': '' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.partner_settings.new_relic.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_partner_settings_new_relic_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.partner_settings.new_relic.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_scopes_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.scopes.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': 'John@example.com', + 'ips': [ + '1.1.1.1', + '2.2.2.2' + ], + 'password': 'johns_password', + 'username': 'John@example.com' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 0, + 'offset': 0, + 'username': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers_reputations_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'usernames': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers.reputations.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'start_date': '2016-01-01', + 'subusers': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers_stats_monthly_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'date': 'test_string', + 'limit': 1, + 'offset': 1, + 'sort_by_direction': 'asc', + 'sort_by_metric': 'test_string', + 'subuser': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers.stats.monthly.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers_stats_sums_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 1, + 'offset': 1, + 'sort_by_direction': 'asc', + 'sort_by_metric': 'test_string', + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers.stats.sums.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers__subuser_name__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'disabled': false +}"; + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.subusers._(subuser_name).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_subusers__subuser_name__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.subusers._(subuser_name).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_subusers__subuser_name__ips_put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"[ + '127.0.0.1' +]"; + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers._(subuser_name).ips.put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers__subuser_name__monitor_put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': 'example@example.com', + 'frequency': 500 +}"; + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers._(subuser_name).monitor.put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers__subuser_name__monitor_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': 'example@example.com', + 'frequency': 50000 +}"; + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers._(subuser_name).monitor.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers__subuser_name__monitor_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers._(subuser_name).monitor.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_subusers__subuser_name__monitor_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.subusers._(subuser_name).monitor.delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_subusers__subuser_name__stats_monthly_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'date': 'test_string', + 'limit': 0, + 'offset': 1, + 'sort_by_direction': 'asc', + 'sort_by_metric': 'test_string' +}"; + var subuser_name = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.subusers._(subuser_name).stats.monthly.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_blocks_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'end_time': 1, + 'limit': 1, + 'offset': 1, + 'start_time': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.blocks.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_blocks_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'delete_all': false, + 'emails': [ + 'example1@example.com', + 'example2@example.com' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.blocks.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_blocks__email__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.blocks._(email).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_blocks__email__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.blocks._(email).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_bounces_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'end_time': 0, + 'start_time': 0 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.bounces.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_bounces_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'delete_all': true, + 'emails': [ + 'example@example.com', + 'example2@example.com' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.bounces.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_bounces__email__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.bounces._(email).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_bounces__email__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'email_address': 'example@example.com' +}"; + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.bounces._(email).delete(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_invalid_emails_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'end_time': 1, + 'limit': 1, + 'offset': 1, + 'start_time': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.invalid_emails.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_invalid_emails_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'delete_all': false, + 'emails': [ + 'example1@example.com', + 'example2@example.com' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.invalid_emails.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_invalid_emails__email__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.invalid_emails._(email).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_invalid_emails__email__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.invalid_emails._(email).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_spam_report__email__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.spam_report._(email).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_spam_report__email__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var email = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.spam_report._(email).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_spam_reports_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'end_time': 1, + 'limit': 1, + 'offset': 1, + 'start_time': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.spam_reports.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_suppression_spam_reports_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'delete_all': false, + 'emails': [ + 'example1@example.com', + 'example2@example.com' + ] +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.suppression.spam_reports.delete(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_suppression_unsubscribes_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'end_time': 1, + 'limit': 1, + 'offset': 1, + 'start_time': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.suppression.unsubscribes.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_templates_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'example_name' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.templates.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_templates_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.templates.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_templates__template_id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'name': 'new_example_name' +}"; + var template_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.templates._(template_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_templates__template_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var template_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.templates._(template_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_templates__template_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var template_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.templates._(template_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_templates__template_id__versions_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'active': 1, + 'html_content': '<%body%>', + 'name': 'example_version_name', + 'plain_content': '<%body%>', + 'subject': '<%subject%>', + 'template_id': 'ddb96bbc-9b92-425e-8979-99464621b543' +}"; + var template_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.templates._(template_id).versions.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_templates__template_id__versions__version_id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'active': 1, + 'html_content': '<%body%>', + 'name': 'updated_example_name', + 'plain_content': '<%body%>', + 'subject': '<%subject%>' +}"; + var template_id = "test_url_param"; + var version_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.templates._(template_id).versions._(version_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_templates__template_id__versions__version_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var template_id = "test_url_param"; + var version_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.templates._(template_id).versions._(version_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_templates__template_id__versions__version_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var template_id = "test_url_param"; + var version_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.templates._(template_id).versions._(version_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_templates__template_id__versions__version_id__activate_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var template_id = "test_url_param"; + var version_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.templates._(template_id).versions._(version_id).activate.post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 1, + 'offset': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_click_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.click.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_click_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.click.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_google_analytics_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'utm_campaign': 'website', + 'utm_content': '', + 'utm_medium': 'email', + 'utm_source': 'sendgrid.com', + 'utm_term': '' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.google_analytics.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_google_analytics_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.google_analytics.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_open_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.open.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_open_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.open.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_subscription_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'enabled': true, + 'html_content': 'html content', + 'landing': 'landing page html', + 'plain_content': 'text content', + 'replace': 'replacement tag', + 'url': 'url' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.subscription.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_tracking_settings_subscription_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.tracking_settings.subscription.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_account_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.account.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_credits_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.credits.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_email_put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'email': 'example@example.com' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.email.put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_email_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.email.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_password_put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'new_password': 'new_password', + 'old_password': 'old_password' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.password.put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_profile_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'city': 'Orange', + 'first_name': 'Example', + 'last_name': 'User' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.profile.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_profile_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.profile.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_scheduled_sends_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'batch_id': 'YOUR_BATCH_ID', + 'status': 'pause' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.user.scheduled_sends.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_user_scheduled_sends_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.scheduled_sends.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_scheduled_sends__batch_id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'status': 'pause' +}"; + var batch_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.user.scheduled_sends._(batch_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_user_scheduled_sends__batch_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var batch_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.scheduled_sends._(batch_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_scheduled_sends__batch_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var batch_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.user.scheduled_sends._(batch_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_user_settings_enforced_tls_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'require_tls': true, + 'require_valid_cert': false +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.settings.enforced_tls.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_settings_enforced_tls_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.settings.enforced_tls.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_username_put() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'username': 'test_username' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.username.put(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_username_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.username.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_webhooks_event_settings_patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'bounce': true, + 'click': true, + 'deferred': true, + 'delivered': true, + 'dropped': true, + 'enabled': true, + 'group_resubscribe': true, + 'group_unsubscribe': true, + 'open': true, + 'processed': true, + 'spam_report': true, + 'unsubscribe': true, + 'url': 'url' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.webhooks._("event").settings.patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_webhooks_event_settings_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.webhooks._("event").settings.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_webhooks_event_test_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'url': 'url' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.user.webhooks._("event").test.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_user_webhooks_parse_settings_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.webhooks.parse.settings.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_user_webhooks_parse_stats_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'aggregated_by': 'day', + 'end_date': '2016-04-01', + 'limit': 'test_string', + 'offset': 'test_string', + 'start_date': '2016-01-01' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.user.webhooks.parse.stats.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'automatic_security': false, + 'custom_spf': true, + 'default': true, + 'domain': 'example.com', + 'ips': [ + '192.168.1.1', + '192.168.1.2' + ], + 'subdomain': 'news', + 'username': 'john@example.com' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.whitelabel.domains.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_whitelabel_domains_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'domain': 'test_string', + 'exclude_subusers': 'true', + 'limit': 1, + 'offset': 1, + 'username': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains_default_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains._("default").get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains_subuser_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains.subuser.get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains_subuser_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.whitelabel.domains.subuser.delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_whitelabel_domains__domain_id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'custom_spf': true, + 'default': false +}"; + var domain_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains._(domain_id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains__domain_id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var domain_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains._(domain_id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains__domain_id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var domain_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.whitelabel.domains._(domain_id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_whitelabel_domains__domain_id__subuser_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'username': 'jane@example.com' +}"; + var domain_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.whitelabel.domains._(domain_id).subuser.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_whitelabel_domains__id__ips_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'ip': '192.168.0.1' +}"; + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains._(id).ips.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains__id__ips__ip__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + var ip = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains._(id).ips._(ip).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_domains__id__validate_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.domains._(id).validate.post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_ips_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'domain': 'example.com', + 'ip': '192.168.1.1', + 'subdomain': 'email' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.whitelabel.ips.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_whitelabel_ips_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'ip': 'test_string', + 'limit': 1, + 'offset': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.ips.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_ips__id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.ips._(id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_ips__id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.whitelabel.ips._(id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_whitelabel_ips__id__validate_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.ips._(id).validate.post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'default': true, + 'domain': 'example.com', + 'subdomain': 'mail' +}"; + string queryParams = @"{ + 'limit': 1, + 'offset': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "201"); + dynamic response = sg.client.whitelabel.links.post(requestBody: data, queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); + } + + [Test] + public void test_whitelabel_links_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'limit': 1 +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links_default_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'domain': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links._("default").get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links_subuser_get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'username': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links.subuser.get(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links_subuser_delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string queryParams = @"{ + 'username': 'test_string' +}"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.whitelabel.links.subuser.delete(queryParams: queryParams, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_whitelabel_links__id__patch() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'default': true +}"; + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links._(id).patch(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links__id__get() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links._(id).get(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links__id__delete() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "204"); + dynamic response = sg.client.whitelabel.links._(id).delete(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.NoContent); + } + + [Test] + public void test_whitelabel_links__id__validate_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + var id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links._(id).validate.post(requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + + [Test] + public void test_whitelabel_links__link_id__subuser_post() + { + string _apiKey = "SendGrid API Key"; + string host = ""; + if( Environment.GetEnvironmentVariable("TRAVIS") == "true" ) { + host = Environment.GetEnvironmentVariable("MOCK_HOST"); + } else { + host = "http://localhost:4010"; + } + dynamic sg = new SendGrid.SendGridAPIClient(_apiKey, host); + string data = @"{ + 'username': 'jane@example.com' +}"; + var link_id = "test_url_param"; + Dictionary headers = new Dictionary(); + headers.Clear(); + headers.Add("X-Mock", "200"); + dynamic response = sg.client.whitelabel.links._(link_id).subuser.post(requestBody: data, requestHeaders: headers); + Assert.AreEqual(response.StatusCode, HttpStatusCode.OK); + } + } } diff --git a/SendGrid/UnitTest/UnitTests.csproj b/SendGrid/UnitTest/UnitTests.csproj index d6ef8ae65..68ea8512a 100644 --- a/SendGrid/UnitTest/UnitTests.csproj +++ b/SendGrid/UnitTest/UnitTests.csproj @@ -8,7 +8,7 @@ Properties UnitTest UnitTest - v4.5 + v4.5.2 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -28,7 +28,7 @@ 4 - pdbonly + none true bin\Release\ TRACE @@ -67,8 +67,13 @@ ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll False + + ..\packages\SendGrid.CSharp.HTTP.Client.2.0.1\lib\SendGrid.CSharp.HTTP.Client.dll + True + + @@ -113,7 +118,7 @@ -