Exemplo n.º 1
0
        public void FetchSegmentShouldUpdateSegmentsCache()
        {
            //Arrange
            var apiClient = new Mock <ISegmentSdkApiClient>();

            apiClient
            .Setup(x => x.FetchSegmentChanges(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <FetchOptions>()))
            .Returns(Task.FromResult(@"{
                          'name': 'payed',
                          'added': [
                            'abcdz',
                            'bcadz',
                            'xzydz'
                          ],
                          'removed': [],
                          'since': -1,
                          'till': 10001
                        }"));
            var apiFetcher     = new ApiSegmentChangeFetcher(apiClient.Object);
            var segments       = new ConcurrentDictionary <string, Segment>();
            var cache          = new InMemorySegmentCache(segments);
            var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, cache);

            //Act
            segmentFetcher.FetchSegment(new FetchOptions());

            //Assert
            Assert.AreEqual(1, segments.Count);
        }
Exemplo n.º 2
0
        public void FetchSegmentShouldUpdateReadinessGatesWhenNoMoreChanges()
        {
            //Arrange
            var gates     = new InMemoryReadinessGatesCache();
            var apiClient = new Mock <ISegmentSdkApiClient>();

            apiClient
            .Setup(x => x.FetchSegmentChanges(It.IsAny <string>(), It.IsAny <long>()))
            .Returns(Task.FromResult(@"{
                          'name': 'payed',
                          'added': [
                            'abcdz',
                            'bcadz',
                            'xzydz'
                          ],
                          'removed': [],
                          'since': -1,
                          'till': -1
                        }"));
            var apiFetcher     = new ApiSegmentChangeFetcher(apiClient.Object);
            var segments       = new ConcurrentDictionary <string, Segment>();
            var cache          = new InMemorySegmentCache(segments);
            var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, gates, cache);

            //Act
            segmentFetcher.FetchSegment();

            //Assert
            Assert.IsTrue(gates.AreSegmentsReady(1));
        }
Exemplo n.º 3
0
        public void FetchSegmentNullChangesFetcherResponseShouldNotUpdateCache()
        {
            //Arrange
            var apiClient = new Mock <ISegmentSdkApiClient>();

            apiClient
            .Setup(x => x.FetchSegmentChanges(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <FetchOptions>()))
            .Throws(new Exception());
            var apiFetcher     = new ApiSegmentChangeFetcher(apiClient.Object);
            var segments       = new ConcurrentDictionary <string, Segment>();
            var cache          = new InMemorySegmentCache(segments);
            var segmentFetcher = new SelfRefreshingSegment("payed", apiFetcher, cache);

            //Act
            segmentFetcher.FetchSegment(new FetchOptions());

            //Assert
            Assert.AreEqual(0, segments.Count);
        }