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
            Assert.True(result);
            Assert.True(File.Exists(expectedFile));

            var actualContents = File.ReadAllText(expectedFile);

            Assert.Equal(BundleWithImportsContent, actualContents, ignoreLineEndingDifferences: true);
        }
        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
            Assert.True(result);
            Assert.True(File.Exists(expectedFile));

            var actualContents = File.ReadAllText(expectedFile);

            Assert.Equal(expectedContent, actualContents, ignoreLineEndingDifferences: true);
        }
        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
            Assert.True(result);
            Assert.True(File.Exists(expectedFile));
            var actualContents = File.ReadAllText(expectedFile);

            Assert.Equal(BundleContent, actualContents, ignoreLineEndingDifferences: true);

            Assert.Equal(lastModified, File.GetLastWriteTimeUtc(expectedFile));
        }
        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
            Assert.True(result);
            Assert.True(File.Exists(expectedFile));

            Assert.Empty(File.ReadAllText(expectedFile));
        }