Esempio n. 1
0
        public async Task UpdateAsync_DoesNotInvoke_OnChangeRegistration_AfterDispose()
        {
            // Arrange
            var expectedOptions = new RazorLSPOptions(Trace.Messages, enableFormatting: false, autoClosingTags: true);
            var configService   = Mock.Of <RazorConfigurationService>(f => f.GetLatestOptionsAsync(CancellationToken.None) == Task.FromResult(expectedOptions));
            var optionsMonitor  = new RazorLSPOptionsMonitor(configService, Cache);
            var called          = false;
            var onChangeToken   = optionsMonitor.OnChange(options =>
            {
                called = true;
            });

            // Act 1
            await optionsMonitor.UpdateAsync(CancellationToken.None);

            // Assert 1
            Assert.True(called, "Registered callback was not called.");

            // Act 2
            called = false;
            onChangeToken.Dispose();
            await optionsMonitor.UpdateAsync(CancellationToken.None);

            // Assert 2
            Assert.False(called, "Registered callback called even after dispose.");
        }
        public async Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken)
        {
            _logger.LogTrace("Settings changed. Updating the server.");

            await _optionsMonitor.UpdateAsync();

            return(new Unit());
        }
Esempio n. 3
0
        public async Task UpdateAsync_ConfigReturnsNull_DoesNotInvoke_OnChangeRegistration()
        {
            // Arrange
            var configService = new Mock <RazorConfigurationService>(MockBehavior.Strict).Object;

            Mock.Get(configService).Setup(s => s.GetLatestOptionsAsync(CancellationToken.None)).ReturnsAsync(value: null);
            var optionsMonitor = new RazorLSPOptionsMonitor(configService, Cache);
            var called         = false;
            var onChangeToken  = optionsMonitor.OnChange(options => called = true);

            // Act
            await optionsMonitor.UpdateAsync(CancellationToken.None);

            // Assert
            Assert.False(called, "Registered callback called even when GetLatestOptionsAsync() returns null.");
        }
Esempio n. 4
0
        public async Task UpdateAsync_ConfigReturnsNull_DoesNotInvoke_OnChangeRegistration()
        {
            // Arrange
            var configService  = Mock.Of <RazorConfigurationService>();
            var optionsMonitor = new RazorLSPOptionsMonitor(configService, Cache);
            var called         = false;
            var onChangeToken  = optionsMonitor.OnChange(options =>
            {
                called = true;
            });

            // Act
            await optionsMonitor.UpdateAsync(CancellationToken.None);

            // Assert
            Assert.False(called, "Registered callback called even when GetLatestOptionsAsync() returns null.");
        }
Esempio n. 5
0
        public async Task UpdateAsync_Invokes_OnChangeRegistration()
        {
            // Arrange
            var expectedOptions = new RazorLSPOptions(Trace.Messages, enableFormatting: false, autoClosingTags: true, insertSpaces: true, tabSize: 4);
            var configService   = Mock.Of <RazorConfigurationService>(f => f.GetLatestOptionsAsync(CancellationToken.None) == Task.FromResult(expectedOptions), MockBehavior.Strict);
            var optionsMonitor  = new RazorLSPOptionsMonitor(configService, Cache);
            var called          = false;

            // Act & Assert
            optionsMonitor.OnChange(options =>
            {
                called = true;
                Assert.Same(expectedOptions, options);
            });
            await optionsMonitor.UpdateAsync(CancellationToken.None);

            Assert.True(called, "Registered callback was not called.");
        }