Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider abstract classes in configuration options #362

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static IOpenApiConfigurationOptions Resolve(Assembly assembly)
{
var type = assembly.GetLoadableTypes()
.SingleOrDefault(p => p.GetInterface("IOpenApiConfigurationOptions", ignoreCase: true).IsNullOrDefault() == false
&& p.IsAbstract == false
&& p.GetCustomAttribute<ObsoleteAttribute>(inherit: false).IsNullOrDefault() == true);
if (type.IsNullOrDefault())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes
{
public class FakeOpenApiConfigurationOptions : FakeOpenApiConfigurationOptionsBase
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes
{
public abstract class FakeOpenApiConfigurationOptionsBase : DefaultOpenApiConfigurationOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Resolvers
Expand Down Expand Up @@ -39,5 +40,16 @@ public void Given_Assembly_When_Resolve_Invoked_Then_It_Should_Return_Result()

result.Should().BeOfType<DefaultOpenApiConfigurationOptions>();
}

[TestMethod]
public void Given_An_Assembly_With_An_Abstract_Base_Configuration_Then_It_Should_Return_Result()
{
var assembly = Assembly.GetAssembly(typeof(FakeOpenApiConfigurationOptions));

var result = OpenApiConfigurationResolver.Resolve(assembly);

result.Should().BeOfType<FakeOpenApiConfigurationOptions>();
result.GetType().BaseType.Should().Be(typeof(FakeOpenApiConfigurationOptionsBase)); // This verifies the abstract type was considered in the resolution
}
}
}