Beispiel #1
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);
        }
Beispiel #2
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 #3
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);
        }
        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 #5
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 #6
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 #7
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 #8
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_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);
        }
        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 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);
        }