public async Task CompressAndStoreToS3Throws() { var pngx = new TinyPngClient(apiKey, new HttpClient(new FakeResponseHandler().Compress().S3())); var result = await pngx.Compress(Cat); await Assert.ThrowsAsync <ArgumentNullException>(async() => await pngx.SaveCompressedImageToAmazonS3(result, null, string.Empty)); //S3 configuration has not been set await Assert.ThrowsAsync <InvalidOperationException>(async() => await pngx.SaveCompressedImageToAmazonS3(result, path: string.Empty)); }
public async Task CompressAndStoreToS3ShouldThrowIfS3HasNotBeenConfigured() { var pngx = new TinyPngClient(apiKey, new HttpClient(new FakeResponseHandler().Compress().S3())); var result = await pngx.Compress(Cat); await Assert.ThrowsAsync <ArgumentNullException>(async() => await pngx.SaveCompressedImageToAmazonS3(null, "bucket/path.jpg")); await Assert.ThrowsAsync <InvalidOperationException>(async() => await pngx.SaveCompressedImageToAmazonS3(result, string.Empty)); await Assert.ThrowsAsync <InvalidOperationException>(async() => await pngx.SaveCompressedImageToAmazonS3(result, "bucket/path.jpg")); }
public async Task CompressAndStoreToS3FooBar() { var pngx = new TinyPngClient(apiKey, new HttpClient(new FakeResponseHandler().Compress().S3AndFail())); var result = await pngx.Compress(Cat); await Assert.ThrowsAsync <TinyPngApiException>(async() => await pngx.SaveCompressedImageToAmazonS3(result, new AmazonS3Configuration(ApiKey, ApiAccessKey, "tinypng-test-bucket", "ap-southeast-2"), "path")); }
public async Task CompressAndStoreToS3WithOptionsPassedIntoConstructor() { var pngx = new TinyPngClient(apiKey, new AmazonS3Configuration(ApiKey, ApiAccessKey, "tinypng-test-bucket", "ap-southeast-2"), new HttpClient(new FakeResponseHandler().Compress().S3())); var result = await pngx.Compress(Cat); var sendToAmazon = (await pngx.SaveCompressedImageToAmazonS3(result, "path.jpg")).ToString(); Assert.Equal("https://s3-ap-southeast-2.amazonaws.com/tinypng-test-bucket/path.jpg", sendToAmazon); }
public async Task CompressAndStoreToS3WithOptionsPassedIntoConstructor() { var pngx = new TinyPngClient(apiKey, new AmazonS3Configuration(ApiKey, ApiAccessKey, "tinypng-test-bucket", "ap-southeast-2")); pngx.httpClient = new HttpClient(new FakeResponseHandler() .Compress() .S3()); var result = await pngx.Compress(Cat); var sendToAmazon = (await pngx.SaveCompressedImageToAmazonS3(result, "path.jpg")).ToString(); Assert.Equal("https://s3-ap-southeast-2.amazonaws.com/tinypng-test-bucket/path.jpg", sendToAmazon); }
public async Task CompressAndStoreToS3Throws() { var pngx = new TinyPngClient(apiKey); pngx.httpClient = new HttpClient(new FakeResponseHandler() .Compress() .S3()); var result = await pngx.Compress(Cat); await Assert.ThrowsAsync<InvalidOperationException>(async () => await pngx.SaveCompressedImageToAmazonS3(result, path: string.Empty)); }
public async Task CompressAndStoreToS3ShouldThrowIfS3HasNotBeenConfigured() { var pngx = new TinyPngClient(apiKey); pngx.httpClient = new HttpClient(new FakeResponseHandler() .Compress() .S3()); var result = await pngx.Compress(Cat); await Assert.ThrowsAsync<ArgumentNullException>(async () => await pngx.SaveCompressedImageToAmazonS3(null, "bucket/path.jpg")); await Assert.ThrowsAsync<InvalidOperationException>(async () => await pngx.SaveCompressedImageToAmazonS3(result, string.Empty)); await Assert.ThrowsAsync<InvalidOperationException>(async () => await pngx.SaveCompressedImageToAmazonS3(result, "bucket/path.jpg")); }