Exemplo n.º 1
0
        public void ComputesScopes_ComputesUniqueScopes_ForCssFiles()
        {
            // Arrange
            var taskInstance = new ComputeCssScope()
            {
                ScopedCssInput = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor.css"),
                    new TaskItem("TestFiles/Pages/Index.razor.css"),
                    new TaskItem("TestFiles/Pages/Profile.razor.css"),
                },
                TargetName = "Test"
            };

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

            // Assert
            Assert.True(result);
            Assert.Equal(3, taskInstance.ScopedCss.Length);
            Assert.All(taskInstance.ScopedCss, item =>
            {
                var scope = item.GetMetadata("CssScope");
                Assert.NotEmpty(scope);
                Assert.Matches("b-[a-z0-9]+", scope);
            });

            Assert.Equal(3, new HashSet <string>(taskInstance.ScopedCss.Select(s => s.GetMetadata("CssScope"))).Count);
        }
Exemplo n.º 2
0
        public void ComputesScopes_VariesByPath()
        {
            // Arrange
            var taskInstance = new ComputeCssScope()
            {
                ScopedCssInput = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.razor.css"),
                    new TaskItem("TestFiles/Index.razor.css"),
                },
                TargetName = "Test"
            };

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

            // Assert
            Assert.True(result);
            Assert.Equal(2, taskInstance.ScopedCss.Length);
            Assert.NotEqual(taskInstance.ScopedCss[0].GetMetadata("CssScope"), taskInstance.ScopedCss[1].GetMetadata("CssScope"));
        }
Exemplo n.º 3
0
        public void ComputesScopes_IsDeterministic()
        {
            // Arrange
            var taskInstance = new ComputeCssScope()
            {
                ScopedCssInput = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor.css"),
                    new TaskItem("TestFiles/Pages/Index.razor.css"),
                    new TaskItem("TestFiles/Pages/Profile.razor.css"),
                },
                TargetName = "Test"
            };

            // Act
            taskInstance.Execute();
            var existing = taskInstance.ScopedCss.Select(s => s.GetMetadata("CssScope")).OrderBy(id => id).ToArray();

            var result = taskInstance.Execute();

            // Assert
            Assert.Equal(existing, taskInstance.ScopedCss.Select(newScoped => newScoped.GetMetadata("CssScope")).OrderBy(id => id).ToArray());
        }
Exemplo n.º 4
0
        public void ComputesScopes_PreservesUserDefinedScopes()
        {
            // Arrange
            var taskInstance = new ComputeCssScope()
            {
                ScopedCssInput = new[]
                {
                    new TaskItem("TestFiles/Pages/Index.razor.css", new Dictionary <string, string> {
                        ["CssScope"] = "b-predefined"
                    }),
                },
                TargetName = "Test"
            };

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

            // Assert
            Assert.True(result);
            var scopedCss = Assert.Single(taskInstance.ScopedCss);

            Assert.Equal("b-predefined", scopedCss.GetMetadata("CssScope"));
        }
Exemplo n.º 5
0
        public void ComputesScopes_ScopeVariesByTargetName()
        {
            // Arrange
            var taskInstance = new ComputeCssScope()
            {
                ScopedCssInput = new[]
                {
                    new TaskItem("TestFiles/Pages/Counter.razor.css"),
                    new TaskItem("TestFiles/Pages/Index.razor.css"),
                    new TaskItem("TestFiles/Pages/Profile.razor.css"),
                },
                TargetName = "Test"
            };

            // Act
            taskInstance.Execute();
            var existing = taskInstance.ScopedCss.Select(s => s.GetMetadata("CssScope")).ToArray();

            taskInstance.TargetName = "AnotherLibrary";
            var result = taskInstance.Execute();

            // Assert
            Assert.All(taskInstance.ScopedCss, newScoped => Assert.DoesNotContain(newScoped.GetMetadata("ScopedCss"), existing));
        }