public void ProjectManager_Changed_DocumentOpened_InitializedProject_NotActive_Publishes()
        {
            // Arrange
            var serializationSuccessful = false;
            var hostProject             = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
            var hostDocument            = new HostDocument("/path/to/file.razor", "file.razor");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.FilePath, ProjectWorkspaceState.Default);
            ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath));
            var projectSnapshot = ProjectSnapshotManager.Projects[0];
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";

            ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath);
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            })
            {
                EnqueueDelay = 10,
            };

            publisher.Initialize(ProjectSnapshotManager);

            // Act
            ProjectSnapshotManager.DocumentOpened(hostProject.FilePath, hostDocument.FilePath, SourceText.From(string.Empty));

            // Assert
            Assert.Empty(publisher._deferredPublishTasks);
            Assert.True(serializationSuccessful);
        }
コード例 #2
0
        public async Task ProjectAdded_PublishesToCorrectFilePathAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";

            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                _razorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            })
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var projectFilePath = "/path/to/project.csproj";
            var hostProject     = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace");

            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath);
            var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default);

            // Act
            await RunOnDispatcherThreadAsync(() =>
            {
                ProjectSnapshotManager.ProjectAdded(hostProject);
                ProjectSnapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState);
            }).ConfigureAwait(false);

            // Assert
            Assert.True(serializationSuccessful);
        }
コード例 #3
0
        public async Task ProjectAdded_DoesNotFireWhenNotReadyAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json";

            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            },
                shouldSerialize: false)
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var projectFilePath = @"C:\path\to\project.csproj";
            var hostProject     = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace");

            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath);
            var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default);

            // Act
            await RunOnDispatcherThreadAsync(() =>
            {
                ProjectSnapshotManager.ProjectAdded(hostProject);
                ProjectSnapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState);
            }).ConfigureAwait(false);

            // Assert
            Assert.False(serializationSuccessful);
        }
コード例 #4
0
        public void UpdateGuestProjectManager_ProjectChanged_ProjectWorkspaceStateChange()
        {
            // Arrange
            var oldHandle = new ProjectSnapshotHandleProxy(
                new Uri("vsls:/path/project.csproj"),
                RazorConfiguration.Default,
                "project",
                ProjectWorkspaceState.Default);
            var newProjectWorkspaceState = ProjectWorkspaceStateWithTagHelpers;
            var newHandle = new ProjectSnapshotHandleProxy(
                oldHandle.FilePath,
                oldHandle.Configuration,
                oldHandle.RootNamespace,
                newProjectWorkspaceState);
            var synchronizationService = new ProjectSnapshotSynchronizationService(
                JoinableTaskFactory,
                SessionContext,
                Mock.Of <IProjectSnapshotManagerProxy>(),
                ProjectSnapshotManager);
            var hostProject = new HostProject("/guest/path/project.csproj", RazorConfiguration.Default, "project");

            ProjectSnapshotManager.ProjectAdded(hostProject);
            ProjectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.FilePath, oldHandle.ProjectWorkspaceState);
            var args = new ProjectChangeEventProxyArgs(oldHandle, newHandle, ProjectProxyChangeKind.ProjectChanged);

            // Act
            synchronizationService.UpdateGuestProjectManager(args);

            // Assert
            var project = Assert.Single(ProjectSnapshotManager.Projects);

            Assert.Equal("/guest/path/project.csproj", project.FilePath);
            Assert.Same(RazorConfiguration.Default, project.Configuration);
            Assert.Same(newProjectWorkspaceState.TagHelpers, project.TagHelpers);
        }
        public async Task ProjectAdded_DoesNotFireWhenNotReadyAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";

            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            },
                shouldSerialize: false)
            {
                _active = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            var projectFilePath = "/path/to/project.csproj";
            var hostProject     = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace");

            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath);
            var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default);

            // Act
            await RunOnForegroundAsync(() =>
            {
                ProjectSnapshotManager.ProjectAdded(hostProject);
                ProjectSnapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState);
            }).ConfigureAwait(false);

            // Assert
            var kvp = Assert.Single(publisher._deferredPublishTasks);
            await kvp.Value.ConfigureAwait(false);

            Assert.False(serializationSuccessful);
        }