示例#1
0
        public async Task ResizingCoverResizeOperation()
        {
            var pngx = new TinyPngClient(apiKey);
            pngx.httpClient = new HttpClient(new FakeResponseHandler()
                .Compress()
                .Resize());

            var result = await pngx.Compress(Cat);

            var resized = await pngx.Resize(result, new CoverResizeOperation(150, 150));

            var resizedImageByteData = await resized.GetImageByteData();

            Assert.Equal(5970, resizedImageByteData.Length);

        }
示例#2
0
        public async Task ResizingCoverResizeOperationThrowsWithInvalidParams()
        {
            var pngx = new TinyPngClient(apiKey);
            pngx.httpClient = new HttpClient(new FakeResponseHandler()
                .Compress()
                .Resize());

            var result = await pngx.Compress(Cat);

            await Assert.ThrowsAsync<ArgumentException>(async () => await pngx.Resize(result, new CoverResizeOperation(0, 150)));
            await Assert.ThrowsAsync<ArgumentException>(async () => await pngx.Resize(result, new CoverResizeOperation(150, 0)));

        }
示例#3
0
        public async Task ResizingOperationThrows()
        {
            var pngx = new TinyPngClient(apiKey);
            pngx.httpClient = new HttpClient(new FakeResponseHandler()
                .Compress()
                .Resize());

            var result = await pngx.Compress(Cat);

            await Assert.ThrowsAsync<ArgumentNullException>(async () => await pngx.Resize(null, 150, 150));
            await Assert.ThrowsAsync<ArgumentNullException>(async () => await pngx.Resize(null, null));
            await Assert.ThrowsAsync<ArgumentNullException>(async () => await pngx.Resize(result, null));
            await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await pngx.Resize(result, 0, 150));
            await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await pngx.Resize(result, 150, 0));

        }