diff options
author | Chad T <chad@tolkien.id.au> | 2017-04-25 10:43:58 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-25 10:43:58 +1000 |
commit | 05da6905fac19035a78a7946d1cf0403043c5b22 (patch) | |
tree | 603b17f4897eeb8b803f10593b28877420b6e469 /tests/TinyPng.Tests/Extensions.cs | |
parent | 8213c3425c799ea5b79305cb20ef51adbd5aa97d (diff) | |
download | TinyPNG-origin/release.zip TinyPNG-origin/release.tar.gz TinyPNG-origin/release.tar.bz2 |
Merging in for V3 release (#18)origin/release
* fixed errors in the readme
* Deleted ncrunch bits.
* Add ncrunch to gitignore
* appveyor WIP
* appveyor wip
* appveyor wip
* AV has bash?!
* appveyor wip
* added badge to readme
* appveyor wip
* appveyor.yml wip
* appveyor wip, don't run tests twice
* appveyor last time!
* test improvements #1
* more test coverage
* more test coverage
* more testing, resize operations
* exception tests
* yet more tests
* test improvements #1 (#13)
* test improvements #1
* more test coverage
* more test coverage
* more testing, resize operations
* exception tests
* yet more tests
* tests
* actually builds
* on the round to 100%
* fixed final failing test
* fixed code which would generate stack overflow exceptions.. woops
* Delete build.sh
* Update .travis.yml
* Update .travis.yml
* Update .travis.yml
* Dropping OSX CI builds
* Update README.md
* Version 3 release (#14)
* refactored the api
* updating readme
* internalsvisibleto
* make httpclient static
* WIP
* cleanup
* further cleanup
* Final update to readme
* add test for non success on compress operation
* increase test coverage
* Remove package.json, unneeded
* CSProj migration (#16)
* migrating to csproj
* Appveyor
* appveyor
* cleanup csprojs
* ditched assembly info
* av
* av
* av
* travis
* travis
* fix AV
* fix AV
* include resources to output
* include resources to output
* project json accidentaly made a return
* update version
* killed off xproj
* v3 refactor
* test open cover
* opencover
* opencover
* yet more travis work
* spell language correctly
* can we get mac builds
* travis
* travis
* travis
* travis
* remove sudo
* Use 2017 release image on AV
Diffstat (limited to 'tests/TinyPng.Tests/Extensions.cs')
-rw-r--r-- | tests/TinyPng.Tests/Extensions.cs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/TinyPng.Tests/Extensions.cs b/tests/TinyPng.Tests/Extensions.cs new file mode 100644 index 0000000..f9528b9 --- /dev/null +++ b/tests/TinyPng.Tests/Extensions.cs @@ -0,0 +1,94 @@ +using Newtonsoft.Json;
+using System;
+using System.IO;
+using System.Net.Http;
+
+namespace TinyPng.Tests
+{
+ static class Extensions
+ {
+ public static FakeResponseHandler Compress(this FakeResponseHandler fakeResponse)
+ {
+ var content = new TinyPngApiResult()
+ {
+ Input = new TinyPngApiInput
+ {
+ Size = 18031,
+ Type = "image/jpeg"
+ },
+ Output = new TinyPngApiOutput
+ {
+ Width = 400,
+ Height = 400,
+ Size = 16646,
+ Type = "image/jpeg",
+ Ratio = 0.9232f,
+ Url = "https://api.tinify.com/output"
+ }
+ };
+ var compressResponseMessage = new HttpResponseMessage
+ {
+ StatusCode = System.Net.HttpStatusCode.Created,
+ Content = new StringContent(JsonConvert.SerializeObject(content)),
+ };
+ compressResponseMessage.Headers.Location = new Uri("https://api.tinify.com/output");
+ compressResponseMessage.Headers.Add("Compression-Count", "99");
+
+ fakeResponse.AddFakePostResponse(new Uri("https://api.tinify.com/shrink"), compressResponseMessage);
+ return fakeResponse;
+ }
+
+ public static FakeResponseHandler CompressAndFail(this FakeResponseHandler fakeResponse)
+ {
+ var errorApiObject = new TinyPngApiException(400, "reason", "title", "message");
+
+ var compressResponseMessage = new HttpResponseMessage
+ {
+ StatusCode = System.Net.HttpStatusCode.BadRequest,
+ Content = new StringContent(JsonConvert.SerializeObject(errorApiObject))
+ };
+ fakeResponse.AddFakePostResponse(new Uri("https://api.tinify.com/shrink"), compressResponseMessage);
+ return fakeResponse;
+ }
+
+ public static FakeResponseHandler Download(this FakeResponseHandler fakeResponse)
+ {
+ var compressedCatStream = File.OpenRead(TinyPngTests.CompressedCat);
+ var outputResponseMessage = new HttpResponseMessage
+ {
+ Content = new StreamContent(compressedCatStream),
+ StatusCode = System.Net.HttpStatusCode.OK
+ };
+
+ fakeResponse.AddFakeGetResponse(new Uri("https://api.tinify.com/output"), outputResponseMessage);
+ return fakeResponse;
+ }
+
+ public static FakeResponseHandler Resize(this FakeResponseHandler fakeResponse)
+ {
+ var resizedCatStream = File.OpenRead(TinyPngTests.ResizedCat);
+ var resizeMessage = new HttpResponseMessage
+ {
+ StatusCode = System.Net.HttpStatusCode.OK,
+ Content = new StreamContent(resizedCatStream)
+ };
+ resizeMessage.Headers.Add("Image-Width", "150");
+ resizeMessage.Headers.Add("Image-Height", "150");
+
+ fakeResponse.AddFakePostResponse(new Uri("https://api.tinify.com/output"), resizeMessage);
+ return fakeResponse;
+ }
+
+ public static FakeResponseHandler S3(this FakeResponseHandler fakeResponse)
+ {
+ var amazonMessage = new HttpResponseMessage
+ {
+ StatusCode = System.Net.HttpStatusCode.OK
+ };
+ amazonMessage.Headers.Add("Location", "https://s3-ap-southeast-2.amazonaws.com/tinypng-test-bucket/path.jpg");
+
+ fakeResponse.AddFakePostResponse(new Uri("https://api.tinify.com/output"), amazonMessage);
+ return fakeResponse;
+ }
+ }
+}
|