public async Task DeserialisationWhenContentIsNotCompressed() { var postcodeWithRadius = new PostcodeWithRadius() { Id = 1, Postcode = "NG1 5FS", RadiusInMetres = 100 }; var json = Utf8Json.JsonSerializer.ToJsonString(postcodeWithRadius); var httpRequestMessage = new HttpRequestMessage() { Content = new StringContent(json) }; var result = await HttpRequestMessageCompressionUtils.DeserialiseAsync <PostcodeWithRadius>(httpRequestMessage); Assert.AreEqual(postcodeWithRadius.Id, result.Id); Assert.AreEqual(postcodeWithRadius.Postcode, result.Postcode); Assert.AreEqual(postcodeWithRadius.RadiusInMetres, result.RadiusInMetres); }
public async Task DeserialisationWhenContentIsCompressed() { var postcodeWithRadius = new PostcodeWithRadius() { Id = 1, Postcode = "NG1 5FS", RadiusInMetres = 100 }; var json = Utf8Json.JsonSerializer.ToJsonString(postcodeWithRadius); byte[] jsonBytes = Encoding.UTF8.GetBytes(json); MemoryStream ms = new MemoryStream(); using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compress, true)) { gzip.Write(jsonBytes, 0, jsonBytes.Length); } ms.Position = 0; StreamContent content = new StreamContent(ms); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); content.Headers.ContentEncoding.Add("gzip"); var httpRequestMessage = new HttpRequestMessage() { Content = content }; var result = await HttpRequestMessageCompressionUtils.DeserialiseAsync <PostcodeWithRadius>(httpRequestMessage); Assert.AreEqual(postcodeWithRadius.Id, result.Id); Assert.AreEqual(postcodeWithRadius.Postcode, result.Postcode); Assert.AreEqual(postcodeWithRadius.RadiusInMetres, result.RadiusInMetres); }