79085878

Date: 2024-10-14 11:05:31
Score: 3
Natty:
Report link

Mock memory cache can be set up like screenshot below.

var firstTime = true;
object? expectedValue = "value from mock";
mockMemoryCache.Setup(x => x.TryGetValue(It.IsAny<object>(), out expectedValue))
          .Returns(() =>
          {
              if (firstTime)
              {
                  firstTime = false;
                  return false;
              }
              return true;
          });

mockMemoryCache
.Setup(x => x.CreateEntry(It.IsAny<object>()))
.Returns(Mock.Of<ICacheEntry>);

Reference: https://stackoverflow.com/a/11308543/8778795 https://github.com/devlooped/moq/issues/436

enter image description here

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Blacklisted phrase (1): enter image description here
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Bo L