Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:38:13+00:00 2026-05-22T02:38:13+00:00

I have the following test: [Test] public void VerifyThat_WhenInitializingTheLoggingInterceptionFacility_TheLoggingInterceptorIsAdded() { var kernel = new

  • 0

I have the following test:

[Test]
public void VerifyThat_WhenInitializingTheLoggingInterceptionFacility_TheLoggingInterceptorIsAdded()
{
    var kernel = new Mock<IKernel>(MockBehavior.Loose)
            {
                DefaultValue = DefaultValue.Mock
            };
    kernel.Setup(k => k.AddFacility<LoggingInterceptionFacility>())
                .Returns(kernel.Object)
                .Callback(() => ((IFacility)new LoggingInterceptionFacility()).Init(kernel.Object, Mock.Of<IConfiguration>()));

    kernel.Setup(k => k.Register(It.IsAny<IRegistration[]>()))
                  .Returns(kernel.Object)
                  .Verifiable();

    kernel.Object.AddFacility<LoggingInterceptionFacility>();

    kernel.Verify(k => k.Register(It.Is<IRegistration[]>(r => r.Contains(Component.For<LoggingInterceptor>()))));
}

As you can see I am mocking the real behavior of the kernel by calling the facilitiy’s Init(IKernel, IConfiguration) method which in turns calls the protected Init() method.
Here’s how the protected Init() looks like:

protected override void Init()
{
    Kernel.ProxyFactory.AddInterceptorSelector(new LoggingModelInterceptorsSelector());
    Kernel.Register(Component.For<LoggingInterceptor>());
}

I expected that the verification would pass but it does not. If I verify that the Kernel.Register was called at all with It.IsAny<LoggingInterceptor>() the test passes.
What am I not matching right here? Is there a way to make this test pass?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:38:13+00:00Added an answer on May 22, 2026 at 2:38 am

    It seems like you are testing way too much here. You are effectively reimplmenting a lot of Windsor’s internals by piping calls from AddFacility to LoggingInterceptionFacility.Init.

    All you really need to test is the fact that your facility calls Register on the kernel and assume that Windsor does the right thing. After all, it has unit tests of its own 😉

    After doing that, the test becomes much more readable, which I consider the most important aspect.

    [Test]
    public void VerifyThat_WhenInitializingTheLoggingInterceptionFacility_TheLoggingInterceptorIsAdded()
    {
        var kernel = new Mock<IKernel>();
    
        kernel.Setup(k => k.Register(It.IsAny<IRegistration[]>()))
                      .Returns(kernel.Object)
                      .Verifiable();
        //Explicit interface implementation requires casting to the interface
        ((IFacility)new LoggingInterceptionFacility()).Init(kernel.Object, Mock.Of<IConfiguration>().Object);
        //verify the type of registration here
        kernel.Verify(k => k.Register(It.Is<IRegistration[]>(r => r[0] is ComponentRegistration<LoggingInterceptor>);
    }
    

    EDIT Calls to Component.For return different instances between setup and execution. I updated the code to reflect that and have the verification check the type of the component.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public class Test { public static void Main() {
I have following test [Test] public void aaa() { CallContext.LogicalSetData(aa, 1); Action parallelMethod =
Say, I have the following test: [Test] public void MyTest( [RandomNumbers( Count=100, Minimum=0, Maximum=1000
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
I have the following controller action and test. I'm new to testing with Shoulda
I have the following code: public void someMethod() { Set<Foo> fooSet = bar.getFoos(); for(Foo
I have the following class structure that I need to unit test: public interface
I have the following program: ~/test> cat test.cc int main() { int i =
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.