Esempio n. 1
0
        public DefaultProjectSnapshotManagerTest()
        {
            TagHelperResolver = new TestTagHelperResolver();

            HostServices = TestServices.Create(
                new IWorkspaceService[]
            {
                new TestProjectSnapshotProjectEngineFactory(),
            },
                new ILanguageService[]
            {
                TagHelperResolver,
            });

            Documents = new HostDocument[]
            {
                new HostDocument("c:\\MyProject\\File.cshtml", "File.cshtml"),
                new HostDocument("c:\\MyProject\\Index.cshtml", "Index.cshtml"),

                // linked file
                new HostDocument("c:\\SomeOtherProject\\Index.cshtml", "Pages\\Index.cshtml"),
            };

            HostProject = new HostProject("c:\\MyProject\\Test.csproj", FallbackRazorConfiguration.MVC_2_0);
            HostProjectWithConfigurationChange = new HostProject("c:\\MyProject\\Test.csproj", FallbackRazorConfiguration.MVC_1_0);

            Workspace      = TestWorkspace.Create(HostServices);
            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Enumerable.Empty <ProjectSnapshotChangeTrigger>(), Workspace);

            var projectId = ProjectId.CreateNewId("Test");
            var solution  = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                     projectId,
                                                                     VersionStamp.Default,
                                                                     "Test",
                                                                     "Test",
                                                                     LanguageNames.CSharp,
                                                                     "c:\\MyProject\\Test.csproj"));

            WorkspaceProject = solution.GetProject(projectId);

            var vbProjectId = ProjectId.CreateNewId("VB");

            solution = solution.AddProject(ProjectInfo.Create(
                                               vbProjectId,
                                               VersionStamp.Default,
                                               "VB",
                                               "VB",
                                               LanguageNames.VisualBasic,
                                               "VB.vbproj"));
            VBWorkspaceProject = solution.GetProject(vbProjectId);

            var projectWithoutFilePathId = ProjectId.CreateNewId("NoFile");

            solution = solution.AddProject(ProjectInfo.Create(
                                               projectWithoutFilePathId,
                                               VersionStamp.Default,
                                               "NoFile",
                                               "NoFile",
                                               LanguageNames.CSharp));
            WorkspaceProjectWithoutFilePath = solution.GetProject(projectWithoutFilePathId);

            // Approximates a project with multi-targeting
            var projectIdWithDifferentTfm = ProjectId.CreateNewId("TestWithDifferentTfm");

            solution = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                projectIdWithDifferentTfm,
                                                                VersionStamp.Default,
                                                                "Test (Different TFM)",
                                                                "Test",
                                                                LanguageNames.CSharp,
                                                                "c:\\MyProject\\Test.csproj"));
            WorkspaceProjectWithDifferentTfm = solution.GetProject(projectIdWithDifferentTfm);

            SomeTagHelpers = TagHelperResolver.TagHelpers;
            SomeTagHelpers.Add(TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build());

            SourceText = SourceText.From("Hello world");
        }
        public DefaultProjectSnapshotManagerTest()
        {
            // Force VB and C# to Load
            GC.KeepAlive(typeof(Microsoft.CodeAnalysis.CSharp.SyntaxFactory));
            GC.KeepAlive(typeof(Microsoft.CodeAnalysis.VisualBasic.SyntaxFactory));

            TagHelperResolver = new TestTagHelperResolver();

            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.SomeProjectFile2,

                // linked file
                TestProjectData.AnotherProjectNestedFile3,

                TestProjectData.SomeProjectComponentFile1,
                TestProjectData.SomeProjectComponentFile2,
            };

            HostProject = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_2_0);
            HostProjectWithConfigurationChange = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0);

            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Enumerable.Empty <ProjectSnapshotChangeTrigger>(), Workspace);

            var projectId = ProjectId.CreateNewId("Test");
            var solution  = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                     projectId,
                                                                     VersionStamp.Default,
                                                                     "Test",
                                                                     "Test",
                                                                     LanguageNames.CSharp,
                                                                     TestProjectData.SomeProject.FilePath));

            WorkspaceProject = solution.GetProject(projectId);

            var vbProjectId = ProjectId.CreateNewId("VB");

            solution = solution.AddProject(ProjectInfo.Create(
                                               vbProjectId,
                                               VersionStamp.Default,
                                               "VB",
                                               "VB",
                                               LanguageNames.VisualBasic,
                                               "VB.vbproj"));
            VBWorkspaceProject = solution.GetProject(vbProjectId);

            var projectWithoutFilePathId = ProjectId.CreateNewId("NoFile");

            solution = solution.AddProject(ProjectInfo.Create(
                                               projectWithoutFilePathId,
                                               VersionStamp.Default,
                                               "NoFile",
                                               "NoFile",
                                               LanguageNames.CSharp));
            WorkspaceProjectWithoutFilePath = solution.GetProject(projectWithoutFilePathId);

            // Approximates a project with multi-targeting
            var projectIdWithDifferentTfm = ProjectId.CreateNewId("TestWithDifferentTfm");

            solution = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                projectIdWithDifferentTfm,
                                                                VersionStamp.Default,
                                                                "Test (Different TFM)",
                                                                "Test",
                                                                LanguageNames.CSharp,
                                                                TestProjectData.SomeProject.FilePath));
            WorkspaceProjectWithDifferentTfm = solution.GetProject(projectIdWithDifferentTfm);

            SomeTagHelpers = TagHelperResolver.TagHelpers;
            SomeTagHelpers.Add(TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build());

            SourceText = SourceText.From("Hello world");
        }