public async Task Ctor_WhenRuleExpirationIsInvalidOrEmpty_ShouldUseDefaultExpiration() { // Arrange const RuleType ruleType = RuleType.Action; var cacheKey = $"{_cacheKeysKey}_{ruleType}_{nameof(TestRule)}"; var cacheKeysKey = _cacheKeysKey; var expectedRules = new List <CompiledRule <TestRule> >(); _innerRuleServiceMock.Setup(r => r.GetCompiledByRuleType <TestRule>(ruleType)).ReturnsAsync(expectedRules); object cacheRules; _cacheMock.Setup(c => c.TryGetValue(cacheKey, out cacheRules)).Returns(false); object cacheKeys; _cacheMock.Setup(c => c.TryGetValue(cacheKeysKey, out cacheKeys)).Returns(false); _cacheSettings = new CacheSettings { RuleExpiration = "invalid" }; var appSettingsMock = new Mock <IOptions <CacheSettings> >(); appSettingsMock.Setup(s => s.Value).Returns(_cacheSettings); _ruleService = new CacheableRuleService(_innerRuleServiceMock.Object, _cacheMock.Object, appSettingsMock.Object); // Act await _ruleService.GetCompiledByRuleType <TestRule>(RuleType.Action); // Assert _cacheMock.Verify(c => c.SetAsync(cacheKey, expectedRules, It.Is <CacheEntryOptions>(o => !o.Expiration.HasValue))); }
public void Init() { _cacheSettings = new CacheSettings(); var appSettingsMock = new Mock <IOptions <CacheSettings> >(); appSettingsMock.Setup(s => s.Value).Returns(_cacheSettings); _innerRuleServiceMock = new Mock <IRuleService>(); _cacheMock = new Mock <ICache>(); _ruleService = new CacheableRuleService(_innerRuleServiceMock.Object, _cacheMock.Object, appSettingsMock.Object); }