Skip to content

Commit

Permalink
test: handle stream disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi committed Jan 30, 2025
1 parent 3354b41 commit 5169886
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ await DeserializeAsync<ChangeRequest>(formatter, turtle,
private static async Task<string> SerializeAsync<T>(MediaTypeFormatter formatter, T value,
MediaTypeHeaderValue mediaType)
{
Stream stream = new MemoryStream();
HttpContent content = new StreamContent(stream);
await using Stream stream = new MemoryStream();
using HttpContent content = new StreamContent(stream);

content.Headers.ContentType = mediaType;

Expand All @@ -183,8 +183,8 @@ private static async Task<string> SerializeAsync<T>(MediaTypeFormatter formatter
private static async Task<string> SerializeCollectionAsync<T>(MediaTypeFormatter formatter,
IEnumerable<T> value, MediaTypeHeaderValue mediaType)
{
Stream stream = new MemoryStream();
HttpContent content = new StreamContent(stream);
await using Stream stream = new MemoryStream();
using HttpContent content = new StreamContent(stream);

content.Headers.ContentType = mediaType;

Expand All @@ -197,9 +197,9 @@ private static async Task<string> SerializeCollectionAsync<T>(MediaTypeFormatter
private static async Task<T?> DeserializeAsync<T>(MediaTypeFormatter formatter, string str,
MediaTypeHeaderValue mediaType) where T : class
{
Stream stream = new MemoryStream();
var writer = new StreamWriter(stream);
HttpContent content = new StreamContent(stream);
await using Stream stream = new MemoryStream();
await using var writer = new StreamWriter(stream);
using HttpContent content = new StreamContent(stream);

content.Headers.ContentType = mediaType;

Expand All @@ -215,9 +215,9 @@ private static async Task<string> SerializeCollectionAsync<T>(MediaTypeFormatter
MediaTypeFormatter formatter,
string str, MediaTypeHeaderValue mediaType) where T : class
{
Stream stream = new MemoryStream();
var writer = new StreamWriter(stream);
HttpContent content = new StreamContent(stream);
await using Stream stream = new MemoryStream();
await using var writer = new StreamWriter(stream);
using HttpContent content = new StreamContent(stream);

content.Headers.ContentType = mediaType;

Expand Down

0 comments on commit 5169886

Please sign in to comment.