Skip to content

Commit

Permalink
Add test for middleware evaluation with IfNotRegistered
Browse files Browse the repository at this point in the history
This test verifies that middleware is evaluated correctly when using IfNotRegistered with a service descriptor. It ensures the middleware is invoked during the resolution pipeline as expected.
  • Loading branch information
Fei Xu committed Dec 11, 2024
1 parent e267b0c commit 9453b96
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ public void IfNotRegistered_EvaluatesServiceMiddleware()
Assert.True(middlewareInvoked);
}

[Fact]
public void IfNotRegistered_EvaluatesServiceMiddleware_WithDescriptor()
{
var builder = new ContainerBuilder();
var middlewareInvoked = false;

builder.RegisterType<ServiceA>().As<IService>().IfNotRegistered(typeof(IService));

const string descriptor = "custom-middleware";
builder.RegisterServiceMiddleware(typeof(IService), descriptor, PipelinePhase.ResolveRequestStart, (context, next) =>
{
next(context);
middlewareInvoked = true;
});

var container = builder.Build();

var result = container.Resolve<IService>();
Assert.True(middlewareInvoked);
}

[Fact]
public void IfNotRegistered_CanBeDecoratedByModuleWhenModuleRegistered1st()
{
Expand Down

0 comments on commit 9453b96

Please sign in to comment.