예제 #1
0
        public async Task AutoPollConfigService_RefreshConfigAsync_ConfigCahged_ShouldRaiseEvent()
        {
            // Arrange

            byte eventChanged = 0;

            this.cacheMock
            .Setup(m => m.Get())
            .Returns(cachedPc);

            this.fetcherMock
            .Setup(m => m.Fetch(cachedPc))
            .Returns(Task.FromResult(fetchedPc));

            this.cacheMock
            .Setup(m => m.Set(fetchedPc));

            var service = new AutoPollConfigService(
                fetcherMock.Object,
                cacheMock.Object,
                TimeSpan.FromMinutes(1),
                TimeSpan.Zero,
                logFactoryMock.Object,
                false);

            service.OnConfigurationChanged += (o, s) => { eventChanged++; };

            // Act

            await service.RefreshConfigAsync();

            // Assert

            Assert.AreEqual(1, eventChanged);
        }
예제 #2
0
        public async Task AutoPollConfigService_RefreshConfigAsync_ShouldNotInvokeCacheGetAndFetchAndCacheSet()
        {
            // Arrange

            this.cacheMock
            .Setup(m => m.Get())
            .Returns(cachedPc);

            this.fetcherMock
            .Setup(m => m.Fetch(cachedPc))
            .Returns(Task.FromResult(fetchedPc));

            this.cacheMock
            .Setup(m => m.Set(fetchedPc));

            var service = new AutoPollConfigService(
                fetcherMock.Object,
                cacheMock.Object,
                TimeSpan.FromMinutes(1),
                TimeSpan.Zero,
                logFactoryMock.Object,
                false);

            // Act

            await service.RefreshConfigAsync();

            // Assert

            this.cacheMock.Verify(m => m.Get(), Times.Once);
            this.cacheMock.Verify(m => m.Set(fetchedPc), Times.Once);
            this.fetcherMock.Verify(m => m.Fetch(cachedPc), Times.Once);
        }
예제 #3
0
        public async Task AutoPollConfigService_RefreshConfigAsync_ConfigChanged_ShouldRaiseEvent()
        {
            // Arrange

            byte eventChanged = 0;

            this.cacheMock
            .Setup(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None))
            .ReturnsAsync(cachedPc);

            this.fetcherMock
            .Setup(m => m.Fetch(cachedPc))
            .Returns(Task.FromResult(fetchedPc));

            this.cacheMock
            .Setup(m => m.SetAsync(It.IsAny <string>(), fetchedPc))
            .Returns(Task.CompletedTask);

            var service = new AutoPollConfigService(
                fetcherMock.Object,
                new CacheParameters {
                ConfigCache = cacheMock.Object
            },
                TimeSpan.FromMinutes(1),
                TimeSpan.Zero,
                loggerMock.Object,
                false);

            service.OnConfigurationChanged += (o, s) => { eventChanged++; };

            // Act

            await service.RefreshConfigAsync();

            // Assert

            Assert.AreEqual(1, eventChanged);
        }
예제 #4
0
        public async Task AutoPollConfigService_RefreshConfigAsync_ShouldOnceInvokeCacheGetAndFetchAndCacheSet()
        {
            // Arrange

            this.cacheMock
            .Setup(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None))
            .ReturnsAsync(cachedPc);

            this.fetcherMock
            .Setup(m => m.Fetch(cachedPc))
            .Returns(Task.FromResult(fetchedPc));

            this.cacheMock
            .Setup(m => m.SetAsync(It.IsAny <string>(), fetchedPc))
            .Returns(Task.CompletedTask);

            var service = new AutoPollConfigService(
                fetcherMock.Object,
                new CacheParameters {
                ConfigCache = cacheMock.Object
            },
                TimeSpan.FromMinutes(1),
                TimeSpan.Zero,
                loggerMock.Object,
                false);

            // Act

            await service.RefreshConfigAsync();

            // Assert

            this.cacheMock.Verify(m => m.GetAsync(It.IsAny <string>(), CancellationToken.None), Times.Once);
            this.cacheMock.Verify(m => m.SetAsync(It.IsAny <string>(), fetchedPc), Times.Once);
            this.fetcherMock.Verify(m => m.Fetch(cachedPc), Times.Once);
        }