コード例 #1
0
        public async Task OnProjectRenamed_RemovesHostProject_CopiesConfiguration()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            RazorComponentWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath));
            RazorComponentWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectComponentFile1.TargetPath);

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));
            RazorGenerateWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectFile1.TargetPath);

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            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(TestProjectData.SomeProject.FilePath, snapshot.FilePath);
            Assert.Same("MVC-2.1", snapshot.Configuration.ConfigurationName);

            // Act - 2
            services.UnconfiguredProject.FullPath = TestProjectData.AnotherProject.FilePath;
            await Task.Run(async() => await host.OnProjectRenamingAsync());

            // Assert - 1
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal(TestProjectData.AnotherProject.FilePath, snapshot.FilePath);
            Assert.Same("MVC-2.1", snapshot.Configuration.ConfigurationName);

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

            Assert.Empty(ProjectManager.Projects);
        }
コード例 #2
0
        public async Task OnProjectChanged_NoVersionFound_DoesNotIniatializeProject()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "");

            ConfigurationItems.Item("TestConfiguration");

            ExtensionItems.Item("TestExtension");

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            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);
        }
コード例 #3
0
        public async Task OnProjectChanged_VersionRemoved_DeinitializesProject()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            RazorComponentWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath));
            RazorComponentWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectComponentFile1.TargetPath);

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));
            RazorGenerateWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectFile1.TargetPath);

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            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(TestProjectData.SomeProject.FilePath, snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName),
                e => Assert.Equal("MVC-2.1", e.ExtensionName));

            // Act - 2
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "");

            changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(changes[0].After),
                ConfigurationItems.ToChange(changes[1].After),
                ExtensionItems.ToChange(changes[2].After),
                RazorComponentWithTargetPathItems.ToChange(changes[3].After),
                RazorGenerateWithTargetPathItems.ToChange(changes[4].After),
            };

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

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

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

            Assert.Empty(ProjectManager.Projects);
        }
コード例 #4
0
        public async Task OnProjectChanged_UpdateProject_Succeeds()
        {
            // Arrange
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.1");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.1");

            ConfigurationItems.Item("MVC-2.1");
            ConfigurationItems.Property("MVC-2.1", Rules.RazorConfiguration.ExtensionsProperty, "MVC-2.1;Another-Thing");

            ExtensionItems.Item("MVC-2.1");
            ExtensionItems.Item("Another-Thing");

            RazorComponentWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath));
            RazorComponentWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectComponentFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectComponentFile1.TargetPath);

            RazorGenerateWithTargetPathItems.Item(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath));
            RazorGenerateWithTargetPathItems.Property(Path.GetFileName(TestProjectData.SomeProjectFile1.FilePath), Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.SomeProjectFile1.TargetPath);

            var changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(),
                ConfigurationItems.ToChange(),
                ExtensionItems.ToChange(),
                RazorComponentWithTargetPathItems.ToChange(),
                RazorGenerateWithTargetPathItems.ToChange(),
            };

            var services = new TestProjectSystemServices(TestProjectData.SomeProject.FilePath);

            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(TestProjectData.SomeProject.FilePath, snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_1, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.1", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName),
                e => Assert.Equal("MVC-2.1", e.ExtensionName));

            Assert.Collection(
                snapshot.DocumentFilePaths.OrderBy(d => d),
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectFile1.TargetPath, document.TargetPath);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            });

            // Act - 2
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorLangVersionProperty, "2.0");
            RazorGeneralProperties.Property(Rules.RazorGeneral.RazorDefaultConfigurationProperty, "MVC-2.0");
            ConfigurationItems.RemoveItem("MVC-2.1");
            ConfigurationItems.Item("MVC-2.0", new Dictionary <string, string>()
            {
                { "Extensions", "MVC-2.0;Another-Thing" },
            });
            ExtensionItems.Item("MVC-2.0");
            RazorComponentWithTargetPathItems.Item(TestProjectData.AnotherProjectNestedComponentFile3.FilePath, new Dictionary <string, string>()
            {
                { Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.AnotherProjectNestedComponentFile3.TargetPath },
            });
            RazorGenerateWithTargetPathItems.Item(TestProjectData.AnotherProjectNestedFile3.FilePath, new Dictionary <string, string>()
            {
                { Rules.RazorGenerateWithTargetPath.TargetPathProperty, TestProjectData.AnotherProjectNestedFile3.TargetPath },
            });

            changes = new TestProjectChangeDescription[]
            {
                RazorGeneralProperties.ToChange(changes[0].After),
                ConfigurationItems.ToChange(changes[1].After),
                ExtensionItems.ToChange(changes[2].After),
                RazorComponentWithTargetPathItems.ToChange(changes[3].After),
                RazorGenerateWithTargetPathItems.ToChange(changes[4].After),
            };

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

            // Assert - 2
            snapshot = Assert.Single(ProjectManager.Projects);
            Assert.Equal(TestProjectData.SomeProject.FilePath, snapshot.FilePath);

            Assert.Equal(RazorLanguageVersion.Version_2_0, snapshot.Configuration.LanguageVersion);
            Assert.Equal("MVC-2.0", snapshot.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Another-Thing", e.ExtensionName),
                e => Assert.Equal("MVC-2.0", e.ExtensionName));

            Assert.Collection(
                snapshot.DocumentFilePaths.OrderBy(d => d),
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.AnotherProjectNestedFile3.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.AnotherProjectNestedFile3.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Legacy, document.FileKind);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.AnotherProjectNestedComponentFile3.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.AnotherProjectNestedComponentFile3.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectFile1.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Legacy, document.FileKind);
            },
                d =>
            {
                var document = snapshot.GetDocument(d);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.FilePath, document.FilePath);
                Assert.Equal(TestProjectData.SomeProjectComponentFile1.TargetPath, document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            });

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

            Assert.Empty(ProjectManager.Projects);
        }