public void GetCurrentDocuments_IgnoresDotRazorFiles()
        {
            // Arrange
            ContentItems.Item("Index.razor", new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "NewIndex.razor",
                [ItemReference.FullPathPropertyName] = "C:\\From\\Index.razor",
            });
            NoneItems.Item("About.razor", new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "NewAbout.razor",
                [ItemReference.FullPathPropertyName] = "C:\\From\\About.razor",
            });
            var services = new TestProjectSystemServices("C:\\To\\Test.csproj");
            var host     = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);
            var changes  = new TestProjectChangeDescription[]
            {
                ContentItems.ToChange(),
                NoneItems.ToChange(),
            };
            var update = services.CreateUpdate(changes).Value;

            // Act
            var result = host.GetCurrentDocuments(update);

            // Assert
            Assert.Empty(result);
        }
Beispiel #2
0
        public async Task OnProjectChanged_NoAssemblyFound_DoesNotIniatializeProject()
        {
            // Arrange
            var changes = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
            };
            var services = new TestProjectSystemServices("Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #3
0
        public async Task OnProjectChanged_AssemblyFoundButCannotReadVersion_DoesNotIniatializeProject()
        {
            // Arrange
            var changes = new TestProjectChangeDescription[]
            {
                new TestProjectChangeDescription()
                {
                    RuleName = ManageProjectSystemSchema.ResolvedCompilationReference.SchemaName,
                    After    = TestProjectRuleSnapshot.CreateItems(ManageProjectSystemSchema.ResolvedCompilationReference.SchemaName, new Dictionary <string, Dictionary <string, string> >()
                    {
                        { "c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll", new Dictionary <string, string>() },
                    }),
                },
            };

            var services = new TestProjectSystemServices("Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #4
0
        public async Task OnProjectChanged_AssemblyFoundButCannotReadVersion_DoesNotIniatializeProject()
        {
            // Arrange
            ReferenceItems.Item("c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll");

            var changes = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
            };

            var services = new TestProjectSystemServices("Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
        public async Task OnProjectChanged_ReadsProperties_InitializesProject()
        {
            // Arrange
            ReferenceItems.Item("c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll");

            var changes = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
            };

            var services = new TestProjectSystemServices("Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager)
            {
                AssemblyVersion = new Version(2, 0), // Mock for reading the assembly's version
            };

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("Test.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #6
0
        public async Task OnProjectChanged_UpdateProject_Succeeds()
        {
            // Arrange
            ReferenceItems.Item("c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll");
            var afterChangeContentItems = new ItemCollection(ManagedProjectSystemSchema.ContentItem.SchemaName);

            ContentItems.Item("Index.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.FullPathPropertyName] = "C:\\Path\\Index.cshtml",
            });

            var initialChanges = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
                ContentItems.ToChange(),
            };
            var changes = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
                afterChangeContentItems.ToChange(ContentItems.ToSnapshot()),
            };

            var services = new TestProjectSystemServices("C:\\Path\\Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager)
            {
                AssemblyVersion = new Version(2, 0),
            };

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(initialChanges)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("C:\\Path\\Test.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);
            var filePath = Assert.Single(snapshot.DocumentFilePaths);

            Assert.Equal("C:\\Path\\Index.cshtml", filePath);

            // Act - 2
            host.AssemblyVersion = new Version(1, 0);
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 2
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal("C:\\Path\\Test.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_1_0, snapshot.Configuration);
            Assert.Empty(snapshot.DocumentFilePaths);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #7
0
        public async Task OnProjectChanged_ReadsProperties_InitializesProject()
        {
            // Arrange
            ReferenceItems.Item("c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll");
            ContentItems.Item("Index.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.FullPathPropertyName] = "C:\\Path\\Index.cshtml",
            });
            NoneItems.Item("About.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.FullPathPropertyName] = "C:\\Path\\About.cshtml",
            });

            var changes = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
                ContentItems.ToChange(),
                NoneItems.ToChange(),
            };

            var services = new TestProjectSystemServices("C:\\Path\\Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager)
            {
                AssemblyVersion = new Version(2, 0), // Mock for reading the assembly's version
            };

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("C:\\Path\\Test.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);

            Assert.Collection(
                snapshot.DocumentFilePaths,
                filePath => Assert.Equal("C:\\Path\\Index.cshtml", filePath),
                filePath => Assert.Equal("C:\\Path\\About.cshtml", filePath));

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #8
0
        public async Task FallbackRazorProjectHost_BackgroundThread_CreateAndDispose_Succeeds()
        {
            // Arrange
            var services = new TestProjectSystemServices("Test.csproj");
            var host     = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);

            // Act & Assert
            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #9
0
        public async Task OnProjectRenamed_RemovesHostProject_CopiesConfiguration()
        {
            // Arrange
            var changes = new TestProjectChangeDescription[]
            {
                new TestProjectChangeDescription()
                {
                    RuleName = ManageProjectSystemSchema.ResolvedCompilationReference.SchemaName,
                    After    = TestProjectRuleSnapshot.CreateItems(ManageProjectSystemSchema.ResolvedCompilationReference.SchemaName, new Dictionary <string, Dictionary <string, string> >()
                    {
                        { "c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll", new Dictionary <string, string>() },
                    }),
                },
            };

            var services = new TestProjectSystemServices("Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager)
            {
                AssemblyVersion = new Version(2, 0), // Mock for reading the assembly's version
            };

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("Test.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);

            // Act - 2
            services.UnconfiguredProject.FullPath = "Test2.csproj";
            await Task.Run(async() => await host.OnProjectRenamingAsync());

            // Assert - 1
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal("Test2.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
        public async Task FallbackRazorProjectHost_UIThread_CreateAndDispose_Succeeds()
        {
            // Arrange
            var services = new TestProjectSystemServices("C:\\To\\Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, Dispatcher, ProjectConfigurationFilePathStore, ProjectManager);

            // Act & Assert
            await host.LoadAsync();

            Assert.Empty(ProjectManager.Projects);

            await host.DisposeAsync();

            Assert.Empty(ProjectManager.Projects);
        }
        public async Task FallbackRazorProjectHost_ForegroundThread_CreateAndDispose_Succeeds()
        {
            // Arrange
            var services = new TestProjectSystemServices("C:\\To\\Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, RazorProjectChangePublisher, ProjectManager);

            // Act & Assert
            await host.LoadAsync();

            Assert.Empty(ProjectManager.Projects);

            await host.DisposeAsync();

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #12
0
        public void TryGetRazorDocument_NonRazorFilePath_ReturnsFalse()
        {
            // Arrange
            var services  = new TestProjectSystemServices("C:\\Path\\Test.csproj");
            var host      = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);
            var itemState = new Dictionary <string, string>()
            {
                [ItemReference.FullPathPropertyName] = "C:\\Path\\site.css",
            }.ToImmutableDictionary();

            // Act
            var result = host.TryGetRazorDocument(itemState, out var document);

            // Assert
            Assert.False(result);
            Assert.Null(document);
        }
        public void TryGetRazorDocument_NoFilePath_ReturnsFalse()
        {
            // Arrange
            var services = new TestProjectSystemServices("C:\\To\\Test.csproj");

            var host      = new TestFallbackRazorProjectHost(services, Workspace, Dispatcher, ProjectConfigurationFilePathStore, ProjectManager);
            var itemState = new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName] = "Index.cshtml",
            }.ToImmutableDictionary();

            // Act
            var result = host.TryGetRazorDocument(itemState, out var document);

            // Assert
            Assert.False(result);
            Assert.Null(document);
        }
        public void GetChangedAndRemovedDocuments_ReturnsChangedContentAndNoneItems()
        {
            // Arrange
            var afterChangeContentItems = new ItemCollection(ManagedProjectSystemSchema.ContentItem.SchemaName);

            ContentItems.Item("Index.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "NewIndex.cshtml",
                [ItemReference.FullPathPropertyName] = "C:\\From\\Index.cshtml",
            });
            var afterChangeNoneItems = new ItemCollection(ManagedProjectSystemSchema.NoneItem.SchemaName);

            NoneItems.Item("About.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "NewAbout.cshtml",
                [ItemReference.FullPathPropertyName] = "C:\\From\\About.cshtml",
            });
            var services = new TestProjectSystemServices("C:\\To\\Test.csproj");

            var host    = new TestFallbackRazorProjectHost(services, Workspace, RazorProjectChangePublisher, ProjectManager);
            var changes = new TestProjectChangeDescription[]
            {
                afterChangeContentItems.ToChange(ContentItems.ToSnapshot()),
                afterChangeNoneItems.ToChange(NoneItems.ToSnapshot()),
            };
            var update = services.CreateUpdate(changes).Value;

            // Act
            var result = host.GetChangedAndRemovedDocuments(update);

            // Assert
            Assert.Collection(
                result,
                document =>
            {
                Assert.Equal("C:\\From\\Index.cshtml", document.FilePath);
                Assert.Equal("C:\\To\\NewIndex.cshtml", document.TargetPath);
            },
                document =>
            {
                Assert.Equal("C:\\From\\About.cshtml", document.FilePath);
                Assert.Equal("C:\\To\\NewAbout.cshtml", document.TargetPath);
            });
        }
        public async Task OnProjectRenamed_RemovesHostProject_CopiesConfiguration()
        {
            // Arrange
            ReferenceItems.Item("c:\\nuget\\Microsoft.AspNetCore.Mvc.razor.dll");

            var changes = new TestProjectChangeDescription[]
            {
                ReferenceItems.ToChange(),
            };

            var services = new TestProjectSystemServices("Test.csproj");

            var host = new TestFallbackRazorProjectHost(services, Workspace, Dispatcher, ProjectConfigurationFilePathStore, ProjectManager)
            {
                AssemblyVersion = new Version(2, 0), // Mock for reading the assembly's version
            };

            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            // Act - 1
            await Task.Run(async() => await host.OnProjectChangedAsync(services.CreateUpdate(changes)));

            // Assert - 1
            var snapshot = Assert.Single(ProjectManager.Projects);

            Assert.Equal("Test.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);

            // Act - 2
            services.UnconfiguredProject.FullPath = "Test2.csproj";
            await Task.Run(async() => await host.OnProjectRenamingAsync());

            // Assert - 1
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal("Test2.csproj", snapshot.FilePath);
            Assert.Same(FallbackRazorConfiguration.MVC_2_0, snapshot.Configuration);

            await Task.Run(async() => await host.DisposeAsync());

            Assert.Empty(ProjectManager.Projects);
        }
Beispiel #16
0
        public void TryGetRazorDocument_JustFilePath_ReturnsTrue()
        {
            // Arrange
            var expectedPath = "C:\\Path\\Index.cshtml";
            var services     = new TestProjectSystemServices("C:\\Path\\Test.csproj");
            var host         = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager);
            var itemState    = new Dictionary <string, string>()
            {
                [ItemReference.FullPathPropertyName] = expectedPath,
            }.ToImmutableDictionary();

            // Act
            var result = host.TryGetRazorDocument(itemState, out var document);

            // Assert
            Assert.True(result);
            Assert.Equal(expectedPath, document.FilePath);
            Assert.Equal(expectedPath, document.TargetPath);
        }
        public void GetCurrentDocuments_ReturnsContentAndNoneItems()
        {
            // Arrange
            ContentItems.Item("Index.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "NewIndex.cshtml",
                [ItemReference.FullPathPropertyName] = "C:\\From\\Index.cshtml",
            });
            NoneItems.Item("About.cshtml", new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "NewAbout.cshtml",
                [ItemReference.FullPathPropertyName] = "C:\\From\\About.cshtml",
            });
            var services = new TestProjectSystemServices("C:\\To\\Test.csproj");

            var host    = new TestFallbackRazorProjectHost(services, Workspace, ProjectConfigurationFilePathStore, ProjectManager);
            var changes = new TestProjectChangeDescription[]
            {
                ContentItems.ToChange(),
                NoneItems.ToChange(),
            };
            var update = services.CreateUpdate(changes).Value;

            // Act
            var result = host.GetCurrentDocuments(update);

            // Assert
            Assert.Collection(
                result,
                document =>
            {
                Assert.Equal("C:\\From\\Index.cshtml", document.FilePath);
                Assert.Equal("C:\\To\\NewIndex.cshtml", document.TargetPath);
            },
                document =>
            {
                Assert.Equal("C:\\From\\About.cshtml", document.FilePath);
                Assert.Equal("C:\\To\\NewAbout.cshtml", document.TargetPath);
            });
        }
Beispiel #18
0
        [ForegroundFact] // This can happen if the .xaml files aren't included correctly.
        public async Task OnProjectChanged_NoRulesDefined()
        {
            // Arrange
            var changes = new TestProjectChangeDescription[]
            {
            };

            var services = new TestProjectSystemServices("Test.csproj");
            var host     = new TestFallbackRazorProjectHost(services, Workspace, ProjectManager)
            {
                AssemblyVersion = new Version(2, 0),
            };

            // Act & Assert
            await Task.Run(async() => await host.LoadAsync());

            Assert.Empty(ProjectManager.Projects);

            await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes)));

            Assert.Empty(ProjectManager.Projects);
        }
        public void TryGetRazorDocument_SetsLegacyFileKind()
        {
            // Arrange
            var expectedFullPath   = "C:\\Path\\From\\Index.cshtml";
            var expectedTargetPath = "C:\\Path\\To\\Index.cshtml";
            var services           = new TestProjectSystemServices("C:\\Path\\To\\Test.csproj");

            var host      = new TestFallbackRazorProjectHost(services, Workspace, RazorProjectChangePublisher, ProjectManager);
            var itemState = new Dictionary <string, string>()
            {
                [ItemReference.LinkPropertyName]     = "Index.cshtml",
                [ItemReference.FullPathPropertyName] = expectedFullPath,
            }.ToImmutableDictionary();

            // Act
            var result = host.TryGetRazorDocument(itemState, out var document);

            // Assert
            Assert.True(result);
            Assert.Equal(expectedFullPath, document.FilePath);
            Assert.Equal(expectedTargetPath, document.TargetPath);
            Assert.Equal(FileKinds.Legacy, document.FileKind);
        }