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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:45:20+00:00 2026-05-18T21:45:20+00:00

My application has the following project structure: There is the Business Logic project and

  • 0

My application has the following project structure: There is the Business Logic project and the UnitTesting project where the methods from the Business Logic are tested. No mocking or testing framework are used (we rely on Visual Studio unit tests and we implement our own mock objects).
In the Business Logic let’s say I have the following method:

public static void SomeMethod ()
{
    ....
    if (cond1)
        if (cond2)
           SendMail();
}

I want to unit test that. I don’t want to unit test the sending of the mail, rather the mail is sent under the correct circumstances. So I was thinking to do something like

public class MailSender : ISmtpMail
{
    // stuff
}

public class FakeMailSender : ISmtpMail
{
    //
    static bool SendMail ()
    {
        return true;
    }
}

The problem is that I don’t know how to enforce the usage of the FakeMailSender in the unit test project or in the unit test methods which look something like :

[TestMethod]
public static void SomeMethod_Test()
{
    // some mock initialization
    BusinessLogic.SomeMEthod ();
    // checks
} 

without changing the BusinessLogic method signature or injecting code (which is undesired)

  • 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-18T21:45:20+00:00Added an answer on May 18, 2026 at 9:45 pm

    It’s not clear where your first method “lives”. It seems to me that:

    • Your SendMail method shouldn’t be static, which makes all kinds of test double injection tricky to say the least
    • You should inject ISmtpMail into whatever needs to send mail.

    You say you want to do it “without injecting code” – why not? The “mail sending” service is clearly a dependency: your code will be clearer, less tightly coupled, and easier to test if you inject that depedency, whether explictly or with the help of a DI container.

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

Sidebar

Related Questions

I'm building WPF client application. I'm following MVC pattern. The project solution has many
We have a multi module project with following modules: Database Persistence Business Application The
I'm working on project which has the following structure: DaoService - is Spring bean
I'm building a Zend website.The project (local) has the following structure: /app /controllers /views
Say I have an application with the following structure. // ASP.NET MVC (Web Project)
In my ASP.NET Web Application, the project structure is shown by the following image:
My application has the following patterns: a FrontController, Command, Service, and DAO. The problem
My android application has several warnings of the following form when I run it
My application has a table that contains snapshot inventory data from each year. For
The following scenario came up in our project: We have hierarchical business objects. The

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.