Skip to content

Commit

Permalink
Use simple using statement
Browse files Browse the repository at this point in the history
Apply Visual Studio refactoring suggestions.
  • Loading branch information
martincostello committed May 13, 2024
1 parent 7bb8e16 commit 12ad627
Showing 1 changed file with 22 additions and 24 deletions.
Expand Up @@ -55,22 +55,21 @@ public async Task DocumentProvider_Writes_Custom_V3_Document()
var services = server.Host.Services;

var documentProvider = services.GetService<IDocumentProvider>();
using (var stream = new MemoryStream())
using var stream = new MemoryStream();

using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 2048, leaveOpen: true))
{
using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 2048, leaveOpen: true))
{
await documentProvider.GenerateAsync("v1", writer);
await writer.FlushAsync();
}
await documentProvider.GenerateAsync("v1", writer);
await writer.FlushAsync();
}

stream.Position = 0L;
stream.Position = 0L;

using var document = JsonDocument.Parse(stream);
using var document = JsonDocument.Parse(stream);

// verify that the custom serializer wrote the swagger info
var swaggerInfo = document.RootElement.GetProperty("swagger").GetString();
Assert.Equal("DocumentSerializerTest3.0", swaggerInfo);
}
// verify that the custom serializer wrote the swagger info
var swaggerInfo = document.RootElement.GetProperty("swagger").GetString();
Assert.Equal("DocumentSerializerTest3.0", swaggerInfo);
}

[Fact]
Expand All @@ -84,22 +83,21 @@ public async Task DocumentProvider_Writes_Custom_V2_Document()
var options = services.GetService<IOptions<SwaggerOptions>>();
options.Value.SerializeAsV2 = true;

using (var stream = new MemoryStream())
using var stream = new MemoryStream();

using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 2048, leaveOpen: true))
{
using (var writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 2048, leaveOpen: true))
{
await documentProvider.GenerateAsync("v1", writer);
await writer.FlushAsync();
}
await documentProvider.GenerateAsync("v1", writer);
await writer.FlushAsync();
}

stream.Position = 0L;
stream.Position = 0L;

using var document = JsonDocument.Parse(stream);
using var document = JsonDocument.Parse(stream);

// verify that the custom serializer wrote the swagger info
var swaggerInfo = document.RootElement.GetProperty("swagger").GetString();
Assert.Equal("DocumentSerializerTest2.0", swaggerInfo);
}
// verify that the custom serializer wrote the swagger info
var swaggerInfo = document.RootElement.GetProperty("swagger").GetString();
Assert.Equal("DocumentSerializerTest2.0", swaggerInfo);
}
}
}

0 comments on commit 12ad627

Please sign in to comment.