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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:15:20+00:00 2026-06-04T09:15:20+00:00

I’m testing a method that calls another method within the same class. Depending on

  • 0

I’m testing a method that calls another method within the same class.

Depending on whether this internal method call returns a result I do different things. In this case it’s a Cache class and I’m testing my GetOrStore method. I want to test two paths, when Get returns null and when Get returns something.

What’s the right approach to controlling the output of Get when called from GetOrStore? It feels like Get should be executed on a mocked instance however I’m unsure how to do that given two methods in the same class.

Update

The only thing I can think to do at this time is to make sure the cache key is removed before running the test:

  HttpRuntime.Cache.Remove("foo"); // Make sure foo isn't in the cache.

  var output = _cache.GetOrStore("foo", () => "Foo", 100);
  Assert.AreEqual(output, "Foo");

This just feels wrong though. I don’t actually want the HttpRuntime cache touched during my test.

  • 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-04T09:15:21+00:00Added an answer on June 4, 2026 at 9:15 am

    The answer to this is in Moqs CallBase property on mocked instances.

    Setting CallBase to true ensures that any methods not explicity setup are called on the real instance of the mocked object.

    This then means we can setup the Get method and still have GetOrStore executed correctly:

      var _mockCache = new Mock<Cache>();
      _mockCache.Setup(m => m.Get(It.IsAny<string>())).Returns(null);
      _mockCache.CallBase = true;
    
      var output = _mockCache.Object.GetOrStore("foo", () => "Foo", 100);
      Assert.AreEqual("Foo", output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.