Пример #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 RazorConfigurationEndpoint(RazorLSPOptionsMonitor optionsMonitor, ILoggerFactory loggerFactory)
        {
            if (optionsMonitor is null)
            {
                throw new ArgumentNullException(nameof(optionsMonitor));
            }

            if (loggerFactory is null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _optionsMonitor = optionsMonitor;
            _logger         = loggerFactory.CreateLogger <RazorConfigurationEndpoint>();
        }
Пример #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.");
        }
Пример #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.");
        }
Пример #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.");
        }
 public ChangeTrackerDisposable(RazorLSPOptionsMonitor monitor, Action <RazorLSPOptions, string> listener)
 {
     _listener = listener;
     _monitor  = monitor;
 }