コード例 #1
0
        public async Task EnqueuePublish_BatchesPublishRequests()
        {
            // Arrange
            var serializationSuccessful = false;
            var firstSnapshot           = CreateProjectSnapshot("/path/to/project.csproj");
            var secondSnapshot          = CreateProjectSnapshot("/path/to/project.csproj", new[] { "/path/to/file.cshtml" });
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(
                LoggerFactory,
                onSerializeToFile: (snapshot, publishFilePath) =>
            {
                Assert.Same(secondSnapshot, snapshot);
                Assert.Equal(expectedPublishFilePath, publishFilePath);
                serializationSuccessful = true;
            });

            publisher.EnqueueDelay = 10;
            publisher.SetPublishFilePath(firstSnapshot.FilePath, expectedPublishFilePath);

            // Act
            publisher.EnqueuePublish(firstSnapshot);
            publisher.EnqueuePublish(secondSnapshot);

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

            Assert.True(serializationSuccessful);
        }
コード例 #2
0
        public async Task ProjectManager_Changed_EnqueuesPublish(OmniSharpProjectChangeKind changeKind)
        {
            // Arrange
            var serializationSuccessful = false;
            var projectSnapshot         = CreateProjectSnapshot("/path/to/project.csproj");
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(
                LoggerFactory,
                onSerializeToFile: (snapshot, publishFilePath) =>
            {
                Assert.Same(projectSnapshot, snapshot);
                Assert.Equal(expectedPublishFilePath, publishFilePath);
                serializationSuccessful = true;
            });

            publisher.EnqueueDelay = 10;
            publisher.SetPublishFilePath(projectSnapshot.FilePath, expectedPublishFilePath);
            var args = OmniSharpProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, changeKind);

            // Act
            publisher.ProjectManager_Changed(null, args);

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

            Assert.True(serializationSuccessful);
        }
コード例 #3
0
        public async Task ProjectRemoved_DeletesPublishFile()
        {
            // Arrange
            var attemptedToDelete       = false;
            var snapshotManager         = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(LoggerFactory,
                                                           onSerializeToFile: (_, __) => { },
                                                           onDeleteFile: (publishFilePath) =>
            {
                attemptedToDelete = true;
                Assert.Equal(expectedPublishFilePath, publishFilePath);
            });

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

            publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath);
            await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject));

            // Act
            await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject));

            // Assert
            Assert.True(attemptedToDelete);
        }
コード例 #4
0
        public async Task ProjectAdded_PublishesToCorrectFilePath()
        {
            // Arrange
            var snapshotManager         = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var serializationSuccessful = false;
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(
                LoggerFactory,
                onSerializeToFile: (snapshot, publishFilePath) =>
            {
                Assert.Equal(expectedPublishFilePath, publishFilePath);
                serializationSuccessful = true;
            });

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

            publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath);

            // Act
            await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject));

            // Assert
            Assert.True(serializationSuccessful);
        }
コード例 #5
0
        public async Task ProjectManager_Changed_ProjectRemoved_AfterEnqueuedPublish()
        {
            // Arrange
            var attemptedToSerialize    = false;
            var projectSnapshot         = CreateProjectSnapshot("/path/to/project.csproj");
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(
                LoggerFactory,
                onSerializeToFile: (snapshot, publishFilePath) => attemptedToSerialize = true,
                onDeleteFile: (path) => { })
            {
                EnqueueDelay = 10
            };

            publisher.SetPublishFilePath(projectSnapshot.FilePath, expectedPublishFilePath);
            publisher.EnqueuePublish(projectSnapshot);
            var args = OmniSharpProjectChangeEventArgs.CreateTestInstance(projectSnapshot, newer: null, documentFilePath: null, OmniSharpProjectChangeKind.ProjectRemoved);

            // Act
            publisher.ProjectManager_Changed(null, args);

            // Assert
            await Task.Delay(publisher.EnqueueDelay * 3);

            Assert.False(attemptedToSerialize);
        }
コード例 #6
0
        public void Publish_UnsetPublishFilePath_Noops()
        {
            // Arrange
            var publisher = new TestProjectChangePublisher(LoggerFactory);
            var omniSharpProjectSnapshot = CreateProjectSnapshot("/path/to/project.csproj");

            // Act & Assert
            publisher.Publish(omniSharpProjectSnapshot);
        }
コード例 #7
0
        public async Task ProjectRemoved_UnSetPublishFilePath_Noops()
        {
            // Arrange
            var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var publisher       = new TestProjectChangePublisher(LoggerFactory);

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

            await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject));

            // Act & Assert
            await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject));
        }
コード例 #8
0
        public void Publish_PublishesToSetPublishFilePath()
        {
            // Arrange
            var serializationSuccessful  = false;
            var omniSharpProjectSnapshot = CreateProjectSnapshot("/path/to/project.csproj");
            var expectedPublishFilePath  = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(
                LoggerFactory,
                onSerializeToFile: (snapshot, publishFilePath) =>
            {
                Assert.Same(omniSharpProjectSnapshot, snapshot);
                Assert.Equal(expectedPublishFilePath, publishFilePath);
                serializationSuccessful = true;
            });

            publisher.SetPublishFilePath(omniSharpProjectSnapshot.FilePath, expectedPublishFilePath);

            // Act
            publisher.Publish(omniSharpProjectSnapshot);

            // Assert
            Assert.True(serializationSuccessful);
        }