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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:19:15+00:00 2026-05-16T00:19:15+00:00

The project that I have just joined uses the command pattern quite extensively for

  • 0

The project that I have just joined uses the command pattern quite extensively for handling calls into the business logic layers of the project.

The business logic layers are built as static handlers calling into providers. The commands then call into these static handlers.

The team want to improve test coverage, and I would like us to move more toward true TDD but the use of static handlers means that there is a hard coded dependency in the commands and there is no way to inject the handlers as dependencies and so it is very difficult to unit test the commands in isolation.

Does anyone have any good suggestions for a strategy for us to move toward a more testable command pattern bearing in mind that there are a lot of commands already in use.

The process method below would be called when execute is called on the command. This would be the method under test. This is a typical example of the usage of static handlers in the command classes.

protected override bool Process()
{
    this.user = SecurityHandler.ActivateUser(this.activationGuid);
    bool success = this.user != null;

    if (!success)
    {
        this.AddStatusMessage(StatusMessageType.Error, "/Commands/Security/ActivateUserCommand/IncorrectLink", true);
    }

    return success;
}
  • 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-16T00:19:16+00:00Added an answer on May 16, 2026 at 12:19 am

    Static methods/fields generally hurt with testability – because it introduces the risk of tests not being isolated. One test could set some static field, changing the initial state for test2.

    That said there was nothing in the Command Pattern that needed static handlers.. so I think it’s a custom implementation. I would like to see some sample code for a shorter answer.

    There is no easy way out.. move the static parts into another class/object and pass it into the objects that need to access it. This might mean adding a parameter to methods that are currently using a TypeName.StaticField invocation to get at the data.

    Update (for posted code snippet): I fail to see the Command Pattern here.. anyways to get the method under test.

    • Does the SecurityHandler.ActivateUser have any side-effects ? Does calling it the second time differ in any manner from calling it the first time? If not (i.e. it is a pure service call) then dont worry about it.
    • if ActivateUser has some side-effects, then you have to do some work. i.e. Turn the static methods into instance methods and pass in an instance of SecurityHandler to the containing type of Process(). You can either pass it in as a method parameter to Process() or a ctor/property set on containing type. Choose whatever you feel is apt.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.