public void WithAnEmbeddedResource_ShouldBeAbleToFindItInVirtualDirectoryWalk() { var appHost = new BasicAppHost(GetType().Assembly); var directory = new ResourceVirtualDirectory(new InMemoryVirtualPathProvider(appHost), null, GetType().Assembly); var resourceFiles = WalkForFiles(directory).ToList(); Assert.IsNotEmpty(resourceFiles); Assert.Contains("/ResourceFile.txt", resourceFiles); }
/// <summary> /// Initializes a new instance of the <see cref="ResourceVirtualFile"/> class. /// </summary> /// <param name="owningProvider">The owning provider.</param> /// <param name="directory">The directory.</param> /// <param name="fileName">Name of the file.</param> /// <exception cref="System.ArgumentNullException">fileName</exception> /// <exception cref="System.ArgumentNullException">directory</exception> public ResourceVirtualFile(IVirtualPathProvider owningProvider, ResourceVirtualDirectory directory, string fileName) : base(owningProvider, directory) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } this.FileName = fileName; this.BackingAssembly = directory.BackingAssembly ?? throw new ArgumentNullException(nameof(directory)); }
public ResourceVirtualFile(IVirtualPathProvider owningProvider, ResourceVirtualDirectory directory, string fileName) : base(owningProvider, directory) { if (string.IsNullOrEmpty(fileName)) throw new ArgumentException("fileName"); if (directory.BackingAssembly == null) throw new ArgumentException("parentDirectory"); this.FileName = fileName; this.BackingAssembly = directory.BackingAssembly; }
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 Children() { var expectedDirectory1 = Directory.CreateDirectory(Path.Combine(_testDirectory, "subDirectory1")); var expectedFile1 = Path.Combine(_testDirectory, "expetedFile1.txt"); File.WriteAllText(expectedFile1, "hello"); var resourceVirtualDirectory = new ResourceVirtualDirectory("~/res/test/", new DirectoryInfo(_testDirectory)); var actual = resourceVirtualDirectory.Children.Cast <VirtualFileBase>().ToArray(); Assert.That(actual.Count(), Is.EqualTo(2)); Assert.That(actual.OfType <ResourceVirtualFile>().Single().PhysicalPath, Is.EqualTo(expectedFile1)); Assert.That(actual.OfType <ResourceVirtualDirectory>().Single().PhysicalPath, Is.EqualTo(expectedDirectory1.FullName)); }
public void Directories() { var expectedDirectory1 = Directory.CreateDirectory(Path.Combine(_testDirectory, "subDirectory1")); var expectedDirectory2 = Directory.CreateDirectory(Path.Combine(_testDirectory, "subDirectory2")); var resourceVirtualDirectory = new ResourceVirtualDirectory("~/res/test/", new DirectoryInfo(_testDirectory)); var actual = resourceVirtualDirectory.Directories.Cast <ResourceVirtualDirectory>(); Assert.That( actual.Select(d => d.PhysicalPath), Is.EquivalentTo( new[] { expectedDirectory1.FullName, expectedDirectory2.FullName })); }
public void Files() { var expectedFile1 = Path.Combine(_testDirectory, "expetedFile1.txt"); var expectedFile2 = Path.Combine(_testDirectory, "expetedFile2.txt"); File.WriteAllText(expectedFile1, "hello"); File.WriteAllText(expectedFile2, "hello"); var resourceVirtualDirectory = new ResourceVirtualDirectory("~/res/test/", new DirectoryInfo(_testDirectory)); var actual = resourceVirtualDirectory.Files.Cast <ResourceVirtualFile>(); Assert.That( actual.Select(d => d.PhysicalPath), Is.EquivalentTo( new[] { expectedFile1, expectedFile2 })); }
public void Directories_ReturnsMappedPaths() { var factoryStub = MockRepository.GenerateStub <Func <string, ResourceVirtualDirectory> >(); var directory = new RootMappingVirtualDirectory( "~/test/", new[] { new ResourcePathMapping("dir1", "testResourceFolder"), new ResourcePathMapping("dir2", "testResourceFolder"), }, new DirectoryInfo("c:\\temp"), factoryStub); var expectedVirtualDirectory1 = new ResourceVirtualDirectory("~/test/dir1/", new DirectoryInfo("c:\\temp\\dir1")); var expectedVirtualDirectory2 = new ResourceVirtualDirectory("~/test/dir2/", new DirectoryInfo("c:\\temp\\dir2")); factoryStub.Stub(_ => _("~/test/dir1/")).Return(expectedVirtualDirectory1); factoryStub.Stub(_ => _("~/test/dir2/")).Return(expectedVirtualDirectory2); Assert.That(directory.Directories, Is.EqualTo(new[] { expectedVirtualDirectory1, expectedVirtualDirectory2 })); }
protected virtual ResourceVirtualDirectory CreateVirtualDirectory(IGrouping<string, string[]> subResources) { var remainingResourceNames = subResources.Select(g => g[1]); var subDir = new ResourceVirtualDirectory( VirtualPathProvider, this, backingAssembly, subResources.Key, remainingResourceNames); return subDir; }
protected override sealed void Initialize() { var asm = BackingAssembly ?? AppHost.GetType().Assembly; RootDir = new ResourceVirtualDirectory(this, null, asm); }
protected sealed override void Initialize() { var asm = BackingAssembly; RootDir = new ResourceVirtualDirectory(this, null, asm, LastModified, RootNamespace); }