Ejemplo n.º 1
0
        public void BundlesScopedCssFiles_DoesNotOverrideBundleForSameContents()
        {
            // Arrange
            var expectedFile = Path.Combine(Directory.GetCurrentDirectory(), $"{Guid.NewGuid():N}.css");
            var taskInstance = new ConcatenateCssFiles()
            {
                ScopedCssFiles = new[]
                {
                    new TaskItem(
                        "TestFiles/Generated/Index.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Index.razor.rz.scp.css",
                    }),
                    new TaskItem(
                        "TestFiles/Generated/Counter.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Counter.razor.rz.scp.css",
                    }),
                },
                ProjectBundles = Array.Empty <ITaskItem>(),
                OutputFile     = expectedFile
            };

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

            var lastModified = File.GetLastWriteTimeUtc(expectedFile);

            taskInstance.Execute();

            // Assert
            result.Should().BeTrue();
            File.Exists(expectedFile).Should().BeTrue();
            var actualContents = File.ReadAllText(expectedFile);

            actualContents.Should().Contain(BundleContent);

            lastModified.Should().BeSameDateAs(File.GetLastWriteTimeUtc(expectedFile));
        }
Ejemplo n.º 2
0
        public void BundlesScopedCssFiles_IncludesOtherBundles()
        {
            // Arrange
            var expectedFile = Path.Combine(Directory.GetCurrentDirectory(), $"{Guid.NewGuid():N}.css");
            var taskInstance = new ConcatenateCssFiles()
            {
                ScopedCssFiles = new[]
                {
                    new TaskItem(
                        "TestFiles/Generated/Counter.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Counter.razor.rz.scp.css",
                    }),
                    new TaskItem(
                        "TestFiles/Generated/Index.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Index.razor.rz.scp.css",
                    }),
                },
                ProjectBundles = new[]
                {
                    new TaskItem(
                        "TestFiles/Generated/lib.bundle.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/lib.bundle.scp.css",
                    }),
                    new TaskItem(
                        "TestFiles/Generated/package.bundle.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "",
                        ["RelativePath"] = "TestFiles/Generated/package.bundle.scp.css",
                    }),
                },
                ScopedCssBundleBasePath = "/",
                OutputFile = expectedFile
            };

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

            // Assert
            result.Should().BeTrue();
            File.Exists(expectedFile).Should().BeTrue();

            var actualContents = File.ReadAllText(expectedFile);

            actualContents.Should().Contain(BundleWithImportsContent);
        }
Ejemplo n.º 3
0
        public void BundlesScopedCssFiles_HandlesBasePathCombinationsCorrectly(string finalBasePath, string libraryBasePath, string expectedImport)
        {
            // Arrange
            var expectedContent = BundleWithImportsContent
                                  .Replace("_content/Test/TestFiles/Generated/lib.bundle.scp.css", expectedImport)
                                  .Replace("@import 'TestFiles/Generated/package.bundle.scp.css';", "")
                                  .Replace("\r\n", "\n")
                                  .Replace("\n\n", "\n");

            var expectedFile = Path.Combine(Directory.GetCurrentDirectory(), $"{Guid.NewGuid():N}.css");
            var taskInstance = new ConcatenateCssFiles()
            {
                ScopedCssFiles = new[]
                {
                    new TaskItem(
                        "TestFiles/Generated/Counter.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Counter.razor.rz.scp.css",
                    }),
                    new TaskItem(
                        "TestFiles/Generated/Index.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Index.razor.rz.scp.css",
                    })
                },
                ProjectBundles = new[]
                {
                    new TaskItem(
                        "TestFiles/Generated/lib.bundle.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = libraryBasePath,
                        ["RelativePath"] = "TestFiles/Generated/lib.bundle.scp.css",
                    }),
                },
                ScopedCssBundleBasePath = finalBasePath,
                OutputFile = expectedFile
            };

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

            // Assert
            result.Should().BeTrue();
            File.Exists(expectedFile).Should().BeTrue();

            var actualContents = File.ReadAllText(expectedFile);

            actualContents.Should().BeVisuallyEquivalentTo(expectedContent);
        }
Ejemplo n.º 4
0
        public void BundlesScopedCssFiles_ProducesEmpyBundleIfNoFilesAvailable()
        {
            // Arrange
            var expectedFile = Path.Combine(Directory.GetCurrentDirectory(), $"{Guid.NewGuid():N}.css");
            var taskInstance = new ConcatenateCssFiles()
            {
                ScopedCssFiles = Array.Empty <ITaskItem>(),
                ProjectBundles = Array.Empty <ITaskItem>(),
                OutputFile     = expectedFile
            };

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

            // Assert
            result.Should().BeTrue();
            File.Exists(expectedFile).Should().BeTrue();
            File.ReadAllText(expectedFile).Should().BeEmpty();
        }
Ejemplo n.º 5
0
        public async System.Threading.Tasks.Task BundlesScopedCssFiles_UpdatesBundleWhenContentsChange()
        {
            // Arrange
            var expectedFile = Path.Combine(Directory.GetCurrentDirectory(), $"{Guid.NewGuid():N}.css");
            var taskInstance = new ConcatenateCssFiles()
            {
                ScopedCssFiles = new[]
                {
                    new TaskItem(
                        "TestFiles/Generated/Index.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Index.razor.rz.scp.css",
                    }),
                    new TaskItem(
                        "TestFiles/Generated/Counter.razor.rz.scp.css",
                        new Dictionary <string, string>
                    {
                        ["BasePath"]     = "_content/Test/",
                        ["RelativePath"] = "TestFiles/Generated/Counter.razor.rz.scp.css",
                    }),
                },
                ProjectBundles = Array.Empty <ITaskItem>(),
                OutputFile     = expectedFile
            };

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

            var lastModified = File.GetLastWriteTimeUtc(expectedFile);

            taskInstance.ScopedCssFiles = new[]
            {
                new TaskItem(
                    "TestFiles/Generated/Index.razor.rz.scp.css",
                    new Dictionary <string, string>
                {
                    ["BasePath"]     = "_content/Test/",
                    ["RelativePath"] = "TestFiles/Generated/Index.razor.rz.scp.css",
                }),
                new TaskItem(
                    "TestFiles/Generated/Counter.razor.rz.scp.css",
                    new Dictionary <string, string>
                {
                    ["BasePath"]     = "_content/Test/",
                    ["RelativePath"] = "TestFiles/Generated/Counter.razor.rz.scp.css",
                }),
                new TaskItem(
                    "TestFiles/Generated/FetchData.razor.rz.scp.css",
                    new Dictionary <string, string>
                {
                    ["BasePath"]     = "_content/Test/",
                    ["RelativePath"] = "TestFiles/Generated/FetchData.razor.rz.scp.css",
                }),
            };

            await System.Threading.Tasks.Task.Delay(1000);

            taskInstance.Execute();

            // Assert
            result.Should().BeTrue();
            File.Exists(expectedFile).Should().BeTrue();
            var actualContents = File.ReadAllText(expectedFile);

            actualContents.Should().Contain(UpdatedBundleContent);
            lastModified.Should().NotBe(File.GetLastWriteTimeUtc(expectedFile));
        }