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);
        }
        public FallbackRazorProjectHostTest()
        {
            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Workspace);

            ReferenceItems = new ItemCollection(ManagedProjectSystemSchema.ResolvedCompilationReference.SchemaName);
            ContentItems   = new ItemCollection(ManagedProjectSystemSchema.ContentItem.SchemaName);
            NoneItems      = new ItemCollection(ManagedProjectSystemSchema.NoneItem.SchemaName);
        }
Ejemplo n.º 3
0
        public DefaultRazorProjectHostTest()
        {
            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Workspace);

            ConfigurationItems     = new ItemCollection(Rules.RazorConfiguration.SchemaName);
            ExtensionItems         = new ItemCollection(Rules.RazorExtension.SchemaName);
            DocumentItems          = new ItemCollection(Rules.RazorGenerateWithTargetPath.SchemaName);
            RazorGeneralProperties = new PropertyCollection(Rules.RazorGeneral.SchemaName);
        }
        public FallbackRazorProjectHostTest()
        {
            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Workspace);

            var projectConfigurationFilePathStore = new Mock <ProjectConfigurationFilePathStore>(MockBehavior.Strict);

            projectConfigurationFilePathStore.Setup(s => s.Remove(It.IsAny <string>())).Verifiable();
            ProjectConfigurationFilePathStore = projectConfigurationFilePathStore.Object;

            ReferenceItems = new ItemCollection(ManagedProjectSystemSchema.ResolvedCompilationReference.SchemaName);
            ContentItems   = new ItemCollection(ManagedProjectSystemSchema.ContentItem.SchemaName);
            NoneItems      = new ItemCollection(ManagedProjectSystemSchema.NoneItem.SchemaName);
        }
Ejemplo n.º 5
0
        public void TryGetConfiguredExtensionNames_FailsIfNoExtensions()
        {
            // Arrange
            var items = new ItemCollection(Rules.RazorConfiguration.SchemaName);

            items.Item("Test");

            var item = items.ToSnapshot().Items.Single();

            // Act
            var result = DefaultRazorProjectHost.TryGetExtensionNames(item, out var configuredExtensionnames);

            // Assert
            Assert.False(result);
            Assert.Null(configuredExtensionnames);
        }
        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);
            });
        }
Ejemplo n.º 7
0
        public void TryGetConfiguredExtensionNames_SucceedsIfMultipleExtensions()
        {
            // Arrange
            var items = new ItemCollection(Rules.RazorConfiguration.SchemaName);

            items.Item("Test");
            items.Property("Test", Rules.RazorConfiguration.ExtensionsProperty, "SomeExtensionName;SomeOtherExtensionName");

            var item = items.ToSnapshot().Items.Single();

            // Act
            var result = DefaultRazorProjectHost.TryGetExtensionNames(item, out var configuredExtensionNames);

            // Assert
            Assert.True(result);
            Assert.Collection(
                configuredExtensionNames,
                name => Assert.Equal("SomeExtensionName", name),
                name => Assert.Equal("SomeOtherExtensionName", name));
        }