示例#1
0
        public void ObjectLifecycle_Create_InitialFetch_Timer_Dispose()
        {
            // Arrange
            // The provider will attempt to fetch issues at start up and will loop if it
            // is not connected to the server, so we'll initialise it as connected.
            SetServiceConnectionStatus(isConnected: true);

            // 1. Construction -> timer initialised
            var testSubject = new TestableCachingDecorator(
                wrappedProvider,
                new BoundSonarQubeProject(),
                serviceMock.Object,
                timerFactoryMock.Object);

            // Assert
            timerFactoryMock.VerifyAll();
            timerMock.VerifySet(t => t.AutoReset = true, Times.Once);
            VerifyTimerStart(Times.Once());
            timerRunning.Should().Be(true);

            // 2. Initial fetch
            // The initial fetch is run in a background thread - wait until
            // the wrapped provider indicates that the fetch has started
            WaitForInitialFetchTaskToStart();
            VerifyServiceIsConnected(Times.Exactly(2));

            // Now wait for the fetch to complete
            testSubject.WaitForInitialFetchTaskToComplete();
            wrappedProvider.GetQualityProfileCallCount.Should().Be(Language.SupportedLanguages.Count());

            // 3. Timer event raised -> check attempt is made to synchronize data
            RaiseTimerElapsed(DateTime.UtcNow);
            RaiseTimerElapsed(DateTime.UtcNow);

            VerifyServiceIsConnected(Times.Exactly(4));
            wrappedProvider.GetQualityProfileCallCount.Should().Be(Language.SupportedLanguages.Count() * 3);
            timerRunning.Should().Be(true);

            // 4. Dispose
            testSubject.Dispose();
            testSubject.Dispose();
            testSubject.Dispose();

            // Assert
            timerMock.Verify(x => x.Dispose(), Times.Once);
        }
示例#2
0
        private QualityProfileProviderCachingDecorator CreateTestSubjectWithInitialFetchCompleted()
        {
            // Arrange - intialise in a connected state, then disconnect
            SetServiceConnectionStatus(isConnected: true);

            var testSubject = new TestableCachingDecorator(
                wrappedProvider,
                new BoundSonarQubeProject(),
                serviceMock.Object,
                timerFactoryMock.Object);

            testSubject.WaitForInitialFetchTaskToComplete();

            // Sanity check - should have fetch the data once
            VerifyServiceIsConnected(Times.Exactly(2));
            wrappedProvider.GetQualityProfileCallCount.Should().Be(Language.SupportedLanguages.Count());

            return(testSubject);
        }