public void GetCacheDependency_ReturnsNullForMappedPaths()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            var actual = provider.GetCacheDependency("~/res/test/testfile.txt", new string[0], DateTime.UtcNow);

            Assert.That(actual, Is.Null);
        }
        public void DirectoryExists_PhysicalDirectoryDoesNotExist()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetMakeRelativeVirtualPathOverride((a, b) => "testDirectory");
            provider.SetCombineVirtualPathOverride((a, b) => "~/res/test/");

            Assert.That(provider.DirectoryExists("~/res/test/testDirectory"), Is.False);
        }
        public void DirectoryExists_NotMappedDirectory_FallsBackToPreviousProvider()
        {
            var previousProviderStub = MockRepository.GenerateStub <VirtualPathProvider>();
            var provider             = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetPrevious(previousProviderStub);

            previousProviderStub.Stub(_ => _.DirectoryExists("~/res/UnknownDirectory/test")).Return(true);

            Assert.That(provider.DirectoryExists("~/res/UnknownDirectory/test"), Is.True);
        }
        public void DirectoryExists()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetMakeRelativeVirtualPathOverride((a, b) => "subfolder");
            provider.SetCombineVirtualPathOverride((a, b) => "~/res/test/");

            Directory.CreateDirectory(Path.Combine(_testDirectory, "testResourceFolder\\subfolder"));

            Assert.That(provider.DirectoryExists("~/res/test/subfolder"));
        }
        public void FileExists_PhysicalFileDoesNotExist()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetMakeRelativeVirtualPathOverride((a, b) => "testfile.txt");
            provider.SetCombineVirtualPathOverride((a, b) => "~/res/test/");

            Directory.CreateDirectory(Path.Combine(_testDirectory, "testResourceFolder"));

            Assert.That(provider.FileExists("~/res/test/testfile.txt"), Is.False);
        }
        public void FileExists()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetMakeRelativeVirtualPathOverride((a, b) => "testfile.txt");
            provider.SetCombineVirtualPathOverride((a, b) => "~/res/test/");

            Directory.CreateDirectory(Path.Combine(_testDirectory, "testResourceFolder"));
            File.WriteAllText(Path.Combine(_testDirectory, "testResourceFolder\\testfile.txt"), "hello");

            Assert.That(provider.FileExists("~/res/test/testfile.txt"));
        }
        public void GetDirectory_NotMappedPath_FallsBackToPreviousProvider()
        {
            var previousProviderStub = MockRepository.GenerateStub <VirtualPathProvider>();
            var provider             = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetPrevious(previousProviderStub);

            var expectedDirectory = new ResourceVirtualDirectory("test", new DirectoryInfo(Path.Combine(_testDirectory, "Directory.txt")));

            previousProviderStub.Stub(_ => _.GetDirectory("~/res/UnknownDirectory/testDirectory")).Return(expectedDirectory);

            var actual = (ResourceVirtualDirectory)provider.GetDirectory("~/res/UnknownDirectory/testDirectory");

            Assert.That(actual, Is.SameAs(expectedDirectory));
        }
        public void GetDirectory()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            provider.SetMakeRelativeVirtualPathOverride((a, b) => "testDirectory");
            provider.SetCombineVirtualPathOverride((a, b) => "~/res/test/");

            var expectedDirectoryPath = Path.Combine(_testDirectory, "testResourceFolder\\testDirectory");

            Directory.CreateDirectory(expectedDirectoryPath);

            var actual = (ResourceVirtualDirectory)provider.GetDirectory("~/res/test/testDirectory");

            Assert.That(actual.PhysicalPath, Is.EqualTo(expectedDirectoryPath));
            Assert.That(actual.Exists);
        }
        public void GetFile_FileInsideMappedSubdirectory()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test/subdirectory", "testResourceFolder") }, _testDirectory);

            provider.SetMakeRelativeVirtualPathOverride((a, b) => "testfile.txt");
            provider.SetCombineVirtualPathOverride((a, b) => "~/res/test/subdirectory");

            var expectedFilePath = Path.Combine(_testDirectory, "testResourceFolder\\testfile.txt");

            Directory.CreateDirectory(Path.Combine(_testDirectory, "testResourceFolder"));
            File.WriteAllText(expectedFilePath, "hello");

            var actual = (ResourceVirtualFile)provider.GetFile("~/res/test/subdirectory/testfile.txt");

            Assert.That(actual.PhysicalPath, Is.EqualTo(expectedFilePath));
            Assert.That(actual.Exists);
        }
        public void IsMappedPath_UnknownResourceDirectory()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            Assert.That(provider.IsMappedPath("~/res/unknown/subdirectory"), Is.False);
        }
        public void IsMappedPath_ResourceFolderRoot()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test", "testResourceFolder") }, _testDirectory);

            Assert.That(provider.IsMappedPath("~/res/"));
        }
        public void IsMappedPath_WithSubDirectoryMapping()
        {
            var provider = new TestableResourceVirtualPathProvider(new[] { new ResourcePathMapping("test/subdirectory", "testResourceFolder") }, _testDirectory);

            Assert.That(provider.IsMappedPath("~/res/test/subdirectory/file.txt"));
        }