public void TryGetConfiguration_FailsIfNoExtensions() { // Arrange var projectState = new Dictionary <string, IProjectRuleSnapshot>() { [Rules.RazorGeneral.SchemaName] = TestProjectRuleSnapshot.CreateProperties( Rules.RazorGeneral.SchemaName, new Dictionary <string, string>() { [Rules.RazorGeneral.RazorDefaultConfigurationProperty] = "13.37", [Rules.RazorGeneral.RazorLangVersionProperty] = "1.0", }), [Rules.RazorConfiguration.SchemaName] = TestProjectRuleSnapshot.CreateItems( Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >() { ["SomeExtension"] = new Dictionary <string, string>() { ["Extensions"] = "Razor-13.37" } }) }.ToImmutableDictionary(); // Act var result = DefaultRazorProjectHost.TryGetConfiguration(projectState, out var configuration); // Assert Assert.False(result); Assert.Null(configuration); }
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); }
public void TryGetExtensions_SucceedsWithSomeConfiguredExtensions() { // Arrange var expectedExtension1Name = "Extension1"; var expectedExtension2Name = "Extension2"; var projectState = new Dictionary <string, IProjectRuleSnapshot>() { [Rules.RazorExtension.PrimaryDataSourceItemType] = TestProjectRuleSnapshot.CreateItems( Rules.RazorExtension.PrimaryDataSourceItemType, new Dictionary <string, Dictionary <string, string> >() { ["UnconfiguredExtensionName"] = new Dictionary <string, string>(), [expectedExtension1Name] = new Dictionary <string, string>(), [expectedExtension2Name] = new Dictionary <string, string>(), }) }.ToImmutableDictionary(); // Act var result = DefaultRazorProjectHost.TryGetExtensions(new[] { expectedExtension1Name, expectedExtension2Name }, projectState, out var extensions); // Assert Assert.True(result); Assert.Collection( extensions, extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName), extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName)); }
public void TryGetConfigurationItem_SucceedsForMatchingConfigurationItem() { // Arrange var expectedConfiguration = "Razor-13.37"; var expectedConfigurationValue = new Dictionary <string, string>() { [Rules.RazorConfiguration.ExtensionsProperty] = "SomeExtension" }; var projectState = new Dictionary <string, IProjectRuleSnapshot>() { [Rules.RazorConfiguration.SchemaName] = TestProjectRuleSnapshot.CreateItems( Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >() { [expectedConfiguration] = expectedConfigurationValue }) }.ToImmutableDictionary(); // Act var result = DefaultRazorProjectHost.TryGetConfigurationItem(expectedConfiguration, projectState, out var configurationItem); // Assert Assert.True(result); Assert.Equal(expectedConfiguration, configurationItem.Key); Assert.True(Enumerable.SequenceEqual(expectedConfigurationValue, configurationItem.Value)); }
public void TryGetConfiguration_SucceedsWithAllPreRequisites() { // Arrange var expectedLanguageVersion = RazorLanguageVersion.Version_1_0; var expectedConfigurationName = "Razor-Test"; var expectedExtension1Name = "Extension1"; var expectedExtension2Name = "Extension2"; var projectState = new Dictionary <string, IProjectRuleSnapshot>() { [Rules.RazorGeneral.SchemaName] = TestProjectRuleSnapshot.CreateProperties( Rules.RazorGeneral.SchemaName, new Dictionary <string, string>() { [Rules.RazorGeneral.RazorDefaultConfigurationProperty] = expectedConfigurationName, [Rules.RazorGeneral.RazorLangVersionProperty] = "1.0", }), [Rules.RazorConfiguration.SchemaName] = TestProjectRuleSnapshot.CreateItems( Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >() { ["UnconfiguredRazorConfiguration"] = new Dictionary <string, string>() { ["Extensions"] = "Razor-9.0" }, [expectedConfigurationName] = new Dictionary <string, string>() { ["Extensions"] = expectedExtension1Name + ";" + expectedExtension2Name } }), [Rules.RazorExtension.PrimaryDataSourceItemType] = TestProjectRuleSnapshot.CreateItems( Rules.RazorExtension.PrimaryDataSourceItemType, new Dictionary <string, Dictionary <string, string> >() { [expectedExtension1Name] = new Dictionary <string, string>(), [expectedExtension2Name] = new Dictionary <string, string>(), }) }.ToImmutableDictionary(); // Act var result = DefaultRazorProjectHost.TryGetConfiguration(projectState, out var configuration); // Assert Assert.True(result); Assert.Equal(expectedLanguageVersion, configuration.LanguageVersion); Assert.Equal(expectedConfigurationName, configuration.ConfigurationName); Assert.Collection( configuration.Extensions, extension => Assert.Equal(expectedExtension2Name, extension.ExtensionName), extension => Assert.Equal(expectedExtension1Name, extension.ExtensionName)); }
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 OnProjectChanged_NoVersionFound_DoesNotIniatializeProject() { // Arrange var changes = new TestProjectChangeDescription[] { new TestProjectChangeDescription() { RuleName = Rules.RazorGeneral.SchemaName, After = TestProjectRuleSnapshot.CreateProperties(Rules.RazorGeneral.SchemaName, new Dictionary <string, string>() { { Rules.RazorGeneral.RazorLangVersionProperty, "" }, { Rules.RazorGeneral.RazorDefaultConfigurationProperty, "" }, }), }, new TestProjectChangeDescription() { RuleName = Rules.RazorConfiguration.SchemaName, After = TestProjectRuleSnapshot.CreateItems(Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >() { }) }, new TestProjectChangeDescription() { RuleName = Rules.RazorExtension.SchemaName, After = TestProjectRuleSnapshot.CreateItems(Rules.RazorExtension.SchemaName, new Dictionary <string, Dictionary <string, string> >() { }) } }; var services = new TestProjectSystemServices("Test.csproj"); var host = new DefaultRazorProjectHost(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 void TryGetConfigurationItem_FailsNoRazorConfigurationItems() { // Arrange var projectState = new Dictionary <string, IProjectRuleSnapshot>() { [Rules.RazorConfiguration.SchemaName] = TestProjectRuleSnapshot.CreateItems( Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >()) }.ToImmutableDictionary(); // Act var result = DefaultRazorProjectHost.TryGetConfigurationItem("Razor-13.37", projectState, out var configurationItem); // Assert Assert.False(result); }
public void TryGetExtensions_SucceedsWithUnConfiguredExtensionTypes() { // Arrange var projectState = new Dictionary <string, IProjectRuleSnapshot>() { [Rules.RazorExtension.PrimaryDataSourceItemType] = TestProjectRuleSnapshot.CreateItems( Rules.RazorExtension.PrimaryDataSourceItemType, new Dictionary <string, Dictionary <string, string> >() { ["UnconfiguredExtensionName"] = new Dictionary <string, string>() }) }.ToImmutableDictionary(); // Act var result = DefaultRazorProjectHost.TryGetExtensions(new[] { "Extension1", "Extension2" }, projectState, out var extensions); // Assert Assert.True(result); Assert.Empty(extensions); }
public async Task OnProjectChanged_AfterDispose_IgnoresUpdate() { // Arrange var changes = new TestProjectChangeDescription[] { new TestProjectChangeDescription() { RuleName = Rules.RazorGeneral.SchemaName, After = TestProjectRuleSnapshot.CreateProperties(Rules.RazorGeneral.SchemaName, new Dictionary <string, string>() { { Rules.RazorGeneral.RazorLangVersionProperty, "2.1" }, { Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1" }, }), }, new TestProjectChangeDescription() { RuleName = Rules.RazorConfiguration.SchemaName, After = TestProjectRuleSnapshot.CreateItems(Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >() { { "MVC-2.1", new Dictionary <string, string>() { { "Extensions", "MVC-2.1;Another-Thing" }, } }, }) }, new TestProjectChangeDescription() { RuleName = Rules.RazorExtension.SchemaName, After = TestProjectRuleSnapshot.CreateItems(Rules.RazorExtension.SchemaName, new Dictionary <string, Dictionary <string, string> >() { { "MVC-2.1", new Dictionary <string, string>() { } }, { "Another-Thing", new Dictionary <string, string>() { } }, }) } }; var services = new TestProjectSystemServices("Test.csproj"); var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager); 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.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion); Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName); Assert.Collection( snapshot.Configuration.Extensions, e => Assert.Equal("MVC-2.1", e.ExtensionName), e => Assert.Equal("Another-Thing", e.ExtensionName)); // Act - 2 await Task.Run(async() => await host.DisposeAsync()); // Assert - 2 Assert.Empty(ProjectManager.Projects); // Act - 3 changes[0].After.SetProperty(Rules.RazorGeneral.RazorLangVersionProperty, "2.0"); changes[0].After.SetProperty(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.0"); changes[1].After.SetItem("MVC-2.0", new Dictionary <string, string>() { { "Extensions", "MVC-2.0;Another-Thing" }, }); await Task.Run(async() => await host.OnProjectChanged(services.CreateUpdate(changes))); // Assert - 3 Assert.Empty(ProjectManager.Projects); }
public async Task OnProjectRenamed_RemovesHostProject_CopiesConfiguration() { // Arrange var changes = new TestProjectChangeDescription[] { new TestProjectChangeDescription() { RuleName = Rules.RazorGeneral.SchemaName, After = TestProjectRuleSnapshot.CreateProperties(Rules.RazorGeneral.SchemaName, new Dictionary <string, string>() { { Rules.RazorGeneral.RazorLangVersionProperty, "2.1" }, { Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1" }, }), }, new TestProjectChangeDescription() { RuleName = Rules.RazorConfiguration.SchemaName, After = TestProjectRuleSnapshot.CreateItems(Rules.RazorConfiguration.SchemaName, new Dictionary <string, Dictionary <string, string> >() { { "MVC-2.1", new Dictionary <string, string>() { { "Extensions", "MVC-2.1;Another-Thing" }, } }, }) }, new TestProjectChangeDescription() { RuleName = Rules.RazorExtension.SchemaName, After = TestProjectRuleSnapshot.CreateItems(Rules.RazorExtension.SchemaName, new Dictionary <string, Dictionary <string, string> >() { { "MVC-2.1", new Dictionary <string, string>() { } }, { "Another-Thing", new Dictionary <string, string>() { } }, }) } }; var services = new TestProjectSystemServices("Test.csproj"); var host = new DefaultRazorProjectHost(services, Workspace, ProjectManager); 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("MVC-2.1", snapshot.Configuration.ConfigurationName); // 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("MVC-2.1", snapshot.Configuration.ConfigurationName); await Task.Run(async() => await host.DisposeAsync()); Assert.Empty(ProjectManager.Projects); }