Skip to content

Instantly share code, notes, and snippets.

@brunomlopes
Last active August 29, 2015 13:57
Show Gist options
  • Save brunomlopes/9418841 to your computer and use it in GitHub Desktop.
Save brunomlopes/9418841 to your computer and use it in GitHub Desktop.
Test for problem with ServicesStack's ResourceVirtualDirectory
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Funq;
using NUnit.Framework;
using ServiceStack.IO;
using ServiceStack.VirtualPath;
namespace ServiceStack.Common.Tests.VirtualPathProvider
{
[TestFixture]
class EmbeddedResourceVirtualPathDirectoryTests
{
[Test]
public void WithAnEmbeddedResource_ShouldBeAbleToFindItInVirtualDirectoryWalk()
{
var thisAssembly = GetType().Assembly;
var appHost = new FakeAppHost("fake", thisAssembly);
var directory = new ResourceVirtualDirectory(new InMemoryVirtualPathProvider(appHost), null, GetType().Assembly);
var resourceFiles = WalkForFiles(directory).ToList();
Assert.IsNotEmpty(resourceFiles);
Assert.Contains("/VirtualPathProvider/ResourceFile.txt", resourceFiles);
}
private IEnumerable<string> WalkForFiles(IVirtualDirectory resourceVirtualDirectory)
{
return resourceVirtualDirectory.Directories.SelectMany(WalkForFiles)
.Concat(resourceVirtualDirectory.Files.Select(f => f.VirtualPath));
}
class FakeAppHost : AppHostBase
{
public FakeAppHost(string serviceName, params Assembly[] assembliesWithServices)
: base(serviceName, assembliesWithServices)
{
}
public override void Configure(Container container)
{
}
}
}
}
Add the ResourceFile.txt to the test project, set compiling action to "Embedded Resource".
Add the test and run it. It should fail.
this file left empty on purpose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment