Skip to content

Commit

Permalink
Add some coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Jul 1, 2024
1 parent b5c9e6c commit 8c05e90
Showing 1 changed file with 73 additions and 53 deletions.
126 changes: 73 additions & 53 deletions Testing/Acceptance/Modules/IO/VirtualTreeTests.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,73 @@
using System.Threading.Tasks;

using GenHTTP.Api.Content.IO;
using GenHTTP.Api.Routing;

using GenHTTP.Modules.IO;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.IO
{

[TestClass]
public sealed class VirtualTreeTests
{

[TestMethod]
public async Task TestNestedTree()
{
var tree = ResourceTree.FromAssembly("Resources");

var virt = VirtualTree.Create()
.Add("r", tree)
.Build();

var (node, file) = await virt.Find(GetTarget("/r/File.txt"));

Assert.IsNotNull(node);
Assert.IsNotNull(file);

Assert.IsTrue((node as IResourceNode)?.Parent == virt);

Assert.IsNotNull(virt.Modified);
}

[TestMethod]
public async Task TestResource()
{
var virt = VirtualTree.Create()
.Add("res.txt", Resource.FromString("Blubb"))
.Build();

var (node, file) = await virt.Find(GetTarget("/res.txt"));

Assert.IsNotNull(node);
Assert.IsNotNull(file);
}

private static RoutingTarget GetTarget(string path) => new(new PathBuilder(path).Build());

}

}
using System.Net;
using System.Threading.Tasks;

using GenHTTP.Api.Content.IO;
using GenHTTP.Api.Routing;

using GenHTTP.Modules.DirectoryBrowsing;
using GenHTTP.Modules.IO;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace GenHTTP.Testing.Acceptance.Modules.IO
{

[TestClass]
public sealed class VirtualTreeTests
{

[TestMethod]
public async Task TestNestedTree()
{
var tree = ResourceTree.FromAssembly("Resources");

var virt = VirtualTree.Create()
.Add("r", tree)
.Build();

var (node, file) = await virt.Find(GetTarget("/r/File.txt"));

Assert.IsNotNull(node);
Assert.IsNotNull(file);

Assert.IsTrue((node as IResourceNode)?.Parent == virt);

Assert.IsNotNull(virt.Modified);
}

[TestMethod]
public async Task TestResource()
{
var virt = VirtualTree.Create()
.Add("res.txt", Resource.FromString("Blubb"))
.Build();

var (node, file) = await virt.Find(GetTarget("/res.txt"));

Assert.IsNotNull(node);
Assert.IsNotNull(file);
}

[TestMethod]
public async Task TestUsage()
{
var tree = ResourceTree.FromAssembly("Resources");

var virt = VirtualTree.Create()
.Add("r", tree)
.Add("res.txt", Resource.FromString("Blubb"));

var handler = Listing.From(virt);

using var host = TestHost.Run(handler);

using var response = await host.GetResponseAsync();

await response.AssertStatusAsync(HttpStatusCode.OK);
}

private static RoutingTarget GetTarget(string path) => new(new PathBuilder(path).Build());

}

}

0 comments on commit 8c05e90

Please sign in to comment.