public async Task GetLatestOptionsAsync_ReturnsExpectedOptions()
        {
            // Arrange
            var expectedOptions      = new RazorLSPOptions(Trace.Messages, enableFormatting: false, autoClosingTags: false);
            var razorJsonString      = @"
{
  ""trace"": ""Messages"",
  ""format"": {
    ""enable"": ""false""
  }
}
".Trim();
            var htmlJsonString       = @"
{
  ""format"": ""true"",
  ""autoClosingTags"": ""false""
}
".Trim();
            var result               = new JObject[] { JObject.Parse(razorJsonString), JObject.Parse(htmlJsonString) };
            var languageServer       = GetLanguageServer(new ResponseRouterReturns(result));
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);

            // Act
            var options = await configurationService.GetLatestOptionsAsync(CancellationToken.None);

            // Assert
            Assert.Equal(expectedOptions, options);
        }
コード例 #2
0
        public void BuildOptions_ReturnsExpectedOptions()
        {
            // Arrange - purposely choosing options opposite of default
            var expectedOptions = new RazorLSPOptions(
                Trace.Verbose, enableFormatting: false, autoClosingTags: false, insertSpaces: false, tabSize: 8);
            var razorJsonString    = @"
{
  ""trace"": ""Verbose"",
  ""format"": {
    ""enable"": ""false""
  }
}
".Trim();
            var htmlJsonString     = @"
{
  ""format"": ""true"",
  ""autoClosingTags"": ""false""
}
".Trim();
            var vsEditorJsonString = @"
{
  ""IndentSize"": 8,
  ""IndentWithTabs"": ""true""
}
".Trim();

            // Act
            var result               = new JObject[] { JObject.Parse(razorJsonString), JObject.Parse(htmlJsonString), JObject.Parse(vsEditorJsonString) };
            var languageServer       = GetLanguageServer(new ResponseRouterReturns(result));
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);
            var options              = configurationService.BuildOptions(result);

            // Assert
            Assert.Equal(expectedOptions, options);
        }
        public async Task GetLatestOptionsAsync_ClientRequestThrows_ReturnsNull()
        {
            // Arrange
            var languageServer       = GetLanguageServer(result: null, shouldThrow: true);
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);

            // Act
            var options = await configurationService.GetLatestOptionsAsync(CancellationToken.None);

            // Assert
            Assert.Null(options);
        }
        public async Task GetLatestOptionsAsync_EmptyResponse_ReturnsNull()
        {
            // Arrange
            var languageServer       = GetLanguageServer(result: null);
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);

            // Act
            var options = await configurationService.GetLatestOptionsAsync(CancellationToken.None);

            // Assert
            Assert.Null(options);
        }
        public async Task GetLatestOptionsAsync_ClientRequestThrows_ReturnsNull()
        {
            // Arrange
            var languageServer       = GetLanguageServer(Array.Empty <object>(), shouldThrow: true);
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);

            // Act
            var options = await configurationService.GetLatestOptionsAsync();

            // Assert
            Assert.Null(options);
        }
        public async Task GetLatestOptionsAsync_EmptyResponse_ReturnsNull()
        {
            // Arrange
            var languageServer       = GetLanguageServer(Array.Empty <object>());
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);

            // Act
            var options = await configurationService.GetLatestOptionsAsync();

            // Assert
            Assert.Null(options);
        }
コード例 #7
0
        public void BuildOptions_NullOptions()
        {
            // Arrange
            var expectedOptions = RazorLSPOptions.Default;

            // Act
            var result               = new JObject[] { null, null, null };
            var languageServer       = GetLanguageServer(new ResponseRouterReturns(result));
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);
            var options              = configurationService.BuildOptions(result);

            // Assert
            Assert.Equal(expectedOptions, options);
        }
コード例 #8
0
        public void BuildOptions_MalformedOptions()
        {
            // This test is purely to ensure we don't crash if the user provides malformed options.

            // Arrange
            var defaultOptions  = RazorLSPOptions.Default;
            var expectedOptions = new RazorLSPOptions(
                defaultOptions.Trace, defaultOptions.EnableFormatting, defaultOptions.AutoClosingTags,
                insertSpaces: false, defaultOptions.TabSize);
            var razorJsonString    = @"
{
  ""trace"": 0,
  ""format"": {
    ""enable"": ""fals""
  }
}
".Trim();
            var htmlJsonString     = @"
{
  ""format"": """",
}
".Trim();
            var vsEditorJsonString = @"
{
  ""IndentSize"": ""supposedToBeAnInt"",
  ""IndentWithTabs"": 4
}
".Trim();

            // Act
            var result               = new JObject[] { JObject.Parse(razorJsonString), JObject.Parse(htmlJsonString), JObject.Parse(vsEditorJsonString) };
            var languageServer       = GetLanguageServer(new ResponseRouterReturns(result));
            var configurationService = new DefaultRazorConfigurationService(languageServer, LoggerFactory);
            var options              = configurationService.BuildOptions(result);

            // Assert
            Assert.Equal(expectedOptions, options);
        }