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 9062679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:47:53+00:00 2026-06-16T15:47:53+00:00

I have a reasonably complex program architecture with minimal logic but lots of event

  • 0

I have a reasonably complex program architecture with minimal logic but lots of event handler passing. I’m making a skeleton of a server framework, and I have the following classes:

Core, which listens to:

CommHandler, which listens to:

CommLayer, which listens to:

IServerMock, which I stub out with a mocking framework (MOQ).

What’s the best way to unit test relationships like this that are triggered by events? I know unit tests are supposed to be very isolated and granular things, but the only way I can think of testing this is by testing the entire process and checking the final output from Core.

  • 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-06-16T15:47:54+00:00Added an answer on June 16, 2026 at 3:47 pm

    You need to make an abstraction for each class so Core depends on an ICommHandler not CommHandler and so-on. The dependencies should be supplied via the constructor and that way you can easily test each class in isolation as you can mock it’s dependancies.

    public class Core
    {
        private ICommHandler commHandler;
    
        public Core(ICommHandler commHandler)
        {
            this.commHandler = commHandler;
        }
    }
    

    In your production code you can then do this:

    var core = new Core(new CommHandler());
    

    Although it would be better to use an IOC container to manage the instantiation of the objects since CommHandler has it’s own dependencies but you should look into that separately.

    Then in your Unit Test, you can do this:

    [Test]
    public void TestSomeCommHandlerEvent()
    {
         var mockCommHandler = new Mock<ICommHandler>();
         // set up the mock
    
         var core = new Core(mockCommHandler.Object);
    }
    

    Doing this allows you to replace the implementation of ICommHandler in your test with a mock which you can configure the behaviour of.

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

Sidebar

Related Questions

I have created a SQL Server view which performs some reasonably complex logic on
I have a reasonably complex layout problem: I would like to have a main
I have 4 reasonably complex r scripts that are used to manipulate csv and
I have a reasonably complex MySQL query being run on another developer's database. I
I have a reasonably complex XML document which I want to flatten down to
I have a reasonably complex custom Django model method. It's visible in the admin
I have a reasonably complex Core Data app for the the iPhone. For the
I have a reasonably complex query to extract the Id field of the results
We're making a Flash browser game with a few reasonably complex animations. Our designer
I have a reasonably complex macro that I need to run on multiple different

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.