Skip to content

Commit

Permalink
Do not consider abstract classes in configuration options (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenpa committed Feb 22, 2022
1 parent e432a6b commit dad34bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
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
}
}
}

0 comments on commit dad34bc

Please sign in to comment.