unit testing problem with ICache
so I am getting this error
for this method
can anyone help how to fix this please?
System.NotSupportedException : Unsupported expression: cache => cache.TryGetValue<Customer>("pendingCustomer", testCustomer)
Extension methods (here: CacheExtensions.TryGetValue) may not be used in setup / verification expressions. System.NotSupportedException : Unsupported expression: cache => cache.TryGetValue<Customer>("pendingCustomer", testCustomer)
Extension methods (here: CacheExtensions.TryGetValue) may not be used in setup / verification expressions.for this method
[Fact]
public async Task VerifyEmailAndCreateAccount_ValidCode_CreatesCustomerAccount()
{
// Arrange
var testCustomer = _testCustomer;
string verificationCode = "123456";
var emailVerification = new EmailVerification
{
Email = testCustomer.Email,
Code = "123456"
};
// Setup the cache mock to return a valid customer and verification code
_mockMemoryCache.Setup(cache => cache.TryGetValue("pendingCustomer", out testCustomer))
.Returns(true);
_mockMemoryCache.Setup(cache => cache.TryGetValue("verificationCode", out verificationCode))
.Returns(true);
// Act: Call the API method
var result = await _controller.VerifyEmailAndCreateAccount(emailVerification);
// Assert
var okResult = Assert.IsType<OkObjectResult>(result);
Assert.Equal("Email successfully verified and account created.", okResult.Value);
} [Fact]
public async Task VerifyEmailAndCreateAccount_ValidCode_CreatesCustomerAccount()
{
// Arrange
var testCustomer = _testCustomer;
string verificationCode = "123456";
var emailVerification = new EmailVerification
{
Email = testCustomer.Email,
Code = "123456"
};
// Setup the cache mock to return a valid customer and verification code
_mockMemoryCache.Setup(cache => cache.TryGetValue("pendingCustomer", out testCustomer))
.Returns(true);
_mockMemoryCache.Setup(cache => cache.TryGetValue("verificationCode", out verificationCode))
.Returns(true);
// Act: Call the API method
var result = await _controller.VerifyEmailAndCreateAccount(emailVerification);
// Assert
var okResult = Assert.IsType<OkObjectResult>(result);
Assert.Equal("Email successfully verified and account created.", okResult.Value);
}can anyone help how to fix this please?

