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

  • Home
  • SEARCH
  • 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 8058551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:23:33+00:00 2026-06-05T09:23:33+00:00

I am having trouble getting my Verify to work on a DB call. I

  • 0

I am having trouble getting my Verify to work on a DB call.

I have a method that I am simply trying to verify that a database call was made.

I can’t post the real code but here is a close example.

    protected void ReportDB(uint waitTimeInMinutes)
    {
        //check database connection
        Status dbStatus = Status.Ok;
        string dbComment = "ok";
        try
        {
            Data.GetActive("1");
        }
        catch (Exception ex)
        {
            dbComment = "Unable to access the database: " + ex.Message;
            dbStatus = Status.Critical;
        }

        //Report Status.
    }

So basically the GetActive() method just makes a database call. If it doesn’t throw an exception then we are good and connectivity is up.

My test method is.

    [TestMethod]
    public void ReportDBStatusTest()
    {
        _fakeData.Setup(s => s.Data.GetActive(It.IsAny<string>()));

        _unitUnderTest = new Service();
        _unitUnderTest.ReportDB(0);

        _fakeData.Verify(s => s.Data.GetActive(It.IsAny<string>()), Times.Once());
    }

I debug through and the method is called and everything, yet the verify says it was called Times.Never. I think I may just be misunderstanding how to do this correctly.

Error:

Expected invocation on the mock once, but was 0 times: s => s.Data.GetActive(It.IsAny())
Configured setups and invocations:

  • 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-05T09:23:34+00:00Added an answer on June 5, 2026 at 9:23 am

    The error is expected. This is because the ‘Data’ object inside the ‘ReportDB’ object is not the same as the ‘Data’ object inside the ‘_fakeData’ object.

    One workaround would be to externalize the ‘Data’ object in your ‘ReportDB’ object so that it can be mocked. Else, you need to alter your unit test.

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

Sidebar

Related Questions

Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having trouble getting a filter to work on a BindingSource that is the
I am having trouble getting this to work. I have variables initiated in main
I am having trouble getting Castle Dynamic Proxy to intercept methods that are explicit
I am having trouble getting my chat application working correctly. I have 2 textbox's,
I am having trouble getting one of my LINQ to SQL queries to work
I am having trouble getting a server Meteor.method to return a successful response when
I am having trouble getting my filters/validators to work correctly on my form, so
Having trouble getting my JQuery POST to be accepted by the WCF Service. Here's
I having trouble getting append() to work in safari for some reason, but it

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.