public ProjectSnapshotManagerBenchmarkBase()
        {
            var current = new DirectoryInfo(AppContext.BaseDirectory);

            while (current != null && !File.Exists(Path.Combine(current.FullName, "src", "Razor", "Razor.sln")))
            {
                current = current.Parent;
            }

            var root        = current;
            var projectRoot = Path.Combine(root.FullName, "src", "Razor", "test", "testapps", "LargeProject");

            HostProject = new HostProject(Path.Combine(projectRoot, "LargeProject.csproj"), FallbackRazorConfiguration.MVC_2_1, rootNamespace: null);

            TextLoaders = new TextLoader[4];
            for (var i = 0; i < 4; i++)
            {
                var filePath = Path.Combine(projectRoot, "Views", "Home", $"View00{i % 4}.cshtml");
                var text     = SourceText.From(filePath, encoding: null);
                TextLoaders[i] = TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create()));
            }

            Documents = new HostDocument[100];
            for (var i = 0; i < Documents.Length; i++)
            {
                var filePath = Path.Combine(projectRoot, "Views", "Home", $"View00{i % 4}.cshtml");
                Documents[i] = new HostDocument(filePath, $"/Views/Home/View00{i}.cshtml", FileKinds.Legacy);
            }

            var tagHelpers = Path.Combine(root.FullName, "src", "Razor", "benchmarks", "Microsoft.AspNetCore.Razor.Microbenchmarks", "taghelpers.json");

            TagHelperResolver = new StaticTagHelperResolver(ReadTagHelpers(tagHelpers));
        }
示例#2
0
        public override HostDocument Create(string filePath, string targetFilePath, string fileKind)
        {
            if (filePath is null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (targetFilePath is null)
            {
                throw new ArgumentNullException(nameof(targetFilePath));
            }

            var hostDocument = new HostDocument(filePath, targetFilePath, fileKind);

            hostDocument.GeneratedDocumentContainer.GeneratedCSharpChanged += GeneratedDocumentContainer_Changed;
            hostDocument.GeneratedDocumentContainer.GeneratedHtmlChanged   += GeneratedDocumentContainer_Changed;

            return(hostDocument);

            void GeneratedDocumentContainer_Changed(object sender, TextChangeEventArgs args)
            {
                var sharedContainer = _generatedDocumentContainerStore.Get(filePath);
                var container       = (GeneratedDocumentContainer)sender;
                var latestDocument  = (DefaultDocumentSnapshot)container.LatestDocument;

                _ = Task.Factory.StartNew(
                    () => sharedContainer.SetOutputAndCaptureReferenceAsync(latestDocument),
                    CancellationToken.None,
                    TaskCreationOptions.None,
                    TaskScheduler.Default);
            }
        }
        static TestProjectData()
        {
            var baseDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\users\\example\\src" : "/home/example";

            SomeProject                     = new HostProject(Path.Combine(baseDirectory, "SomeProject", "SomeProject.csproj"), RazorConfiguration.Default, "SomeProject");
            SomeProjectFile1                = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "File1.cshtml"), "File1.cshtml", FileKinds.Legacy);
            SomeProjectFile2                = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "File2.cshtml"), "File2.cshtml", FileKinds.Legacy);
            SomeProjectImportFile           = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "_Imports.cshtml"), "_Imports.cshtml", FileKinds.Legacy);
            SomeProjectNestedFile3          = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "Nested", "File3.cshtml"), "Nested\\File1.cshtml", FileKinds.Legacy);
            SomeProjectNestedFile4          = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "Nested", "File4.cshtml"), "Nested\\File2.cshtml", FileKinds.Legacy);
            SomeProjectNestedImportFile     = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "Nested", "_Imports.cshtml"), "Nested\\_Imports.cshtml", FileKinds.Legacy);
            SomeProjectComponentFile1       = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "File1.razor"), "File1.razor", FileKinds.Component);
            SomeProjectComponentFile2       = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "File2.razor"), "File2.razor", FileKinds.Component);
            SomeProjectComponentImportFile1 = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "_Imports.razor"), "_Imports.razor", FileKinds.Component);
            SomeProjectNestedComponentFile3 = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "Nested", "File3.razor"), "Nested\\File1.razor", FileKinds.Component);
            SomeProjectNestedComponentFile4 = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "Nested", "File4.razor"), "Nested\\File2.razor", FileKinds.Component);
            SomeProjectCshtmlComponentFile5 = new HostDocument(Path.Combine(baseDirectory, "SomeProject", "File5.cshtml"), "File5.cshtml", FileKinds.Component);

            AnotherProject                     = new HostProject(Path.Combine(baseDirectory, "AnotherProject", "AnotherProject.csproj"), RazorConfiguration.Default, "AnotherProject");
            AnotherProjectFile1                = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "File1.cshtml"), "File1.cshtml", FileKinds.Legacy);
            AnotherProjectFile2                = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "File2.cshtml"), "File2.cshtml", FileKinds.Legacy);
            AnotherProjectImportFile           = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "_Imports.cshtml"), "_Imports.cshtml", FileKinds.Legacy);
            AnotherProjectNestedFile3          = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "Nested", "File3.cshtml"), "Nested\\File1.cshtml", FileKinds.Legacy);
            AnotherProjectNestedFile4          = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "Nested", "File4.cshtml"), "Nested\\File2.cshtml", FileKinds.Legacy);
            AnotherProjectNestedImportFile     = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "Nested", "_Imports.cshtml"), "Nested\\_Imports.cshtml", FileKinds.Legacy);
            AnotherProjectComponentFile1       = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "File1.razor"), "File1.razor", FileKinds.Component);
            AnotherProjectComponentFile2       = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "File2.razor"), "File2.razor", FileKinds.Component);
            AnotherProjectNestedComponentFile3 = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "Nested", "File3.razor"), "Nested\\File1.razor", FileKinds.Component);
            AnotherProjectNestedComponentFile4 = new HostDocument(Path.Combine(baseDirectory, "AnotherProject", "Nested", "File4.razor"), "Nested\\File2.razor", FileKinds.Component);
        }
        public void UpdateProject_KnownDocuments()
        {
            // Arrange
            var projectManager = TestProjectSnapshotManager.Create(Dispatcher);
            var hostProject    = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            projectManager.ProjectAdded(hostProject);
            var document = new HostDocument("/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy);

            projectManager.DocumentAdded(hostProject, document, Mock.Of <TextLoader>());
            var projectService = CreateProjectService(Mock.Of <ProjectResolver>(), projectManager);
            var newDocument    = new DocumentSnapshotHandle(document.FilePath, document.TargetPath, document.FileKind);

            projectManager.AllowNotifyListeners = true;
            projectManager.Changed += (sender, args) =>
            {
                if (args.Kind == ProjectChangeKind.DocumentRemoved ||
                    args.Kind == ProjectChangeKind.DocumentChanged ||
                    args.Kind == ProjectChangeKind.DocumentAdded)
                {
                    throw new XunitException("Should have nooped");
                }
            };

            // Act & Assert
            projectService.UpdateProject(hostProject.FilePath, hostProject.Configuration, hostProject.RootNamespace, ProjectWorkspaceState.Default, new[] { newDocument });
        }
示例#5
0
        // Adapted from DocumentExcerptServiceTestBase's InitializeDocument.
        // Adds the text to a ProjectSnapshot, generates code, and updates the workspace.
        private Document InitializeDocument(SourceText sourceText)
        {
            var baseDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\users\\example\\src" : "/home/example";
            var hostProject   = new HostProject(
                Path.Combine(baseDirectory, "SomeProject", "SomeProject.csproj"), RazorConfiguration.Default, "SomeProject");
            var hostDocument = new HostDocument(
                Path.Combine(baseDirectory, "SomeProject", "File1.cshtml"), "File1.cshtml", FileKinds.Legacy);

            var project = new DefaultProjectSnapshot(
                ProjectState.Create(Workspace.Services, hostProject)
                .WithAddedHostDocument(hostDocument, () => Task.FromResult(TextAndVersion.Create(sourceText, VersionStamp.Create()))));

            var documentSnapshot = project.GetDocument(hostDocument.FilePath);

            var solution = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                    ProjectId.CreateNewId(Path.GetFileNameWithoutExtension(hostDocument.FilePath)),
                                                                    VersionStamp.Create(),
                                                                    Path.GetFileNameWithoutExtension(hostDocument.FilePath),
                                                                    Path.GetFileNameWithoutExtension(hostDocument.FilePath),
                                                                    LanguageNames.CSharp,
                                                                    hostDocument.FilePath));

            solution = solution.AddDocument(
                DocumentId.CreateNewId(solution.ProjectIds.Single(), hostDocument.FilePath),
                hostDocument.FilePath,
                new GeneratedDocumentTextLoader(documentSnapshot, hostDocument.FilePath));

            var document = solution.Projects.Single().Documents.Single();

            return(document);
        }
        protected RoutingSlipEventDocument(DateTime timestamp, TimeSpan duration, HostInfo host = null)
        {
            Timestamp = timestamp;
            Duration = duration;

            if (host != null)
                Host = new HostDocument(host);
        }
示例#7
0
 public DefaultWorkspaceSemanticTokensRefreshTriggerTest()
 {
     ProjectManager = TestProjectSnapshotManager.Create(LegacyDispatcher);
     ProjectManager.AllowNotifyListeners = true;
     HostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");
     ProjectManager.ProjectAdded(HostProject);
     HostDocument = new HostDocument("/path/to/file.razor", "file.razor");
     ProjectManager.DocumentAdded(HostProject, HostDocument, new EmptyTextLoader(HostDocument.FilePath));
 }
 public DefaultGeneratedDocumentPublisherTest()
 {
     Server         = new TestServer();
     ProjectManager = TestProjectSnapshotManager.Create(Dispatcher);
     ProjectManager.AllowNotifyListeners = true;
     HostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");
     ProjectManager.ProjectAdded(HostProject);
     HostDocument = new HostDocument("/path/to/file.razor", "file.razor");
     ProjectManager.DocumentAdded(HostProject, HostDocument, new EmptyTextLoader(HostDocument.FilePath));
 }
示例#9
0
        protected RoutingSlipEventDocument(DateTime timestamp, TimeSpan duration, HostInfo host = null)
        {
            Timestamp = timestamp;
            Duration  = duration;

            if (host != null)
            {
                Host = new HostDocument(host);
            }
        }
示例#10
0
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                new HostDocument("c:/Test1/Index.cshtml", "Index.cshtml"),
                new HostDocument("c:/Test1/Components/Counter.cshtml", "Components/Counter.cshtml"),
            };

            HostProject1 = new HostProject("c:/Test1/Test1.csproj", RazorConfiguration.Default, "TestRootNamespace");
            HostProject2 = new HostProject("c:/Test2/Test2.csproj", RazorConfiguration.Default, "TestRootNamespace");
        }
        public DocumentOutputReferenceCapturerTest()
        {
            ProjectManager = TestProjectSnapshotManager.Create(Dispatcher);
            ProjectManager.AllowNotifyListeners = true;

            HostProject = new HostProject("C:/path/to/project.csproj", RazorConfiguration.Default, "TestNamespace");
            ProjectManager.ProjectAdded(HostProject);
            HostDocument = new HostDocument("C:/path/to/file.razor", "file.razor");
            ProjectManager.DocumentAdded(HostProject, HostDocument, new EmptyTextLoader(HostDocument.FilePath));

            DocumentOutputReferenceCapturer = new DocumentOutputReferenceCapturer();
            DocumentOutputReferenceCapturer.Initialize(ProjectManager);
        }
示例#12
0
        public OmniSharpHostDocument(string filePath, string targetPath, string kind)
        {
            InternalHostDocument = new HostDocument(filePath, targetPath, kind);

            if (targetPath.Contains("/"))
            {
                throw new FormatException("TargetPath's must use '\\' instead of '/'");
            }

            if (targetPath.StartsWith("\\", StringComparison.Ordinal))
            {
                throw new FormatException("TargetPath's can't start with '\\'");
            }
        }
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                new HostDocument("c:\\Test1\\Index.cshtml", "Index.cshtml"),
                new HostDocument("c:\\Test1\\Components\\Counter.cshtml", "Components\\Counter.cshtml"),
            };

            HostProject1 = new HostProject("c:\\Test1\\Test1.csproj", RazorConfiguration.Default);
            HostProject2 = new HostProject("c:\\Test2\\Test2.csproj", RazorConfiguration.Default);

            var projectId1 = ProjectId.CreateNewId("Test1");
            var projectId2 = ProjectId.CreateNewId("Test2");
        }
示例#14
0
        protected void AddDocument(HostProject hostProject, string filePath, string relativeFilePath)
        {
            ProjectSnapshotManagerDispatcher.AssertDispatcherThread();

            if (_currentDocuments.ContainsKey(filePath))
            {
                return;
            }

            var hostDocument = new HostDocument(filePath, relativeFilePath);

            _projectSnapshotManager.DocumentAdded(hostProject, hostDocument, new FileTextLoader(filePath, defaultEncoding: null));

            _currentDocuments[filePath] = hostDocument;
        }
示例#15
0
        public static TestProjectSnapshot Create(string filePath, string[] documentFilePaths)
        {
            var workspace   = TestWorkspace.Create();
            var hostProject = new HostProject(filePath, RazorConfiguration.Default);
            var state       = ProjectState.Create(workspace.Services, hostProject);

            foreach (var documentFilePath in documentFilePaths)
            {
                var hostDocument = new HostDocument(documentFilePath, documentFilePath);
                state = state.WithAddedHostDocument(hostDocument, () => Task.FromResult(TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default)));
            }
            var testProject = new TestProjectSnapshot(state);

            return(testProject);
        }
示例#16
0
        public static TestDocumentSnapshot Create(string filePath, string text, VersionStamp version)
        {
            var testProject   = TestProjectSnapshot.Create(filePath + ".csproj");
            var testWorkspace = TestWorkspace.Create();
            var hostDocument  = new HostDocument(filePath, filePath);
            var sourceText    = SourceText.From(text);
            var documentState = new DocumentState(
                testWorkspace.Services,
                hostDocument,
                SourceText.From(text),
                version,
                () => Task.FromResult(TextAndVersion.Create(sourceText, version)));
            var testDocument = new TestDocumentSnapshot(testProject, documentState);

            return(testDocument);
        }
示例#17
0
        public void PublishesOnWorkspaceUpdate()
        {
            // Arrange
            var workspaceChangedPublisher = new Mock <WorkspaceSemanticTokensRefreshPublisher>(MockBehavior.Strict);

            workspaceChangedPublisher.Setup(w => w.EnqueueWorkspaceSemanticTokensRefresh());
            var defaultWorkspaceChangedRefresh = new TestDefaultWorkspaceSemanticTokensRefreshTrigger(workspaceChangedPublisher.Object);

            defaultWorkspaceChangedRefresh.Initialize(ProjectManager);

            // Act
            var newDocument = new HostDocument("/path/to/newFile.razor", "newFile.razor");

            ProjectManager.DocumentAdded(HostProject, newDocument, new EmptyTextLoader(newDocument.FilePath));

            // Assert
            workspaceChangedPublisher.VerifyAll();
        }
示例#18
0
        internal DocumentSnapshot GetDocumentSnapshot(string projectFilePath, string filePath, string targetPath)
        {
            var hostProject = new HostProject(projectFilePath, RazorConfiguration.Default, rootNamespace: null);

            using var fileStream = new FileStream(filePath, FileMode.Open);
            var text         = SourceText.From(fileStream);
            var textLoader   = TextLoader.From(TextAndVersion.Create(text, VersionStamp.Create()));
            var hostDocument = new HostDocument(filePath, targetPath, FileKinds.Component);

            var projectSnapshotManager = CreateProjectSnapshotManager();

            projectSnapshotManager.ProjectAdded(hostProject);
            projectSnapshotManager.DocumentAdded(hostProject, hostDocument, textLoader);
            var projectSnapshot = projectSnapshotManager.GetOrCreateProject(projectFilePath);

            var documentSnapshot = projectSnapshot.GetDocument(filePath);

            return(documentSnapshot);
        }
        public override HostDocument Create(string documentFilePath)
        {
            var hostDocument = new HostDocument(documentFilePath, documentFilePath);

            hostDocument.GeneratedCodeContainer.GeneratedCodeChanged += (sender, args) =>
            {
                var generatedCodeContainer = (GeneratedCodeContainer)sender;

                IReadOnlyList <TextChange> textChanges;

                if (args.NewText.ContentEquals(args.OldText))
                {
                    // If the content is equal then no need to update the underlying CSharp buffer.
                    textChanges = Array.Empty <TextChange>();
                }
                else
                {
                    textChanges = args.NewText.GetTextChanges(args.OldText);
                }

                var latestDocument = generatedCodeContainer.LatestDocument;

                Task.Factory.StartNew(() =>
                {
                    if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var hostDocumentVersion))
                    {
                        // Cache entry doesn't exist, document most likely was evicted from the cache/too old.
                        return;
                    }

                    var request = new UpdateCSharpBufferRequest()
                    {
                        HostDocumentFilePath = documentFilePath,
                        Changes             = textChanges,
                        HostDocumentVersion = hostDocumentVersion
                    };

                    _router.Client.SendRequest("updateCSharpBuffer", request);
                }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
            };

            return(hostDocument);
        }
        public RazorDiagnosticsPublisherTest()
        {
            var testProjectManager = TestProjectSnapshotManager.Create(Dispatcher);
            var hostProject        = new HostProject("/C:/project/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            testProjectManager.ProjectAdded(hostProject);
            var sourceText         = SourceText.From(string.Empty);
            var textAndVersion     = TextAndVersion.Create(sourceText, VersionStamp.Default);
            var openedHostDocument = new HostDocument("/C:/project/open_document.cshtml", "/C:/project/open_document.cshtml");

            testProjectManager.DocumentAdded(hostProject, openedHostDocument, TextLoader.From(textAndVersion));
            testProjectManager.DocumentOpened(hostProject.FilePath, openedHostDocument.FilePath, sourceText);
            var closedHostDocument = new HostDocument("/C:/project/closed_document.cshtml", "/C:/project/closed_document.cshtml");

            testProjectManager.DocumentAdded(hostProject, closedHostDocument, TextLoader.From(textAndVersion));

            OpenedDocument = testProjectManager.Projects[0].GetDocument(openedHostDocument.FilePath);
            ClosedDocument = testProjectManager.Projects[0].GetDocument(closedHostDocument.FilePath);
            ProjectManager = testProjectManager;
        }
        public DefaultDocumentDivergenceCheckerTest()
        {
            ProjectSnapshotManager = new TestProjectSnapshotManager(Workspace);
            HostProject            = new HostProject("C:/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");
            ProjectSnapshotManager.ProjectAdded(HostProject);
            var cshtmlDocument = new HostDocument("C:/path/to/file1.cshtml", "file1.cshtml", FileKinds.Legacy);

            ProjectSnapshotManager.DocumentAdded(HostProject, cshtmlDocument, new EmptyTextLoader(cshtmlDocument.FilePath));
            var componentDocument = new HostDocument("C:/path/to/file2.razor", "file2.razor", FileKinds.Component);

            ProjectSnapshotManager.DocumentAdded(HostProject, componentDocument, new EmptyTextLoader(componentDocument.FilePath));
            var importDocument = new HostDocument("C:/path/to/_Imports.razor", "_Imports.razor", FileKinds.ComponentImport);

            ProjectSnapshotManager.DocumentAdded(HostProject, importDocument, new EmptyTextLoader(importDocument.FilePath));

            var project = ProjectSnapshotManager.GetLoadedProject(HostProject.FilePath);

            CSHTMLDocument    = project.GetDocument(cshtmlDocument.FilePath);
            ComponentDocument = project.GetDocument(componentDocument.FilePath);
            ImportDocument    = project.GetDocument(importDocument.FilePath);
        }
示例#22
0
        public override HostDocument Create(string filePath, string targetFilePath, string fileKind)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (targetFilePath == null)
            {
                throw new ArgumentNullException(nameof(targetFilePath));
            }

            var hostDocument = new HostDocument(filePath, targetFilePath, fileKind);

            hostDocument.GeneratedDocumentContainer.GeneratedCSharpChanged += GeneratedDocumentContainer_Changed;
            hostDocument.GeneratedDocumentContainer.GeneratedHtmlChanged   += GeneratedDocumentContainer_Changed;

            return(hostDocument);

            void GeneratedDocumentContainer_Changed(object sender, TextChangeEventArgs args)
            {
                var sharedContainer = _generatedDocumentContainerStore.Get(filePath);
                var container       = (GeneratedDocumentContainer)sender;
                var latestDocument  = (DefaultDocumentSnapshot)container.LatestDocument;

                _ = Task.Factory.StartNew(async() =>
                {
                    var codeDocument = await latestDocument.GetGeneratedOutputAsync();

                    sharedContainer.SetOutput(
                        latestDocument,
                        codeDocument.GetCSharpDocument(),
                        codeDocument.GetHtmlDocument(),
                        container.InputVersion,
                        container.OutputCSharpVersion,
                        container.OutputHtmlVersion);
                }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.BackgroundScheduler);
            }
        }
        public void UpdateProject_DoesNotRemoveOrAddDocuments()
        {
            // Arrange
            var projectManager = TestProjectSnapshotManager.Create(Dispatcher);
            var hostProject    = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            projectManager.ProjectAdded(hostProject);
            var hostDocument = new HostDocument("/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy);

            projectManager.DocumentAdded(hostProject, hostDocument, Mock.Of <TextLoader>());
            var projectService  = CreateProjectService(Mock.Of <ProjectResolver>(), projectManager);
            var unknownDocument = new DocumentSnapshotHandle("/path/to/other/file.cshtml", "file.cshtml", FileKinds.Legacy);

            // Act
            projectService.UpdateProject(hostProject.FilePath, hostProject.Configuration, hostProject.RootNamespace, ProjectWorkspaceState.Default, new[] { unknownDocument });

            // Assert
            var project          = projectManager.GetLoadedProject(hostProject.FilePath);
            var documentFilePath = Assert.Single(project.DocumentFilePaths);

            Assert.Equal(hostDocument.FilePath, documentFilePath);
        }
        public void UpdateProject_UpdatingDocument_MapsRelativeFilePathToActualDocument()
        {
            // Arrange
            var projectManager = TestProjectSnapshotManager.Create(Dispatcher);
            var hostProject    = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            projectManager.ProjectAdded(hostProject);
            var hostDocument = new HostDocument("/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy);

            projectManager.DocumentAdded(hostProject, hostDocument, Mock.Of <TextLoader>());
            var projectService = CreateProjectService(Mock.Of <ProjectResolver>(), projectManager);
            var newDocument    = new DocumentSnapshotHandle("file.cshtml", "file.cshtml", FileKinds.Component);

            // Act
            projectService.UpdateProject(hostProject.FilePath, hostProject.Configuration, hostProject.RootNamespace, ProjectWorkspaceState.Default, new[] { newDocument });

            // Assert
            var project  = projectManager.GetLoadedProject(hostProject.FilePath);
            var document = project.GetDocument(hostDocument.FilePath);

            Assert.NotNull(document);
            Assert.Equal(FileKinds.Component, document.FileKind);
        }
示例#25
0
        public void ProjectSnapshotManager_Changed_DocumentChanged_OpenDoc_DoesNotEvictCache()
        {
            // Arrange
            var documentFilePath = "/C:/path/to/file.cshtml";
            var projectFilePath  = "/C:/path/to/project.csproj";
            var container        = Store.Get(documentFilePath);
            var project          = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace");

            ProjectManager.ProjectAdded(project);
            var document = new HostDocument(documentFilePath, "file.cshtml");

            ProjectManager.DocumentAdded(project, document, null);
            ProjectManager.DocumentOpened(projectFilePath, documentFilePath, SourceText.From(string.Empty));
            var oldProject = TestProjectSnapshot.Create(projectFilePath, new[] { documentFilePath });
            var newProjet  = TestProjectSnapshot.Create(projectFilePath, new[] { documentFilePath });
            var args       = new ProjectChangeEventArgs(oldProject, newProjet, documentFilePath, ProjectChangeKind.DocumentChanged);

            // Act
            Store.ProjectSnapshotManager_Changed(null, args);
            var newContainer = Store.Get(documentFilePath);

            // Assert
            Assert.Same(container, newContainer);
        }
示例#26
0
        public void ProjectManager_Changed_NotActive_Noops()
        {
            // Arrange
            var attemptedToSerialize = false;
            var hostProject          = new HostProject(@"C:\path\to\project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
            var hostDocument         = new HostDocument(@"C:\path\to\file.razor", "file.razor");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore,
                onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true)
            {
                EnqueueDelay = 10,
            };

            publisher.Initialize(ProjectSnapshotManager);

            // Act
            ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath));

            // Assert
            Assert.Empty(publisher.DeferredPublishTasks);
            Assert.False(attemptedToSerialize);
        }
示例#27
0
 public DocumentExcerptServiceTestBase()
 {
     HostProject  = TestProjectData.SomeProject;
     HostDocument = TestProjectData.SomeProjectFile1;
 }
示例#28
0
 public OmniSharpHostDocument(string filePath, string targetPath, string kind)
 {
     InternalHostDocument = new HostDocument(filePath, targetPath, kind);
 }