public async Task IsPartialComponentClass_NonComponents_ReturnsFalse() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var sourceText = SourceText.From( $@" public partial class NonComponent1 {{}} public class NonComponent2 {{}} public partial class NonComponent3 {{}} public class NonComponent4 {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Initialize document await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.False(result); }
public void IsPartialComponentClass_Uninitialized_ReturnsFalse() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var sourceText = SourceText.From( $@" public partial class TestComponent : {ComponentsApi.IComponent.MetadataName} {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.False(result); }
public async Task IsPartialComponentClass_InitializedDocument_ReturnsTrue() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator, Dispatcher, WorkQueue); var sourceText = SourceText.From( $@" public partial class TestComponent : {ComponentsApi.IComponent.MetadataName} {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = await CSharpSyntaxTree.ParseText(sourceText).GetRootAsync(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Initialize document await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.True(result); }
public async Task IsPartialComponentClass_NonClass_ReturnsFalse() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var sourceText = SourceText.From(string.Empty); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Initialize document await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.False(result); }