public async Task Handle_OnTypeFormatting_UnexpectedTriggerCharacter_ReturnsNull() { // Arrange var content = @" @{ if(true){} }"; var sourceMappings = new List <SourceMapping> { new SourceMapping(new SourceSpan(17, 0), new SourceSpan(17, 0)) }; var codeDocument = CreateCodeDocument(content, sourceMappings); var uri = new Uri("file://path/test.razor"); var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument); var formattingService = new TestRazorFormattingService(); var documentMappingService = new DefaultRazorDocumentMappingService(LoggerFactory); var optionsMonitor = GetOptionsMonitor(enableFormatting: true); var endpoint = new RazorFormattingEndpoint( Dispatcher, documentResolver, formattingService, documentMappingService, optionsMonitor, LoggerFactory); var @params = new DocumentOnTypeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri), Character = ".", Position = new Position(2, 11), Options = new FormattingOptions { InsertSpaces = true, TabSize = 4 } }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.Null(result); }
public async Task Handle_UnsupportedCodeDocument_ReturnsNull() { // Arrange var codeDocument = TestRazorCodeDocument.CreateEmpty(); codeDocument.SetUnsupported(); var uri = new Uri("file://path/test.razor"); var documentResolver = CreateDocumentResolver(uri.AbsolutePath, codeDocument); var formattingService = new TestRazorFormattingService(); var documentMappingService = new DefaultRazorDocumentMappingService(); var adhocWorkspaceFactory = TestAdhocWorkspaceFactory.Instance; var optionsMonitor = GetOptionsMonitor(enableFormatting: true); var endpoint = new RazorFormattingEndpoint( LegacyDispatcher, documentResolver, formattingService, documentMappingService, adhocWorkspaceFactory, optionsMonitor, LoggerFactory); var @params = new DocumentRangeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri) }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.Null(result); }
public async Task Handle_FormattingDisabled_ReturnsNull() { // Arrange var formattingService = new TestRazorFormattingService(); var optionsMonitor = GetOptionsMonitor(enableFormatting: false); var endpoint = new RazorFormattingEndpoint(Dispatcher, EmptyDocumentResolver, formattingService, optionsMonitor, LoggerFactory); var @params = new DocumentRangeFormattingParams(); // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.Null(result); }
public async Task Handle_DocumentNotFound_ReturnsNull() { // Arrange var formattingService = new TestRazorFormattingService(); var optionsMonitor = GetOptionsMonitor(enableFormatting: true); var endpoint = new RazorFormattingEndpoint(Dispatcher, EmptyDocumentResolver, formattingService, optionsMonitor, LoggerFactory); var uri = new Uri("file://path/test.razor"); var @params = new DocumentRangeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri) }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.Null(result); }
public async Task Handle_FormattingEnabled_InvokesFormattingService() { // Arrange var codeDocument = TestRazorCodeDocument.CreateEmpty(); var uri = new Uri("file://path/test.razor"); var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument); var formattingService = new TestRazorFormattingService(); var optionsMonitor = GetOptionsMonitor(enableFormatting: true); var endpoint = new RazorFormattingEndpoint(Dispatcher, documentResolver, formattingService, optionsMonitor, LoggerFactory); var @params = new DocumentRangeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri) }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.NotNull(result); Assert.True(formattingService.Called); }
public async Task Handle_OnTypeFormatting_FormattingDisabled_ReturnsNull() { // Arrange var uri = new Uri("file://path/test.razor"); var formattingService = new TestRazorFormattingService(); var documentMappingService = new DefaultRazorDocumentMappingService(); var adhocWorkspaceFactory = TestAdhocWorkspaceFactory.Instance; var optionsMonitor = GetOptionsMonitor(enableFormatting: false); var endpoint = new RazorFormattingEndpoint( LegacyDispatcher, EmptyDocumentResolver, formattingService, documentMappingService, adhocWorkspaceFactory, optionsMonitor, LoggerFactory); var @params = new DocumentOnTypeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri) }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.Null(result); }
public async Task Handle_OnTypeFormatting_RazorLanguageKind_ReturnsNull() { // Arrange var content = @" @{ if(true){} }"; var sourceMappings = new List <SourceMapping> { new SourceMapping(new SourceSpan(17, 0), new SourceSpan(17, 0)) }; var codeDocument = CreateCodeDocument(content, sourceMappings); var uri = new Uri("file://path/test.razor"); var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument); var formattingService = new TestRazorFormattingService(); var documentMappingService = new Mock <RazorDocumentMappingService>(MockBehavior.Strict); documentMappingService.Setup(s => s.GetLanguageKind(codeDocument, 17)).Returns(RazorLanguageKind.Razor); var adhocWorkspaceFactory = TestAdhocWorkspaceFactory.Instance; var optionsMonitor = GetOptionsMonitor(enableFormatting: true); var endpoint = new RazorFormattingEndpoint( LegacyDispatcher, documentResolver, formattingService, documentMappingService.Object, adhocWorkspaceFactory, optionsMonitor, LoggerFactory); var @params = new DocumentOnTypeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri), Character = "}", Position = new Position(2, 11), Options = new FormattingOptions { InsertSpaces = true, TabSize = 4 } }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.Null(result); }
public async Task Handle_OnTypeFormatting_ReturnsValidResults() { // Arrange var content = @" @{ if(true){} }"; var sourceMappings = new List <SourceMapping> { new SourceMapping(new SourceSpan(17, 0), new SourceSpan(17, 0)) }; var codeDocument = CreateCodeDocument(content, sourceMappings); var uri = new Uri("file://path/test.razor"); var documentResolver = CreateDocumentResolver(uri.GetAbsoluteOrUNCPath(), codeDocument); var formattingService = new TestRazorFormattingService(); var documentMappingService = new DefaultRazorDocumentMappingService(); var adhocWorkspaceFactory = TestAdhocWorkspaceFactory.Instance; var optionsMonitor = GetOptionsMonitor(enableFormatting: true); var endpoint = new RazorFormattingEndpoint( LegacyDispatcher, documentResolver, formattingService, documentMappingService, adhocWorkspaceFactory, optionsMonitor, LoggerFactory); var @params = new DocumentOnTypeFormattingParams() { TextDocument = new TextDocumentIdentifier(uri), Character = "}", Position = new Position(2, 11), Options = new FormattingOptions { InsertSpaces = true, TabSize = 4 } }; // Act var result = await endpoint.Handle(@params, CancellationToken.None); // Assert Assert.NotNull(result); Assert.Collection(Iterate(result.GetEnumerator()), edit => Assert.Equal(edit, new TextEdit { NewText = " ", Range = new Range { Start = new Position { Line = 2, Character = 1 }, End = new Position { Line = 2, Character = 1 } } }), edit => Assert.Equal(edit, new TextEdit { NewText = " ", Range = new Range { Start = new Position { Line = 2, Character = 3 }, End = new Position { Line = 2, Character = 3 } } }), edit => Assert.Equal(edit, new TextEdit { NewText = " ", Range = new Range { Start = new Position { Line = 2, Character = 9 }, End = new Position { Line = 2, Character = 9 } } }), edit => Assert.Equal(edit, new TextEdit { NewText = " ", Range = new Range { Start = new Position { Line = 2, Character = 10 }, End = new Position { Line = 2, Character = 10 } } }));