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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:59:29+00:00 2026-06-18T09:59:29+00:00

Imagine that we have below code public class test { public void Condition(x,y) {

  • 0

Imagine that we have below code

public class test
  {
   public void Condition(x,y)
   {
       if (x == y)
       {
           methodOne();
       }
       else
       {
           methodTwo();
       }
   }
    public void methodOne(){//do some database stuff}
    public void methodTwo(){//do some database stuff}
 }

I want to assert that if methodone is get called when x==y or not but do not want my test to execute the code inside my method one as it will do some database stuff …

I am writing something like this

 MockRepository mockRepository=new MockRepository();
 var Mock = mockRepository.PartialMock<test>();
 mock.Replay();
 mock.condition(1,1);
 mock.AssertWasCalled(x=>x.methodOne);
 mock.VerifyAllExpectations();

but it tries to run run the stuff in the method one as well and I do not want my test do the database connection , I just need to make sure my condition is work and it called or not.

  • 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-18T09:59:31+00:00Added an answer on June 18, 2026 at 9:59 am

    You are mixing your concerns, business logic and data access, in one class. You need to think about Single Responsibility Principle and Separation of concerns.

    Your public void Condition(x,y) should probably be in a Business Logic Layer with methodOne() and methodTwo() being in a Data Access Layer.

    The Data Access Layer should be injected (IoC) into the Business Logic Layer so it can be mocked out. That way when you are testing the Condition method you would pass in a mock Data Access Layer that doesn’t actually connect to a database.

    That way you can check that Condition was called, as you are now, without any side-effects like writing to the database. When you encounter situations like this it helps you to break out your code into a better architecture and could ultimately lead you to investigate Test Driven Development.

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

Sidebar

Related Questions

Imagine that i have the following code: <a:repeat value=#{bean.getList()} var=x > <li class=la> <span>
Imagine that I have a nice Deck class, in the best OO fashion. It
I have a C++ class Finder that stores a location in containers plus some
Just imagine that my asp.net mvc Controller method could have this code: testplanService.AddTestplan(testplan,template,release); which
Imagine I have a table with data as below: ROLE_ID | USER_ID | CODE
Imagine that I have a form in a flash application with two fields, input1
imagine that I have a Form with 9 controls (TabbedStuffControl) in a 3x3 tile,
Let's imagine that I have to make a table with the following structure with
Let's imagine that I have list of files at host1 find /path/to -name *.jpg
Let's imagine that I have a result of evaluating XPath expression //node/@*. MSXML6 returns

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.