Ejemplo n.º 1
0
        public void FullProjectSnapshotHandle_CanRoundTrip()
        {
            // Arrange
            var legacyDocument    = new DocumentSnapshotHandle("/path/to/file.cshtml", "file.cshtml", FileKinds.Legacy);
            var componentDocument = new DocumentSnapshotHandle("/path/to/otherfile.razor", "otherfile.razor", FileKinds.Component);
            var handle            = new FullProjectSnapshotHandle(
                "/path/to/project.csproj",
                Configuration,
                rootNamespace: "TestProject",
                ProjectWorkspaceState,
                new[] { legacyDocument, componentDocument });
            var serializedHandle = JsonConvert.SerializeObject(handle, Converters);

            // Act
            var deserializedHandle = JsonConvert.DeserializeObject <FullProjectSnapshotHandle>(serializedHandle, Converters);

            // Assert
            Assert.Equal(handle.FilePath, deserializedHandle.FilePath);
            Assert.Equal(handle.Configuration, deserializedHandle.Configuration);
            Assert.Equal(handle.RootNamespace, deserializedHandle.RootNamespace);
            Assert.Equal(handle.ProjectWorkspaceState, deserializedHandle.ProjectWorkspaceState);
            Assert.Collection(handle.Documents.OrderBy(doc => doc.FilePath),
                              document =>
            {
                Assert.Equal(legacyDocument.FilePath, document.FilePath);
                Assert.Equal(legacyDocument.TargetPath, document.TargetPath);
                Assert.Equal(legacyDocument.FileKind, document.FileKind);
            },
                              document =>
            {
                Assert.Equal(componentDocument.FilePath, document.FilePath);
                Assert.Equal(componentDocument.TargetPath, document.TargetPath);
                Assert.Equal(componentDocument.FileKind, document.FileKind);
            });
        }
        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 });
        }
        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);
        }