diff --git a/.gitignore b/.gitignore index 725e07c..a9e8711 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,12 @@ -CSharpHTTPClient/CSharpHTTPClient.sln.DotSettings.user -CSharpHTTPClient/bin/ -Example/bin/ -CSharpHTTPClient/obj/ -Example/obj/ -UnitTest/bin/ -UnitTest/obj/ -*.suo -CSharpHTTPClient/*/bin/ -CSharpHTTPClient/*/obj/ +obj +bin +.vs +project.lock.json +TestResult.xml .DS_store -CSharpHTTPClient/CSharpHTTPClient.userprefs -CSharpHTTPClient/packages/ -CSharpHTTPClient/CSharpHTTPClient.sln.VisualState.xml -*.pfx -*.PublicKey \ No newline at end of file +CSharpHTTPClient.userprefs +*.sln.DotSettings.user +*.xproj.user +*.suo +*.PublicKey +*.pfx \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index f62e705..c2fda3d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,41 @@ language: csharp -solution: CSharpHTTPClient/CSharpHTTPClient.sln + +#dotnet cli require Ubuntu 14.04 +sudo: required +dist: trusty + +addons: + apt: + packages: + - gettext + - libcurl4-openssl-dev + - libicu-dev + - libssl-dev + - libunwind8 + - zlib1g + +os: + - linux + env: - matrix: - secure: KJrQ+NfmzlgCSXRyqeAMDGZUG6GO4/+xk1T0wGy1BgVz8seo/fDWL8osWEljB4Sj05sfFj7CM+rociwL6sdVyqCiHbCAM7XuHs58D+4Tlh5pGHL+G1qOl65/pDl0ulq+M7PwDxHPZ60/oyH2a16t5jtD9e4W31y2fXzEbHGLHXg= -install: -- nuget restore CSharpHTTPClient/CSharpHTTPClient.sln -- nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner + matrix: + - CLI_VERSION=1.0.0-preview2-003121 + - CLI_VERSION=Latest + +matrix: + allow_failures: + - env: CLI_VERSION=Latest + +before_install: + # Download script to install dotnet cli + - if test "$CLI_OBTAIN_URL" == ""; then export CLI_OBTAIN_URL="https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.sh"; fi + - curl -L --create-dirs $CLI_OBTAIN_URL -o ./scripts/obtain/install.sh + - find ./scripts -name "*.sh" -exec chmod +x {} \; + - export DOTNET_INSTALL_DIR="$PWD/.dotnetcli" + # use bash to workaround bug https://github.com/dotnet/cli/issues/1725 + - sudo bash ./scripts/obtain/install.sh --channel "preview" --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR" --no-path + # add dotnet to PATH + - export PATH="$DOTNET_INSTALL_DIR:$PATH" + script: -- xbuild /p:Configuration=Release CSharpHTTPClient/CSharpHTTPClient.sln -- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe UnitTest/bin/Release/UnitTest.dll -domain:None -notifications: - hipchat: - rooms: - secure: T8r/eNzevZXJDmSK7ZKG+t/Vx0cENHIMWVuKbt3RSYbXl6QsWv8UTPamFSkLP0zbcCyGQ7d+QKaEc18ffCtiBV9MXPy8Q1XFGzKxr5/GnwMx4p0ArTqbFLCyl3JuXBmCGouWG+ulb9eOGUFc6L/4p2cwAfXf2oTcXYqosBnfoHg= - template: - - '%{repository} - Build %{build_number} on branch %{branch} by %{author}: %{message} - View on GitHub' - format: html + - ./build.sh \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e290fa..621ac41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.0.2] - 2016-06-16 +### Added +- Fix async, per https://github.com/sendgrid/sendgrid-csharp/issues/235 + +## [2.0.1] - 2016-06-03 +### Added +- Sign assembly with a strong name + +## [2.0.0] - 2016-06-03 +### Changed +- Made the Response variables non-redundant. e.g. response.ResponseBody becomes response.Body + ## [1.0.2] - 2016-03-17 ### Added -- We are live! \ No newline at end of file +- We are live! diff --git a/CSharpHTTPClient.sln b/CSharpHTTPClient.sln new file mode 100644 index 0000000..6136df1 --- /dev/null +++ b/CSharpHTTPClient.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{671B0509-1433-4E96-B89F-6E25F55B2B6E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{04880DC9-F242-43EF-A157-C868CEC92957}" + ProjectSection(SolutionItems) = preProject + global.json = global.json + EndProjectSection +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CSharpHTTPClient", "src\CSharpHTTPClient\CSharpHTTPClient.xproj", "{D7B5CD21-3F54-432B-B9F7-4CE2F81FFA5F}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7EF30ACB-B177-41CE-8E18-E886D2BCB500}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UnitTest", "test\UnitTest\UnitTest.xproj", "{98AE955C-242B-4300-9080-BE4F01CFF1D3}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Example", "src\Example\Example.xproj", "{5AD0DF79-66EB-4F44-B569-B7EE84E00D40}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D7B5CD21-3F54-432B-B9F7-4CE2F81FFA5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7B5CD21-3F54-432B-B9F7-4CE2F81FFA5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7B5CD21-3F54-432B-B9F7-4CE2F81FFA5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7B5CD21-3F54-432B-B9F7-4CE2F81FFA5F}.Release|Any CPU.Build.0 = Release|Any CPU + {98AE955C-242B-4300-9080-BE4F01CFF1D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98AE955C-242B-4300-9080-BE4F01CFF1D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98AE955C-242B-4300-9080-BE4F01CFF1D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98AE955C-242B-4300-9080-BE4F01CFF1D3}.Release|Any CPU.Build.0 = Release|Any CPU + {5AD0DF79-66EB-4F44-B569-B7EE84E00D40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5AD0DF79-66EB-4F44-B569-B7EE84E00D40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5AD0DF79-66EB-4F44-B569-B7EE84E00D40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5AD0DF79-66EB-4F44-B569-B7EE84E00D40}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {D7B5CD21-3F54-432B-B9F7-4CE2F81FFA5F} = {671B0509-1433-4E96-B89F-6E25F55B2B6E} + {98AE955C-242B-4300-9080-BE4F01CFF1D3} = {7EF30ACB-B177-41CE-8E18-E886D2BCB500} + {5AD0DF79-66EB-4F44-B569-B7EE84E00D40} = {671B0509-1433-4E96-B89F-6E25F55B2B6E} + EndGlobalSection +EndGlobal diff --git a/CSharpHTTPClient/App.config b/CSharpHTTPClient/App.config deleted file mode 100644 index d1428ad..0000000 --- a/CSharpHTTPClient/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/CSharpHTTPClient/CSharpHTTPClient.csproj b/CSharpHTTPClient/CSharpHTTPClient.csproj deleted file mode 100644 index 0399794..0000000 --- a/CSharpHTTPClient/CSharpHTTPClient.csproj +++ /dev/null @@ -1,76 +0,0 @@ - - - - - Debug - AnyCPU - {26C4841F-EC62-4EC7-B16E-3A7386EA36DC} - Library - Properties - SendGrid.CSharp.HTTP.Client - SendGrid.CSharp.HTTP.Client - v4.5 - 512 - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - false - - - csharphttpclient.pfx - - - - - - ..\..\sendgrid-csharp\SendGrid\SendGrid\bin\Debug\System.Net.Http.Formatting.dll - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/CSharpHTTPClient/CSharpHTTPClient.sln b/CSharpHTTPClient/CSharpHTTPClient.sln deleted file mode 100644 index 6a910e4..0000000 --- a/CSharpHTTPClient/CSharpHTTPClient.sln +++ /dev/null @@ -1,34 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpHTTPClient", "CSharpHTTPClient.csproj", "{26C4841F-EC62-4EC7-B16E-3A7386EA36DC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "..\Example\Example.csproj", "{490AD14D-B821-435A-BEC8-F4DFE34E6556}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "..\UnitTest\UnitTest.csproj", "{DF845C59-4B39-4A8A-AC89-E5336B57076B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {26C4841F-EC62-4EC7-B16E-3A7386EA36DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {26C4841F-EC62-4EC7-B16E-3A7386EA36DC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {26C4841F-EC62-4EC7-B16E-3A7386EA36DC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {26C4841F-EC62-4EC7-B16E-3A7386EA36DC}.Release|Any CPU.Build.0 = Release|Any CPU - {490AD14D-B821-435A-BEC8-F4DFE34E6556}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {490AD14D-B821-435A-BEC8-F4DFE34E6556}.Debug|Any CPU.Build.0 = Debug|Any CPU - {490AD14D-B821-435A-BEC8-F4DFE34E6556}.Release|Any CPU.ActiveCfg = Release|Any CPU - {490AD14D-B821-435A-BEC8-F4DFE34E6556}.Release|Any CPU.Build.0 = Release|Any CPU - {DF845C59-4B39-4A8A-AC89-E5336B57076B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DF845C59-4B39-4A8A-AC89-E5336B57076B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DF845C59-4B39-4A8A-AC89-E5336B57076B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DF845C59-4B39-4A8A-AC89-E5336B57076B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Example/App.config b/Example/App.config deleted file mode 100644 index d1428ad..0000000 --- a/Example/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Example/Example.csproj b/Example/Example.csproj deleted file mode 100644 index d5dcaac..0000000 --- a/Example/Example.csproj +++ /dev/null @@ -1,68 +0,0 @@ - - - - - Debug - AnyCPU - {490AD14D-B821-435A-BEC8-F4DFE34E6556} - Exe - Properties - Example - Example - v4.5 - 512 - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - {26c4841f-ec62-4ec7-b16e-3a7386ea36dc} - CSharpHTTPClient - - - - - \ No newline at end of file diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj deleted file mode 100644 index 6635286..0000000 --- a/UnitTest/UnitTest.csproj +++ /dev/null @@ -1,111 +0,0 @@ - - - - Debug - AnyCPU - {DF845C59-4B39-4A8A-AC89-E5336B57076B} - Library - Properties - UnitTest - UnitTest - v4.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - ..\CSharpHTTPClient\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.dll - True - - - ..\CSharpHTTPClient\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.interfaces.dll - True - - - ..\CSharpHTTPClient\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.framework.dll - True - - - ..\CSharpHTTPClient\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.util.dll - True - - - ..\CSharpHTTPClient\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - True - - - - - - - - - - - - - - - - - - - {26c4841f-ec62-4ec7-b16e-3a7386ea36dc} - CSharpHTTPClient - - - - - - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file diff --git a/UnitTest/packages.config b/UnitTest/packages.config deleted file mode 100644 index cfc878f..0000000 --- a/UnitTest/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..3d8448c --- /dev/null +++ b/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +dotnet restore + +# Build Library and Example +for path in src/*/project.json; do + dirname="$(dirname "${path}")" + dotnet build ${dirname} -c Release +done + +# Run Unit Tests +dotnet build test/UnitTest/project.json -f netcoreapp1.0 -c Release +dotnet run -p test/UnitTest/project.json -f netcoreapp1.0 -c Release diff --git a/global.json b/global.json new file mode 100644 index 0000000..e793049 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "projects": [ "src", "test" ], + "sdk": { + "version": "1.0.0-preview2-003121" + } +} diff --git a/src/CSharpHTTPClient/CSharpHTTPClient.xproj b/src/CSharpHTTPClient/CSharpHTTPClient.xproj new file mode 100644 index 0000000..7f47c84 --- /dev/null +++ b/src/CSharpHTTPClient/CSharpHTTPClient.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + d7b5cd21-3f54-432b-b9f7-4ce2f81ffa5f + SendGrid.CSharp.HTTP.Client + ..\..\artifacts\obj\$(MSBuildProjectName) + .\bin\ + + + 2.0 + + + True + + + \ No newline at end of file diff --git a/CSharpHTTPClient/Client.cs b/src/CSharpHTTPClient/Client.cs similarity index 92% rename from CSharpHTTPClient/Client.cs rename to src/CSharpHTTPClient/Client.cs index 4fa9148..e8421db 100644 --- a/CSharpHTTPClient/Client.cs +++ b/src/CSharpHTTPClient/Client.cs @@ -7,8 +7,13 @@ using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; -using System.Web.Script.Serialization; +#if NET45 using System.Web; +using System.Web.Script.Serialization; +#else +using Newtonsoft.Json; +using Microsoft.AspNetCore.WebUtilities; +#endif namespace SendGrid.CSharp.HTTP.Client { @@ -38,8 +43,12 @@ public Response(HttpStatusCode statusCode, HttpContent responseBody, HttpRespons /// Dictionary object representation of HttpContent public virtual Dictionary DeserializeResponseBody(HttpContent content) { +#if NET45 JavaScriptSerializer jss = new JavaScriptSerializer(); var dsContent = jss.Deserialize>(content.ReadAsStringAsync().Result); +#else + var dsContent = JsonConvert.DeserializeObject>(content.ReadAsStringAsync().Result); +#endif return dsContent; } @@ -64,7 +73,7 @@ public virtual Dictionary DeserializeResponseHeaders(HttpRespons public class Client : DynamicObject { public string Host; - public Dictionary RequestHeaders; + public Dictionary RequestHeaders; public string Version; public string UrlPath; public string MediaType; @@ -81,10 +90,10 @@ public enum Methods /// API version, override AddVersion to customize /// Path to endpoint (e.g. /path/to/endpoint) /// Fluent interface to a REST API - public Client(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) + public Client(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) { Host = host; - if(requestHeaders != null) + if (requestHeaders != null) { AddRequestHeader(requestHeaders); } @@ -111,7 +120,7 @@ private string BuildUrl(string queryParams = null) { string endpoint = null; - if( Version != null) + if (Version != null) { endpoint = Host + "/" + Version + UrlPath; } @@ -122,9 +131,14 @@ private string BuildUrl(string queryParams = null) if (queryParams != null) { +#if NET45 JavaScriptSerializer jss = new JavaScriptSerializer(); var ds_query_params = jss.Deserialize>(queryParams); var query = HttpUtility.ParseQueryString(string.Empty); +#else + var ds_query_params = JsonConvert.DeserializeObject>(queryParams); + var query = QueryHelpers.ParseQuery(string.Empty); +#endif foreach (var pair in ds_query_params) { query[pair.Key] = pair.Value.ToString(); @@ -162,7 +176,7 @@ private Client BuildClient(string name = null) /// /// Add the authorization header, override to customize /// - /// Authoriztion header + /// Authorization header /// Authorization value to add to the header public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair header) { @@ -218,7 +232,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o return true; } - if( Enum.IsDefined(typeof(Methods), binder.Name.ToUpper())) + if (Enum.IsDefined(typeof(Methods), binder.Name.ToUpper())) { string queryParams = null; string requestBody = null; @@ -261,7 +275,7 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o /// Response object public async virtual Task MakeRequest(HttpClient client, HttpRequestMessage request) { - HttpResponseMessage response = await client.SendAsync(request); + HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false); return new Response(response.StatusCode, response.Content, response.Headers); } @@ -284,7 +298,7 @@ private async Task RequestAsync(string method, String requestBody = nu // Build the request headers client.DefaultRequestHeaders.Accept.Clear(); - if(RequestHeaders != null) + if (RequestHeaders != null) { foreach (KeyValuePair header in RequestHeaders) { @@ -318,7 +332,7 @@ private async Task RequestAsync(string method, String requestBody = nu RequestUri = new Uri(endpoint), Content = content }; - return await MakeRequest(client, request); + return await MakeRequest(client, request).ConfigureAwait(false); } catch (Exception ex) diff --git a/CSharpHTTPClient/Properties/AssemblyInfo.cs b/src/CSharpHTTPClient/Properties/AssemblyInfo.cs similarity index 94% rename from CSharpHTTPClient/Properties/AssemblyInfo.cs rename to src/CSharpHTTPClient/Properties/AssemblyInfo.cs index 7f52500..f68167d 100644 --- a/CSharpHTTPClient/Properties/AssemblyInfo.cs +++ b/src/CSharpHTTPClient/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // 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.2")] -[assembly: AssemblyFileVersion("1.0.2")] +[assembly: AssemblyVersion("2.0.4")] +[assembly: AssemblyFileVersion("2.0.4")] \ No newline at end of file diff --git a/src/CSharpHTTPClient/project.json b/src/CSharpHTTPClient/project.json new file mode 100644 index 0000000..d2a945e --- /dev/null +++ b/src/CSharpHTTPClient/project.json @@ -0,0 +1,31 @@ +{ + "version": "1.0.2", + "description": "HTTP REST client, simplified for C Sharp", + "authors": [ "SendGrid" ], + "packOptions": { + "projectUrl": "https://github.com/sendgrid/csharp-http-client", + "licenseUrl": "https://github.com/sendgrid/csharp-http-client/blob/master/LICENSE" + }, + "frameworks": { + "net45": { + "frameworkAssemblies": { + "System": "", + "System.Net.Http": "", + "System.Web": "", + "System.Web.Extensions": "", + "Microsoft.CSharp": "" + } + }, + "netstandard1.6": { + "dependencies": { + "Microsoft.AspNetCore.WebUtilities": "1.0.0", + "Newtonsoft.Json": "9.0.1", + "System.Net.Http": "4.1.0", + "System.Runtime.InteropServices": "4.1.0" + } + } + }, + "tooling": { + "defaultNamespace": "SendGrid.CSharp.HTTP.Client" + } +} diff --git a/src/Example/Example.xproj b/src/Example/Example.xproj new file mode 100644 index 0000000..a757186 --- /dev/null +++ b/src/Example/Example.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 5ad0df79-66eb-4f44-b569-b7ee84e00d40 + Example + ..\..\artifacts\obj\$(MSBuildProjectName) + .\bin\ + + + 2.0 + + + \ No newline at end of file diff --git a/Example/Example.cs b/src/Example/Program.cs similarity index 87% rename from Example/Example.cs rename to src/Example/Program.cs index 309dc4d..bf27e75 100644 --- a/Example/Example.cs +++ b/src/Example/Program.cs @@ -1,20 +1,28 @@ -using System; +using SendGrid.CSharp.HTTP.Client; +using System; using System.Collections.Generic; -using SendGrid.CSharp.HTTP.Client; +#if DNX451 using System.Web.Script.Serialization; +#else +using Newtonsoft.Json; +#endif // This is a working example, using the SendGrid API // You will need a SendGrid account and an active API Key // They key should be stored in an environment variable called SENDGRID_APIKEY namespace Example { - class Example + public class Program { - static void Main(string[] args) + public static void Main(string[] args) { String host = "https://e9sk3d3bfaikbpdq7.stoplight-proxy.io"; Dictionary globalRequestHeaders = new Dictionary(); +#if DNX451 string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); +#else + string apiKey = "TODO"; +#endif globalRequestHeaders.Add("Authorization", "Bearer " + apiKey); globalRequestHeaders.Add("Content-Type", "application/json"); @@ -27,15 +35,15 @@ static void Main(string[] args) }"; Dictionary requestHeaders = new Dictionary(); requestHeaders.Add("X-Test", "test"); - dynamic response = client.version("v3").api_keys.get(queryParams: queryParams, requestHeaders: requestHeaders); + dynamic response = client.api_keys.get(queryParams: queryParams, requestHeaders: requestHeaders); // Console.WriteLine(response.StatusCode); // Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); // Console.WriteLine(response.ResponseHeaders.ToString()); var dssResponseBody = response.DeserializeResponseBody(response.ResponseBody); - foreach ( var value in dssResponseBody["result"]) + foreach (var value in dssResponseBody["result"]) { - Console.WriteLine("name: {0}, api_key_id: {1}",value["name"], value["api_key_id"]); + Console.WriteLine("name: {0}, api_key_id: {1}", value["name"], value["api_key_id"]); } var dssResponseHeaders = response.DeserializeResponseHeaders(response.ResponseHeaders); @@ -62,8 +70,12 @@ static void Main(string[] args) Console.WriteLine(response.StatusCode); Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); Console.WriteLine(response.ResponseHeaders.ToString()); +#if DNX451 JavaScriptSerializer jss = new JavaScriptSerializer(); var ds_response = jss.Deserialize>(response.ResponseBody.ReadAsStringAsync().Result); +#else + var ds_response = JsonConvert.DeserializeObject>(response.ResponseBody.ReadAsStringAsync().Result); +#endif string api_key_id = ds_response["api_key_id"]; Console.WriteLine("\n\nPress any key to continue to GET single."); diff --git a/Example/Properties/AssemblyInfo.cs b/src/Example/Properties/AssemblyInfo.cs similarity index 84% rename from Example/Properties/AssemblyInfo.cs rename to src/Example/Properties/AssemblyInfo.cs index 9313b64..0a19aea 100644 --- a/Example/Properties/AssemblyInfo.cs +++ b/src/Example/Properties/AssemblyInfo.cs @@ -1,8 +1,7 @@ using System.Reflection; -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("Example")] @@ -14,13 +13,13 @@ [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)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("490ad14d-b821-435a-bec8-f4dfe34e6556")] +[assembly: Guid("5ad0df79-66eb-4f44-b569-b7ee84e00d40")] // Version information for an assembly consists of the following four values: // @@ -32,5 +31,5 @@ // 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("2.0.4")] +[assembly: AssemblyFileVersion("2.0.4")] diff --git a/src/Example/project.json b/src/Example/project.json new file mode 100644 index 0000000..712f386 --- /dev/null +++ b/src/Example/project.json @@ -0,0 +1,31 @@ +{ + "version": "1.0.0-*", + "description": "Example Console Application", + "authors": [ "SendGrid" ], + + "buildOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "CSharpHTTPClient": "1.0.2", + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + }, + + "commands": { + "run": "Example" + }, + + "tooling": { + "defaultNamespace": "Example" + } +} diff --git a/test/UnitTest/MockClient.cs b/test/UnitTest/MockClient.cs new file mode 100644 index 0000000..acf0c93 --- /dev/null +++ b/test/UnitTest/MockClient.cs @@ -0,0 +1,25 @@ +using SendGrid.CSharp.HTTP.Client; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace UnitTest +{ + // Mock the Client so that we intercept network calls + public class MockClient : Client + { + public MockClient(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) : base(host, requestHeaders, version, urlPath) + { + } + + public async override Task MakeRequest(HttpClient client, HttpRequestMessage request) + { + HttpResponseMessage response = new HttpResponseMessage(); + response.Content = new StringContent("{'test': 'test_content'}", Encoding.UTF8, "application/json"); + response.StatusCode = HttpStatusCode.OK; + return new Response(response.StatusCode, response.Content, response.Headers); + } + } +} diff --git a/test/UnitTest/Program.cs b/test/UnitTest/Program.cs new file mode 100644 index 0000000..2651741 --- /dev/null +++ b/test/UnitTest/Program.cs @@ -0,0 +1,20 @@ +using NUnit.Common; +using NUnitLite; +using System; +using System.Reflection; + +namespace UnitTest +{ + public class Program + { + public static void Main(string[] args) + { +#if DNX451 + new AutoRun().Execute(args); +#else + var writter = new ExtendedTextWrapper(Console.Out); + new AutoRun(typeof(Program).GetTypeInfo().Assembly).Execute(args, writter, Console.In); +#endif + } + } +} diff --git a/UnitTest/Properties/AssemblyInfo.cs b/test/UnitTest/Properties/AssemblyInfo.cs similarity index 84% rename from UnitTest/Properties/AssemblyInfo.cs rename to test/UnitTest/Properties/AssemblyInfo.cs index 899351a..aea948b 100644 --- a/UnitTest/Properties/AssemblyInfo.cs +++ b/test/UnitTest/Properties/AssemblyInfo.cs @@ -1,8 +1,7 @@ using System.Reflection; -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,13 +13,13 @@ [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)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("df845c59-4b39-4a8a-ac89-e5336b57076b")] +[assembly: Guid("98ae955c-242b-4300-9080-be4f01cff1d3")] // Version information for an assembly consists of the following four values: // @@ -32,5 +31,5 @@ // 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("2.0.4")] +[assembly: AssemblyFileVersion("2.0.4")] diff --git a/test/UnitTest/Properties/launchSettings.json b/test/UnitTest/Properties/launchSettings.json new file mode 100644 index 0000000..ec5d3e4 --- /dev/null +++ b/test/UnitTest/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "test": { + "commandName": "test", + "commandLineArgs": "-wait" + } + } +} \ No newline at end of file diff --git a/UnitTest/UnitTest.cs b/test/UnitTest/TestClient.cs similarity index 73% rename from UnitTest/UnitTest.cs rename to test/UnitTest/TestClient.cs index 89f0cd2..aeab068 100644 --- a/UnitTest/UnitTest.cs +++ b/test/UnitTest/TestClient.cs @@ -1,31 +1,13 @@ -using System; -using NUnit.Framework; +using NUnit.Framework; using SendGrid.CSharp.HTTP.Client; +using System; using System.Collections.Generic; -using System.Threading.Tasks; +using System.Net; using System.Net.Http; using System.Text; -using System.Net; namespace UnitTest { - - // Mock the Client so that we intercept network calls - public class MockClient : Client - { - public MockClient(string host, Dictionary requestHeaders = null, string version = null, string urlPath = null) : base (host, requestHeaders, version, urlPath) - { - } - - public async override Task MakeRequest(HttpClient client, HttpRequestMessage request) - { - HttpResponseMessage response = new HttpResponseMessage(); - response.Content = new StringContent("{'test': 'test_content'}", Encoding.UTF8, "application/json"); - response.StatusCode = HttpStatusCode.OK; - return new Response(response.StatusCode, response.Content, response.Headers); - } - } - [TestFixture] public class TestClient { diff --git a/test/UnitTest/UnitTest.xproj b/test/UnitTest/UnitTest.xproj new file mode 100644 index 0000000..44df9de --- /dev/null +++ b/test/UnitTest/UnitTest.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 98ae955c-242b-4300-9080-be4f01cff1d3 + UnitTest + ..\..\artifacts\obj\$(MSBuildProjectName) + .\bin\ + + + 2.0 + + + + \ No newline at end of file diff --git a/test/UnitTest/project.json b/test/UnitTest/project.json new file mode 100644 index 0000000..575602b --- /dev/null +++ b/test/UnitTest/project.json @@ -0,0 +1,32 @@ +{ + "version": "1.0.0-*", + "description": "UnitTest Console Application", + "authors": [ "SendGrid" ], + + "buildOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "CSharpHTTPClient": "1.0.2", + "NUnitLite": "3.4.0", + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + }, + + "commands": { + "test": "UnitTest" + }, + + "tooling": { + "defaultNamespace": "UnitTest" + } +}