public void GetFileInfo_ResolveNonExistingFile_ReturnsNotFoundFileInfo()
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Act
            var file = provider.GetFileInfo("some/non/existing/file.txt");

            // Assert
            Assert.IsType <NotFoundFileInfo>(file);
        }
        public void ScopedFileProvider_DoesNotReturnFilesOutOfScope(string path)
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js")),
                                    TestEntry.File("site.css")));

            var provider       = new ManifestEmbeddedFileProvider(assembly);
            var scopedProvider = new ManifestEmbeddedFileProvider(assembly, provider.Manifest.Scope("wwwroot"), DateTimeOffset.UtcNow);

            // Act
            var jqueryValidate = scopedProvider.GetFileInfo(path);

            // Assert
            Assert.IsType <NotFoundFileInfo>(jqueryValidate);
        }
        public void GetDirectoryContents_ReturnsNotFoundDirectoryContents_ForPathsWithInvalidCharacters(string path)
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            // Act
            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Assert
            var directory = provider.GetDirectoryContents(path);

            Assert.IsType <NotFoundDirectoryContents>(directory);
        }
        public void GetFileInfo_EscapingFromTheRootFolder_ReturnsNotFound()
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            // Act
            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Assert
            var jqueryValidate = provider.GetFileInfo(Path.Combine("..", "wwwroot", "jquery.validate.js"));

            Assert.IsType <NotFoundFileInfo>(jqueryValidate);
        }
        public void GetFileInfo_ReturnsNotFoundfileInfo_ForPathsWithInvalidCharacters(string path)
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            // Act
            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Assert
            var file = provider.GetFileInfo(path);

            Assert.IsType <NotFoundFileInfo>(file);
            Assert.Equal(path, file.Name);
        }
        public void Contructor_CanScopeManifestToAFolder()
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js")),
                                    TestEntry.File("site.css")));

            var provider       = new ManifestEmbeddedFileProvider(assembly);
            var scopedProvider = new ManifestEmbeddedFileProvider(assembly, provider.Manifest.Scope("wwwroot"), DateTimeOffset.UtcNow);

            // Act
            var jqueryValidate = scopedProvider.GetFileInfo("jquery.validate.js");

            // Assert
            Assert.True(jqueryValidate.Exists);
            Assert.False(jqueryValidate.IsDirectory);
            Assert.Equal("jquery.validate.js", jqueryValidate.Name);
            Assert.Null(jqueryValidate.PhysicalPath);
            Assert.Equal(0, jqueryValidate.Length);
        }
        public void GetDirectoryContents_EnumeratesFilesAndDirectoriesOnAGivenPath()
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot"),
                                    TestEntry.File("site.css")));

            var provider = new ManifestEmbeddedFileProvider(assembly);

            var expectedContents = new[]
            {
                CreateTestFileInfo("wwwroot", isDirectory: true),
                CreateTestFileInfo("site.css")
            };

            // Act
            var contents = provider.GetDirectoryContents(".").ToArray();

            // Assert
            Assert.Equal(expectedContents, contents, FileInfoComparer.Instance);
        }
        public void GetFileInfo_AllowsLeadingDots_OnThePath()
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            // Act
            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Assert
            var jqueryValidate = provider.GetFileInfo(Path.Combine(".", "wwwroot", "jquery.validate.js"));

            Assert.True(jqueryValidate.Exists);
            Assert.False(jqueryValidate.IsDirectory);
            Assert.Equal("jquery.validate.js", jqueryValidate.Name);
            Assert.Null(jqueryValidate.PhysicalPath);
            Assert.Equal(0, jqueryValidate.Length);
        }
        public void GetFileInfo_ResolvesFiles_WithDifferentCasing(string folder, string file)
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            // Act
            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Assert
            var jqueryValidate = provider.GetFileInfo(Path.Combine(folder, file));

            Assert.True(jqueryValidate.Exists);
            Assert.False(jqueryValidate.IsDirectory);
            Assert.Equal("jquery.validate.js", jqueryValidate.Name);
            Assert.Null(jqueryValidate.PhysicalPath);
            Assert.Equal(0, jqueryValidate.Length);
        }
        public void GetFileInfo_CanResolveFilesInsideAFolder()
        {
            // Arrange
            var assembly = new TestAssembly(
                TestEntry.Directory("unused",
                                    TestEntry.Directory("wwwroot",
                                                        TestEntry.File("jquery.validate.js"),
                                                        TestEntry.File("jquery.min.js"),
                                                        TestEntry.File("site.css"))));

            // Act
            var provider = new ManifestEmbeddedFileProvider(assembly);

            // Assert
            var jqueryValidate = provider.GetFileInfo(Path.Combine("wwwroot", "jquery.validate.js"));

            Assert.True(jqueryValidate.Exists);
            Assert.False(jqueryValidate.IsDirectory);
            Assert.Equal("jquery.validate.js", jqueryValidate.Name);
            Assert.Null(jqueryValidate.PhysicalPath);
            Assert.Equal(0, jqueryValidate.Length);

            var jqueryMin = provider.GetFileInfo(Path.Combine("wwwroot", "jquery.min.js"));

            Assert.True(jqueryMin.Exists);
            Assert.False(jqueryMin.IsDirectory);
            Assert.Equal("jquery.min.js", jqueryMin.Name);
            Assert.Null(jqueryMin.PhysicalPath);
            Assert.Equal(0, jqueryMin.Length);

            var siteCss = provider.GetFileInfo(Path.Combine("wwwroot", "site.css"));

            Assert.True(siteCss.Exists);
            Assert.False(siteCss.IsDirectory);
            Assert.Equal("site.css", siteCss.Name);
            Assert.Null(siteCss.PhysicalPath);
            Assert.Equal(0, siteCss.Length);
        }