2025-08-18 18:40:50 +02:00
|
|
|
|
using Bit.SharedWeb.Swagger;
|
2026-02-10 11:11:44 -05:00
|
|
|
|
using Microsoft.OpenApi;
|
2025-08-18 18:40:50 +02:00
|
|
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SharedWeb.Test;
|
|
|
|
|
|
|
|
|
|
|
|
public class SourceFileLineOperationFilterTest
|
|
|
|
|
|
{
|
|
|
|
|
|
private class DummyController
|
|
|
|
|
|
{
|
|
|
|
|
|
public void DummyMethod() { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void AddsSourceFileAndLineExtensionsIfAvailable()
|
|
|
|
|
|
{
|
|
|
|
|
|
var methodInfo = typeof(DummyController).GetMethod(nameof(DummyController.DummyMethod));
|
|
|
|
|
|
var operation = new OpenApiOperation();
|
2026-02-10 11:11:44 -05:00
|
|
|
|
var context = new OperationFilterContext(null, null, null, null, methodInfo);
|
2025-08-18 18:40:50 +02:00
|
|
|
|
var filter = new SourceFileLineOperationFilter();
|
|
|
|
|
|
filter.Apply(operation, context);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(operation.Extensions.ContainsKey("x-source-file"));
|
|
|
|
|
|
Assert.True(operation.Extensions.ContainsKey("x-source-line"));
|
2026-02-10 11:11:44 -05:00
|
|
|
|
var fileExt = operation.Extensions["x-source-file"] as JsonNodeExtension;
|
|
|
|
|
|
var lineExt = operation.Extensions["x-source-line"] as JsonNodeExtension;
|
2025-08-18 18:40:50 +02:00
|
|
|
|
Assert.NotNull(fileExt);
|
|
|
|
|
|
Assert.NotNull(lineExt);
|
|
|
|
|
|
|
2026-02-10 11:11:44 -05:00
|
|
|
|
Assert.Equal(11, (int)lineExt.Node);
|
|
|
|
|
|
Assert.StartsWith("test/SharedWeb.Test/", fileExt.Node.ToString());
|
2025-08-18 18:40:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|