Skip to content

Commit

Permalink
SpecFlowOSS#2307 Fixed bug when feature context can't be resolved at …
Browse files Browse the repository at this point in the history
…static methods (SpecFlowOSS#2449)

* SpecFlowOSS#2307 Fixed bug when feature context can't be resolved at static methods

Again - This time for Windsor

* Updated tests to new WindsorTestObjectResolver
  • Loading branch information
Bo Søborg Petersen authored and Code-Grump committed Mar 29, 2023
1 parent 6b5ee63 commit af50831
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ public class WindsorTestObjectResolver : ITestObjectResolver
{
public object ResolveBindingInstance(Type bindingType, IObjectContainer scenarioContainer)
{
var componentContext = scenarioContainer.Resolve<IWindsorContainer>();
return componentContext.Resolve(bindingType);
if (scenarioContainer.IsRegistered<IWindsorContainer>())
{
var componentContext = scenarioContainer.Resolve<IWindsorContainer>();
return componentContext.Resolve(bindingType);
}
return scenarioContainer.Resolve(bindingType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,35 @@ public void Can_load_Windsor_plugin()
plugin.Should().NotBeNull();
}

[Fact]
public void Resolutions_are_not_forwarded_to_Windsor_before_it_is_registered()
{
var resolver = new WindsorTestObjectResolver();

var objectContainer = new Mock<IObjectContainer>();
var container = new Mock<IWindsorContainer>();
objectContainer.Setup(x => x.IsRegistered<IWindsorContainer>()).Returns(false);
objectContainer.Setup(x => x.Resolve<IWindsorContainer>()).Returns(container.Object);

resolver.ResolveBindingInstance(typeof(ITraceListener), objectContainer.Object);

objectContainer.Verify(x => x.Resolve(typeof(ITraceListener), It.IsAny<string>()), Times.Once);
container.Verify(x => x.Resolve(typeof(ITraceListener)), Times.Never);
}

[Fact]
public void Resolutions_are_forwarded_to_Windsor()
{
var resolver = new WindsorTestObjectResolver();

var objectContainer = new Mock<IObjectContainer>();
var container = new Mock<IWindsorContainer>();
objectContainer.Setup(x => x.IsRegistered<IWindsorContainer>()).Returns(true);
objectContainer.Setup(x => x.Resolve<IWindsorContainer>()).Returns(container.Object);

resolver.ResolveBindingInstance(typeof(ITraceListener), objectContainer.Object);

objectContainer.Verify(x => x.Resolve(typeof(ITraceListener), It.IsAny<string>()), Times.Never);
container.Verify(x => x.Resolve(typeof(ITraceListener)), Times.Once);
}

Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Fixes:
+ Fix Type or namespace [TestNamespace]_XunitAssemblyFixture could not be found #1825
+ Fix Default value deserialization from specflow.json #2239 #2439
+ Should not log error if TestAssembly does not have a RuntimePlugin attribute #2432
+ Fixed context injection in static methods for Windsor plugin - Same as https://github.com/SpecFlowOSS/SpecFlow/issues/2307, but for Windsor


3.8
Expand Down

0 comments on commit af50831

Please sign in to comment.