public void BuildManifest_CanCreatesManifest_ForTopLevelFiles()
        {
            // Arrange
            var task          = new TestGenerateEmbeddedResourcesManifest();
            var embeddedFiles = CreateEmbeddedResource(
                CreateMetadata("jquery.validate.js"),
                CreateMetadata("jquery.min.js"),
                CreateMetadata("Site.css"));

            var manifestFiles = task.CreateEmbeddedItems(embeddedFiles);

            var expectedManifest = new Manifest()
            {
                Root = Entry.Directory("").AddRange(
                    Entry.File("jquery.validate.js", "jquery.validate.js"),
                    Entry.File("jquery.min.js", "jquery.min.js"),
                    Entry.File("Site.css", "Site.css"))
            };

            // Act
            var manifest = task.BuildManifest(manifestFiles);

            // Assert
            Assert.Equal(expectedManifest, manifest, ManifestComparer.Instance);
        }
        public void BuildManifest_CanCreatesManifest_ForFilesWithinAFolder()
        {
            // Arrange
            var task          = new TestGenerateEmbeddedResourcesManifest();
            var embeddedFiles = CreateEmbeddedResource(
                CreateMetadata(Path.Combine("wwwroot", "js", "jquery.validate.js")),
                CreateMetadata(Path.Combine("wwwroot", "js", "jquery.min.js")),
                CreateMetadata(Path.Combine("wwwroot", "css", "Site.css")),
                CreateMetadata(Path.Combine("Areas", "Identity", "Views", "Account", "Index.cshtml")));

            var manifestFiles = task.CreateEmbeddedItems(embeddedFiles);

            var expectedManifest = new Manifest()
            {
                Root = Entry.Directory("").AddRange(
                    Entry.Directory("wwwroot").AddRange(
                        Entry.Directory("js").AddRange(
                            Entry.File("jquery.validate.js", "wwwroot.js.jquery.validate.js"),
                            Entry.File("jquery.min.js", "wwwroot.js.jquery.min.js")),
                        Entry.Directory("css").AddRange(
                            Entry.File("Site.css", "wwwroot.css.Site.css"))),
                    Entry.Directory("Areas").AddRange(
                        Entry.Directory("Identity").AddRange(
                            Entry.Directory("Views").AddRange(
                                Entry.Directory("Account").AddRange(
                                    Entry.File("Index.cshtml", "Areas.Identity.Views.Account.Index.cshtml"))))))
            };

            // Act
            var manifest = task.BuildManifest(manifestFiles);

            // Assert
            Assert.Equal(expectedManifest, manifest, ManifestComparer.Instance);
        }
        public void BuildManifest_SupportsFilesAndFoldersWithDifferentCasing()
        {
            // Arrange
            var task          = new TestGenerateEmbeddedResourcesManifest();
            var embeddedFiles = CreateEmbeddedResource(
                CreateMetadata(Path.Combine("A", "b", "c.txt")),
                CreateMetadata(Path.Combine("A", "B", "c.txt")),
                CreateMetadata(Path.Combine("A", "B", "C.txt")),
                CreateMetadata(Path.Combine("A", "b", "C.txt")),
                CreateMetadata(Path.Combine("A", "d")),
                CreateMetadata(Path.Combine("A", "D", "e.txt")));

            var manifestFiles = task.CreateEmbeddedItems(embeddedFiles);

            var expectedManifest = new Manifest()
            {
                Root = Entry.Directory("").AddRange(
                    Entry.Directory("A").AddRange(
                        Entry.Directory("b").AddRange(
                            Entry.File("c.txt", @"A.b.c.txt"),
                            Entry.File("C.txt", @"A.b.C.txt")),
                        Entry.Directory("B").AddRange(
                            Entry.File("c.txt", @"A.B.c.txt"),
                            Entry.File("C.txt", @"A.B.C.txt")),
                        Entry.Directory("D").AddRange(
                            Entry.File("e.txt", "A.D.e.txt")),
                        Entry.File("d", "A.d")))
            };

            // Act
            var manifest = task.BuildManifest(manifestFiles);

            // Assert
            Assert.Equal(expectedManifest, manifest, ManifestComparer.Instance);
        }
        public void BuildManifest_RespectsEntriesWithLogicalName()
        {
            // Arrange
            var task          = new TestGenerateEmbeddedResourcesManifest();
            var embeddedFiles = CreateEmbeddedResource(
                CreateMetadata("jquery.validate.js", null, @"wwwroot\lib\js\jquery.validate.js"),
                CreateMetadata("jquery.min.js", null, @"wwwroot\lib/js\jquery.min.js"),
                CreateMetadata("Site.css", null, "wwwroot/lib/css/site.css"));
            var manifestFiles = task.CreateEmbeddedItems(embeddedFiles);

            var expectedManifest = new Manifest()
            {
                Root = Entry.Directory("").AddRange(
                    Entry.Directory("wwwroot").AddRange(
                        Entry.Directory("lib").AddRange(
                            Entry.Directory("js").AddRange(
                                Entry.File("jquery.validate.js", @"wwwroot\lib\js\jquery.validate.js"),
                                Entry.File("jquery.min.js", @"wwwroot\lib/js\jquery.min.js")),
                            Entry.Directory("css").AddRange(
                                Entry.File("site.css", "wwwroot/lib/css/site.css")))))
            };

            // Act
            var manifest = task.BuildManifest(manifestFiles);

            // Assert
            Assert.Equal(expectedManifest, manifest, ManifestComparer.Instance);
        }
        public void BuildManifest_ThrowsInvalidOperationException_WhenTryingToAddAFolderWithTheSameNameAsAFile()
        {
            // Arrange
            var task          = new TestGenerateEmbeddedResourcesManifest();
            var embeddedFiles = CreateEmbeddedResource(
                CreateMetadata(Path.Combine("A", "b")),
                CreateMetadata(Path.Combine("A", "b", "c.txt")));

            var manifestFiles = task.CreateEmbeddedItems(embeddedFiles);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => task.BuildManifest(manifestFiles));
        }
        public void CreateEmbeddedItems_MapsMetadataFromEmbeddedResources_UsesTheTargetPath()
        {
            // Arrange
            var task          = new TestGenerateEmbeddedResourcesManifest();
            var embeddedFiles = CreateEmbeddedResource(
                CreateMetadata(@"lib\js\jquery.validate.js"));

            var expectedItems = new[]
            {
                CreateEmbeddedItem(@"lib\js\jquery.validate.js", "lib.js.jquery.validate.js")
            };

            // Act
            var embeddedItems = task.CreateEmbeddedItems(embeddedFiles);

            // Assert
            Assert.Equal(expectedItems, embeddedItems);
        }
        public void CreateEmbeddedItems_MapsMetadataFromEmbeddedResources_WithLogicalName()
        {
            // Arrange
            var task = new TestGenerateEmbeddedResourcesManifest();
            var DirectorySeparator = (Path.DirectorySeparatorChar == '\\' ? '/' : '\\');
            var embeddedFiles      = CreateEmbeddedResource(
                CreateMetadata("site.css", null, "site.css"),
                CreateMetadata("lib/jquery.validate.js", null, $"dist{DirectorySeparator}jquery.validate.js"));

            var expectedItems = new[]
            {
                CreateEmbeddedItem("site.css", "site.css"),
                CreateEmbeddedItem(Path.Combine("dist", "jquery.validate.js"), $"dist{DirectorySeparator}jquery.validate.js")
            };

            // Act
            var embeddedItems = task.CreateEmbeddedItems(embeddedFiles);

            // Assert
            Assert.Equal(expectedItems, embeddedItems);
        }