public RazorComponentRenameEndpointTest()
 {
     _endpoint = CreateEndpoint();
 }
        private RazorComponentRenameEndpoint CreateEndpoint(LanguageServerFeatureOptions languageServerFeatureOptions = null)
        {
            var tagHelperDescriptors = new List <TagHelperDescriptor>();

            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("First", "First.Components", "Component1"));
            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("First", "Test", "Component2"));
            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("Second", "Second.Components", "Component3"));
            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("Second", "Second.Components", "Component4"));
            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("First", "Test", "Component1337"));
            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("First", "Test.Components", "Directory1"));
            tagHelperDescriptors.AddRange(CreateRazorComponentTagHelperDescriptors("First", "Test.Components", "Directory2"));

            var item1 = CreateProjectItem("@namespace First.Components\n@using Test\n<Component2></Component2>", "c:/First/Component1.razor");
            var item2 = CreateProjectItem("@namespace Test", "c:/First/Component2.razor");
            var item3 = CreateProjectItem("@namespace Second.Components\n<Component3></Component3>", "c:/Second/Component3.razor");
            var item4 = CreateProjectItem("@namespace Second.Components\n<Component3></Component3>\n<Component3></Component3>", "c:/Second/Component4.razor");
            var itemComponentParam = CreateProjectItem("@namespace Second.Components\n<Component3 Title=\"Something\"></Component3>", "c:/Second/Component5.razor");
            var item1337           = CreateProjectItem(string.Empty, "c:/First/Component1337.razor");
            var indexItem          = CreateProjectItem("@namespace First.Components\n@using Test\n<Component1337></Component1337>\n<Test.Component1337></Test.Component1337>", "c:/First/Index.razor");

            var itemDirectory1 = CreateProjectItem("@namespace Test.Components\n<Directory2></Directory2>", "c:/Dir1/Directory1.razor");
            var itemDirectory2 = CreateProjectItem("@namespace Test.Components\n<Directory1></Directory1>", "c:/Dir2/Directory2.razor");

            var fileSystem = new TestRazorProjectFileSystem(new[] { item1, item2, item3, item4, itemComponentParam, indexItem, itemDirectory1, itemDirectory2 });

            var projectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem, builder => {
                builder.AddDirective(NamespaceDirective.Directive);
                builder.AddTagHelpers(tagHelperDescriptors);
            });

            var component1         = CreateRazorDocumentSnapshot(projectEngine, item1, "First.Components", tagHelperDescriptors);
            var component2         = CreateRazorDocumentSnapshot(projectEngine, item2, "Test", tagHelperDescriptors);
            var component3         = CreateRazorDocumentSnapshot(projectEngine, item3, "Second.Components", tagHelperDescriptors);
            var component4         = CreateRazorDocumentSnapshot(projectEngine, item4, "Second.Components", tagHelperDescriptors);
            var componentWithParam = CreateRazorDocumentSnapshot(projectEngine, itemComponentParam, "Second.Components", tagHelperDescriptors);
            var component1337      = CreateRazorDocumentSnapshot(projectEngine, item1337, "Test", tagHelperDescriptors);
            var index = CreateRazorDocumentSnapshot(projectEngine, indexItem, "First.Components", tagHelperDescriptors);
            var directory1Component = CreateRazorDocumentSnapshot(projectEngine, itemDirectory1, "Test.Components", tagHelperDescriptors);
            var directory2Component = CreateRazorDocumentSnapshot(projectEngine, itemDirectory2, "Test.Components", tagHelperDescriptors);

            var firstProject = Mock.Of <ProjectSnapshot>(p =>
                                                         p.FilePath == "c:/First/First.csproj" &&
                                                         p.DocumentFilePaths == new[] { "c:/First/Component1.razor", "c:/First/Component2.razor", itemDirectory1.FilePath, itemDirectory2.FilePath, component1337.FilePath } &&
                                                         p.GetDocument("c:/First/Component1.razor") == component1 &&
                                                         p.GetDocument("c:/First/Component2.razor") == component2 &&
                                                         p.GetDocument(itemDirectory1.FilePath) == directory1Component &&
                                                         p.GetDocument(itemDirectory2.FilePath) == directory2Component &&
                                                         p.GetDocument(component1337.FilePath) == component1337, MockBehavior.Strict);

            var secondProject = Mock.Of <ProjectSnapshot>(p =>
                                                          p.FilePath == "c:/Second/Second.csproj" &&
                                                          p.DocumentFilePaths == new[] { "c:/Second/Component3.razor", "c:/Second/Component4.razor", index.FilePath } &&
                                                          p.GetDocument("c:/Second/Component3.razor") == component3 &&
                                                          p.GetDocument("c:/Second/Component4.razor") == component4 &&
                                                          p.GetDocument("c:/Second/ComponentWithParam.razor") == componentWithParam &&
                                                          p.GetDocument(index.FilePath) == index, MockBehavior.Strict);

            var projectSnapshotManager         = Mock.Of <ProjectSnapshotManagerBase>(p => p.Projects == new[] { firstProject, secondProject }, MockBehavior.Strict);
            var projectSnapshotManagerAccessor = new TestProjectSnapshotManagerAccessor(projectSnapshotManager);

            var documentResolver = Mock.Of <DocumentResolver>(d =>
                                                              d.TryResolveDocument("c:/First/Component1.razor", out component1) == true &&
                                                              d.TryResolveDocument("c:/First/Component2.razor", out component2) == true &&
                                                              d.TryResolveDocument("c:/Second/Component3.razor", out component3) == true &&
                                                              d.TryResolveDocument("c:/Second/Component4.razor", out component4) == true &&
                                                              d.TryResolveDocument("c:/Second/ComponentWithParam.razor", out componentWithParam) == true &&
                                                              d.TryResolveDocument(index.FilePath, out index) == true &&
                                                              d.TryResolveDocument(component1337.FilePath, out component1337) == true &&
                                                              d.TryResolveDocument(itemDirectory1.FilePath, out directory1Component) == true &&
                                                              d.TryResolveDocument(itemDirectory2.FilePath, out directory2Component) == true, MockBehavior.Strict);

            var searchEngine = new DefaultRazorComponentSearchEngine(Dispatcher, projectSnapshotManagerAccessor);

            languageServerFeatureOptions = languageServerFeatureOptions ?? Mock.Of <LanguageServerFeatureOptions>(options => options.SupportsFileManipulation == true, MockBehavior.Strict);
            var endpoint = new RazorComponentRenameEndpoint(Dispatcher, documentResolver, searchEngine, projectSnapshotManagerAccessor, languageServerFeatureOptions);

            return(endpoint);
        }
示例#3
0
        private void CreateEndpoint()
        {
            var tag1                 = CreateRazorComponentTagHelperDescriptor("First", "First.Components", "Component1");
            var tag2                 = CreateRazorComponentTagHelperDescriptor("First", "Test", "Component2");
            var tag3                 = CreateRazorComponentTagHelperDescriptor("Second", "Second.Components", "Component3");
            var tag4                 = CreateRazorComponentTagHelperDescriptor("Second", "Second.Components", "Component4");
            var directory1           = CreateRazorComponentTagHelperDescriptor("First", "Test.Components", "Directory1");
            var directory2           = CreateRazorComponentTagHelperDescriptor("First", "Test.Components", "Directory2");
            var tagHelperDescriptors = new[] { tag1, tag2, tag3, tag4, directory1, directory2 };

            var item1 = CreateProjectItem("@namespace First.Components\n@using Test\n<Component2></Component2>", "c:/First/Component1.razor");
            var item2 = CreateProjectItem("@namespace Test", "c:/First/Component2.razor");
            var item3 = CreateProjectItem("@namespace Second.Components\n<Component3></Component3>", "c:/Second/Component3.razor");
            var item4 = CreateProjectItem("@namespace Second.Components\n<Component3></Component3>\n<Component3></Component3>", "c:/Second/Component4.razor");

            var itemDirectory1 = CreateProjectItem("@namespace Test.Components\n<Directory2></Directory2>", "c:/Dir1/Directory1.razor");
            var itemDirectory2 = CreateProjectItem("@namespace Test.Components\n<Directory1></Directory1>", "c:/Dir2/Directory2.razor");

            var fileSystem = new TestRazorProjectFileSystem(new[] { item1, item2, item3, item4, itemDirectory1, itemDirectory2 });

            _projectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem, builder => {
                builder.AddDirective(NamespaceDirective.Directive);
                builder.AddTagHelpers(tagHelperDescriptors);
            });

            var component1          = CreateRazorDocumentSnapshot(item1, "First.Components");
            var component2          = CreateRazorDocumentSnapshot(item2, "Test");
            var component3          = CreateRazorDocumentSnapshot(item3, "Second.Components");
            var component4          = CreateRazorDocumentSnapshot(item4, "Second.Components");
            var directory1Component = CreateRazorDocumentSnapshot(itemDirectory1, "Test.Components");
            var directory2Component = CreateRazorDocumentSnapshot(itemDirectory2, "Test.Components");

            var firstProject = Mock.Of <ProjectSnapshot>(p =>
                                                         p.FilePath == "c:/First/First.csproj" &&
                                                         p.DocumentFilePaths == new[] { "c:/First/Component1.razor", "c:/First/Component2.razor", itemDirectory1.FilePath, itemDirectory2.FilePath } &&
                                                         p.GetDocument("c:/First/Component1.razor") == component1 &&
                                                         p.GetDocument("c:/First/Component2.razor") == component2 &&
                                                         p.GetDocument(itemDirectory1.FilePath) == directory1Component &&
                                                         p.GetDocument(itemDirectory2.FilePath) == directory2Component);

            var secondProject = Mock.Of <ProjectSnapshot>(p =>
                                                          p.FilePath == "c:/Second/Second.csproj" &&
                                                          p.DocumentFilePaths == new[] { "c:/Second/Component3.razor", "c:/Second/Component4.razor" } &&
                                                          p.GetDocument("c:/Second/Component3.razor") == component3 &&
                                                          p.GetDocument("c:/Second/Component4.razor") == component4);

            var projectSnapshotManager         = Mock.Of <ProjectSnapshotManagerBase>(p => p.Projects == new[] { firstProject, secondProject });
            var projectSnapshotManagerAccessor = new TestProjectSnapshotManagerAccessor(projectSnapshotManager);

            var documentResolver = Mock.Of <DocumentResolver>(d =>
                                                              d.TryResolveDocument("c:/First/Component1.razor", out component1) == true &&
                                                              d.TryResolveDocument("c:/First/Component2.razor", out component2) == true &&
                                                              d.TryResolveDocument("c:/Second/Component3.razor", out component3) == true &&
                                                              d.TryResolveDocument("c:/Second/Component4.razor", out component4) == true &&
                                                              d.TryResolveDocument(itemDirectory1.FilePath, out directory1Component) == true &&
                                                              d.TryResolveDocument(itemDirectory2.FilePath, out directory2Component) == true);

            var searchEngine = new DefaultRazorComponentSearchEngine(Dispatcher, projectSnapshotManagerAccessor);

            _endpoint = new RazorComponentRenameEndpoint(Dispatcher, documentResolver, searchEngine, projectSnapshotManagerAccessor);
        }