コード例 #1
0
        public void DoesNotApplyCssScopes_ToRazorComponentsWithoutAssociatedFiles()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorComponents = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor"),
                    new TaskItem("TestFiles/Pages/Index.razor"),
                    new TaskItem("TestFiles/Pages/FetchData.razor"),
                },
                ScopedCss = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    })
                }
            };

            // Act
            var result = taskInstance.Execute();

            // Assert
            Assert.True(result);
            Assert.DoesNotContain(taskInstance.RazorComponentsWithScopes, rcws => rcws.ItemSpec == "TestFiles/Pages/Fetchdata.razor");
        }
コード例 #2
0
        public void ApplyAllCssScopes_FailsWhenTheScopedCss_DoesNotMatchTheRazorComponent()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorComponents = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor"),
                    new TaskItem("TestFiles/Pages/Index.razor"),
                },
                ScopedCss = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Profile.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "profile-scope"
                    }),
                }
            };

            taskInstance.BuildEngine = Mock.Of <IBuildEngine>();

            // Act
            var result = taskInstance.Execute();

            // Assert
            Assert.False(result);
        }
コード例 #3
0
        public void ScopedCssCanDefineAssociatedRazorComponentFile()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorComponents = new[]
                {
                    new TaskItem("TestFiles/Pages/FetchData.razor")
                },
                ScopedCss = new[]
                {
                    new TaskItem("TestFiles/Pages/Profile.razor.css", new Dictionary <string, string>
                    {
                        ["CssScope"]       = "fetchdata-scope",
                        ["RazorComponent"] = "TestFiles/Pages/FetchData.razor"
                    })
                }
            };

            // Act
            var result = taskInstance.Execute();

            // Assert
            Assert.True(result);
            var rcws = Assert.Single(taskInstance.RazorComponentsWithScopes);

            Assert.Equal("TestFiles/Pages/FetchData.razor", rcws.ItemSpec);
            Assert.Equal("fetchdata-scope", rcws.GetMetadata("CssScope"));
        }
コード例 #4
0
        public void ApplyAllCssScopes_AppliesScopesToRazorFiles()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorComponents = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor"),
                    new TaskItem("TestFiles/Pages/Index.razor"),
                },
                ScopedCss = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    }),
                }
            };

            // Act
            var result = taskInstance.Execute();

            // Assert
            Assert.True(result);
            Assert.Equal(2, taskInstance.RazorComponentsWithScopes.Length);
            Assert.Single(taskInstance.RazorComponentsWithScopes, rcws => rcws.ItemSpec == "TestFiles/Pages/Index.razor" && rcws.GetMetadata("CssScope") == "index-scope");
            Assert.Single(taskInstance.RazorComponentsWithScopes, rcws => rcws.ItemSpec == "TestFiles/Pages/Counter.razor" && rcws.GetMetadata("CssScope") == "counter-scope");
        }
コード例 #5
0
        public void ApplyAllCssScopes_AppliesScopesToRazorViewFiles()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorGenerate = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.cshtml"),
                    new TaskItem("TestFiles/Pages/Index.cshtml"),
                },
                RazorComponents = Array.Empty <ITaskItem>(),
                ScopedCss       = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    }),
                }
            };

            // Act
            var result = taskInstance.Execute();

            // Assert
            result.Should().BeTrue();
            taskInstance.RazorGenerateWithScopes.Should().HaveCount(2);
            taskInstance.RazorGenerateWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/Index.cshtml" && rcws.GetMetadata("CssScope") == "index-scope");
            taskInstance.RazorGenerateWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/Counter.cshtml" && rcws.GetMetadata("CssScope") == "counter-scope");
        }
コード例 #6
0
        public void ApplyAllCssScopes_FailsWhenMultipleScopedCssFiles_MatchTheSameRazorView()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorGenerate = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.cshtml"),
                    new TaskItem("TestFiles/Pages/Index.cshtml"),
                },
                RazorComponents = Array.Empty <ITaskItem>(),
                ScopedCss       = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Profile.cshtml.css", new Dictionary <string, string>
                    {
                        ["CssScope"] = "conflict-scope",
                        ["View"]     = "TestFiles/Pages/Index.cshtml"
                    }),
                }
            };

            taskInstance.BuildEngine = Mock.Of <IBuildEngine>();

            // Act
            var result = taskInstance.Execute();

            // Assert
            result.Should().BeFalse();
        }
コード例 #7
0
        public void ScopedCssCanDefineAssociatedRazorGenerateFile()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorGenerate = new[]
                {
                    new TaskItem("TestFiles/Pages/FetchData.cshtml")
                },
                RazorComponents = Array.Empty <ITaskItem>(),
                ScopedCss       = new[]
                {
                    new TaskItem("TestFiles/Pages/Profile.cshtml.css", new Dictionary <string, string>
                    {
                        ["CssScope"] = "fetchdata-scope",
                        ["View"]     = "TestFiles/Pages/FetchData.cshtml"
                    })
                }
            };

            // Act
            var result = taskInstance.Execute();

            // Assert
            result.Should().BeTrue();
            taskInstance.RazorGenerateWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/FetchData.cshtml" && rcws.GetMetadata("CssScope") == "fetchdata-scope");
        }
コード例 #8
0
        public void DoesNotApplyCssScopes_ToRazorViewsWithoutAssociatedFiles()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorGenerate = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.cshtml"),
                    new TaskItem("TestFiles/Pages/Index.cshtml"),
                    new TaskItem("TestFiles/Pages/FetchData.cshtml"),
                },
                RazorComponents = Array.Empty <ITaskItem>(),
                ScopedCss       = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    })
                }
            };

            // Act
            var result = taskInstance.Execute();

            // Assert
            Assert.True(result);
            result.Should().BeTrue();
            taskInstance.RazorGenerateWithScopes.Should().NotContain(rcws => rcws.ItemSpec == "TestFiles/Pages/Fetchdata.razor");
        }
コード例 #9
0
        public void ApplyAllCssScopes_ScopedCssComponentsDontMatchWithScopedCssViewStylesAndViceversa()
        {
            // Arrange
            var taskInstance = new ApplyCssScopes()
            {
                RazorComponents = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor"),
                    new TaskItem("TestFiles/Pages/Index.razor"),
                },
                RazorGenerate = new[]
                {
                    new TaskItem("TestFiles/Pages/Home.cshtml"),
                    new TaskItem("TestFiles/Pages/_Host.cshtml"),
                },
                ScopedCss = new[]
                {
                    new TaskItem("TestFiles/Pages/Home.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "home-scope"
                    }),
                    new TaskItem("TestFiles/Pages/_Host.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "_host-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Index.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "index-scope"
                    }),
                    new TaskItem("TestFiles/Pages/Counter.cshtml.css", new Dictionary <string, string> {
                        ["CssScope"] = "counter-scope"
                    }),
                }
            };

            taskInstance.BuildEngine = Mock.Of <IBuildEngine>();

            // Act
            var result = taskInstance.Execute();

            // Assert
            result.Should().BeFalse();
        }