Is there a way to Mock ProtectedSessionStorage in a Blazor Server Side project?
I tried below code but I am getting error : "Type to mock (ProtectedSessionStorage) must be an interface, a delegate, or a non-sealed, non-static class."
private readonly Mock<ProtectedSessionStorage> _sessionStorage = new();
private readonly Mock<IDataProtector> _mockDataProtector = new();
private readonly Mock<IDataProtectionProvider> _mockDataProtectionProvider = new();
//in ctor()
Services.AddSingleton(_sessionStorage.Object);
//mock IDataProtector
_mockDataProtector = new Mock<IDataProtector>();
_mockDataProtector.Setup(sut => sut.Protect(It.IsAny<byte[]>())).Returns(Encoding.UTF8.GetBytes("protectedText"));
_mockDataProtector.Setup(sut => sut.Unprotect(It.IsAny<byte[]>())).Returns(Encoding.UTF8.GetBytes("originalText"));
Services.AddSingleton(_mockDataProtector.Object);
//mock IDataProtectionProvider
_mockDataProtectionProvider = new Mock<IDataProtectionProvider>();
_mockDataProtectionProvider.Setup(s => s.CreateProtector(It.IsAny<string>())).Returns(_mockDataProtector.Object);
Services.AddSingleton(_mockDataProtectionProvider.Object);
//in testMethod()
EquipmentSearchFilterDto filter = new();
filter.HospitalID = 1;
var result = new ProtectedBrowserStorageResult<EquipmentSearchFilterDto>();
_sessionStorage.Setup(x => x.GetAsync<EquipmentSearchFilterDto>(It.IsAny<string>()))
.ReturnsAsync(new ProtectedBrowserStorageResult<EquipmentSearchFilterDto>());
I thought of hiding ProtectedSessionStorage implementation behind an interface unfortunately I was unable to come up with one. Any ideas?