public async Task ManualPollConfigService_GetConfigAsync_ShouldInvokeCacheGet() { // Arrange this.cacheMock .Setup(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None)) .ReturnsAsync(cachedPc); var service = new ManualPollConfigService( fetcherMock.Object, new CacheParameters { ConfigCache = cacheMock.Object }, loggerMock.Object); // Act var projectConfig = await service.GetConfigAsync(); // Assert Assert.AreEqual(cachedPc, projectConfig); this.cacheMock.Verify(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None), Times.Once); this.fetcherMock.Verify(m => m.Fetch(It.IsAny <ProjectConfig>()), Times.Never); this.cacheMock.Verify(m => m.SetAsync(It.IsAny <string>(), It.IsAny <ProjectConfig>()), Times.Never); }
public async Task ManualPollConfigService_RefreshConfigAsync_ShouldInvokeCacheGet() { // Arrange byte callOrder = 1; this.cacheMock .Setup(m => m.Get()) .Returns(cachedPc) .Callback(() => Assert.AreEqual(1, callOrder++)); this.fetcherMock .Setup(m => m.Fetch(cachedPc)) .Returns(Task.FromResult(fetchedPc)) .Callback(() => Assert.AreEqual(2, callOrder++)); this.cacheMock .Setup(m => m.Set(fetchedPc)) .Callback(() => Assert.AreEqual(3, callOrder++)); var service = new ManualPollConfigService( fetcherMock.Object, cacheMock.Object, logFactoryMock.Object); // Act await service.RefreshConfigAsync(); // Assert this.cacheMock.Verify(m => m.Get(), Times.Once); this.fetcherMock.Verify(m => m.Fetch(It.IsAny <ProjectConfig>()), Times.Once); this.cacheMock.Verify(m => m.Set(It.IsAny <ProjectConfig>()), Times.Once); }
public async Task ManualPollConfigService_GetConfigAsync_ShouldInvokeCacheGet() { // Arrange this.cacheMock .Setup(m => m.Get()) .Returns(cachedPc); var service = new ManualPollConfigService( fetcherMock.Object, cacheMock.Object, logFactoryMock.Object); // Act var projectConfig = await service.GetConfigAsync(); // Assert Assert.AreEqual(cachedPc, projectConfig); this.cacheMock.Verify(m => m.Get(), Times.Once); this.fetcherMock.Verify(m => m.Fetch(It.IsAny <ProjectConfig>()), Times.Never); this.cacheMock.Verify(m => m.Set(It.IsAny <ProjectConfig>()), Times.Never); }
/// <summary> /// Create an instance of ConfigCatClient and setup ManualPoll mode /// </summary> /// <param name="configuration">Configuration for LazyLoading mode</param> /// <exception cref="ArgumentException">When the configuration contains any invalid property</exception> /// <exception cref="ArgumentNullException">When the configuration is null</exception> public ConfigCatClient(ManualPollConfiguration configuration) : this((ConfigurationBase)configuration) { var configService = new ManualPollConfigService( new HttpConfigFetcher(configuration.CreateUri(), "m-" + version, configuration.Logger, configuration.HttpClientHandler, this.configDeserializer, configuration.IsCustomBaseUrl), this.cacheParameters, configuration.Logger); this.configService = configService; }
/// <summary> /// Create an instance of BetterConfigClient and setup ManualPoll mode /// </summary> /// <param name="configuration">Configuration for LazyLoading mode</param> /// <exception cref="ArgumentException">When the configuration contains any invalid property</exception> /// <exception cref="ArgumentNullException">When the configuration is null</exception> public BetterConfigClient(ManualPollConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } configuration.Validate(); InitializeClient(configuration); var configService = new ManualPollConfigService( new HttpConfigFetcher(configuration.Url, "m-" + version, configuration.LoggerFactory), new InMemoryConfigCache(), configuration.LoggerFactory); this.configService = configService; }
public async Task ManualPollConfigService_RefreshConfigAsync_ShouldInvokeCacheGet() { // Arrange byte callOrder = 1; this.cacheMock .Setup(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None)) .ReturnsAsync(cachedPc) .Callback(() => Assert.AreEqual(1, callOrder++)); this.fetcherMock .Setup(m => m.Fetch(cachedPc)) .Returns(Task.FromResult(fetchedPc)) .Callback(() => Assert.AreEqual(2, callOrder++)); this.cacheMock .Setup(m => m.SetAsync(It.IsAny <string>(), fetchedPc)) .Callback(() => Assert.AreEqual(3, callOrder++)) .Returns(Task.CompletedTask); var service = new ManualPollConfigService( fetcherMock.Object, new CacheParameters { ConfigCache = cacheMock.Object }, loggerMock.Object); // Act await service.RefreshConfigAsync(); // Assert this.cacheMock.Verify(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None), Times.Once); this.fetcherMock.Verify(m => m.Fetch(It.IsAny <ProjectConfig>()), Times.Once); this.cacheMock.Verify(m => m.SetAsync(It.IsAny <string>(), It.IsAny <ProjectConfig>()), Times.Once); }