예제 #1
0
        public async Task Handle_CreateComponent()
        {
            // Arrange
            var documentPath = "c:/Test.razor";
            var documentUri  = new Uri(documentPath);
            var contents     = $"@page \"/test\"";
            var codeDocument = CreateCodeDocument(contents);

            var resolver     = new CreateComponentCodeActionResolver(LegacyDispatcher, CreateDocumentResolver(documentPath, codeDocument));
            var actionParams = new CreateComponentCodeActionParams
            {
                Uri  = documentUri,
                Path = "c:/Another.razor",
            };
            var data = JObject.FromObject(actionParams);

            // Act
            var workspaceEdit = await resolver.ResolveAsync(data, default);

            // Assert
            Assert.NotNull(workspaceEdit);
            Assert.NotNull(workspaceEdit.DocumentChanges);
            Assert.Single(workspaceEdit.DocumentChanges);

            var documentChanges  = workspaceEdit.DocumentChanges.ToArray();
            var createFileChange = documentChanges[0];

            Assert.True(createFileChange.IsCreateFile);
        }
예제 #2
0
        public async Task Handle_CreateComponentWithNamespace()
        {
            // Arrange
            var documentPath = "c:/Test.razor";
            var documentUri  = new Uri(documentPath);
            var contents     = $"@page \"/test\"{Environment.NewLine}@namespace Another.Namespace";
            var codeDocument = CreateCodeDocument(contents);

            var resolver     = new CreateComponentCodeActionResolver(LegacyDispatcher, CreateDocumentResolver(documentPath, codeDocument));
            var actionParams = new CreateComponentCodeActionParams
            {
                Uri  = documentUri,
                Path = "c:/Another.razor",
            };
            var data = JObject.FromObject(actionParams);

            // Act
            var workspaceEdit = await resolver.ResolveAsync(data, default);

            // Assert
            Assert.NotNull(workspaceEdit);
            Assert.NotNull(workspaceEdit.DocumentChanges);
            Assert.Equal(2, workspaceEdit.DocumentChanges.Count());

            var documentChanges  = workspaceEdit.DocumentChanges.ToArray();
            var createFileChange = documentChanges[0];

            Assert.True(createFileChange.IsCreateFile);

            var editNewComponentChange = documentChanges[1];
            var editNewComponentEdit   = editNewComponentChange.TextDocumentEdit.Edits.First();

            Assert.Contains("@namespace Another.Namespace", editNewComponentEdit.NewText, StringComparison.Ordinal);
        }
예제 #3
0
        public async Task Handle_MissingFile()
        {
            // Arrange
            var resolver = new CreateComponentCodeActionResolver(LegacyDispatcher, _emptyDocumentResolver);
            var data     = JObject.FromObject(new CreateComponentCodeActionParams()
            {
                Uri  = new Uri("c:/Test.razor"),
                Path = "c:/Another.razor",
            });

            // Act
            var workspaceEdit = await resolver.ResolveAsync(data, default);

            // Assert
            Assert.Null(workspaceEdit);
        }
예제 #4
0
        public async Task Handle_InvalidFileKind()
        {
            // Arrange
            var documentPath = "c:/Test.razor";
            var contents     = $"@page \"/test\"";
            var codeDocument = CreateCodeDocument(contents);

            codeDocument.SetFileKind(FileKinds.Legacy);

            var resolver = new CreateComponentCodeActionResolver(LegacyDispatcher, CreateDocumentResolver(documentPath, codeDocument));
            var data     = JObject.FromObject(new CreateComponentCodeActionParams()
            {
                Uri  = new Uri(documentPath),
                Path = "c:/Another.razor",
            });

            // Act
            var workspaceEdit = await resolver.ResolveAsync(data, default);

            // Assert
            Assert.Null(workspaceEdit);
        }