Пример #1
0
        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);
        }
Пример #2
0
        public static FakeResponseHandler Compress(this FakeResponseHandler fakeResponse)
        {

            var content = new TinyPngApiResult();
            content.Input = new TinyPngApiInput
            {
                Size = 18031,
                Type = "image/jpeg"
            };
            content.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;
        }
Пример #3
0
        public TinyPngCompressResponse(HttpResponseMessage msg, HttpClient httpClient) : base(msg)
        {
            HttpClient = httpClient;

            //this is a cute trick to handle async in a ctor and avoid deadlocks
            ApiResult = Task.Run(() => Deserialize(msg)).GetAwaiter().GetResult();
            Input     = ApiResult.Input;
            Output    = ApiResult.Output;
        }
Пример #4
0
        public TinyPngCompressResponse(HttpResponseMessage msg) : base(msg)
        {
            //configure json settings for camelCase.
            jsonSettings = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            //this is a cute trick to handle async in a ctor and avoid deadlocks
            ApiResult = Task.Run(() => Deserialize(msg)).GetAwaiter().GetResult();
            Input = ApiResult.Input;
            Output = ApiResult.Output;

        }