mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-06-25 16:31:27 +00:00
* Start of reorganization and cleanup * Remove duplicate title id * Refactor types * Fix Release building * Move classes in /Types to a Types namespace * Fix compilation error (RoomVisualizerPage strikes again) * Fix bugs created from auto merge * Fix auto-merge compilation error * Changes from review/fix failed merge
65 lines
No EOL
2.6 KiB
C#
65 lines
No EOL
2.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using LBPUnion.ProjectLighthouse.Files;
|
|
using LBPUnion.ProjectLighthouse.Types.Resources;
|
|
using Xunit;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Tests;
|
|
|
|
public class ResourceTests
|
|
{
|
|
[Fact]
|
|
public void ShouldNotDeleteResourceFolder()
|
|
{
|
|
FileHelper.EnsureDirectoryCreated(FileHelper.ResourcePath);
|
|
Assert.True(Directory.Exists(FileHelper.ResourcePath));
|
|
FileHelper.DeleteResource(FileHelper.ResourcePath);
|
|
Assert.True(Directory.Exists(FileHelper.ResourcePath));
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldNotDeleteImagesFolder()
|
|
{
|
|
FileHelper.EnsureDirectoryCreated(FileHelper.ImagePath);
|
|
Assert.True(Directory.Exists(FileHelper.ImagePath));
|
|
FileHelper.DeleteResource(FileHelper.ImagePath);
|
|
Assert.True(Directory.Exists(FileHelper.ImagePath));
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldNotRecursivelyTraverseImage()
|
|
{
|
|
string path = Path.Combine(FileHelper.ImagePath, $"..{Path.DirectorySeparatorChar}appsettings.json");
|
|
FileHelper.DeleteResource(path);
|
|
Assert.True(File.Exists(Path.Combine(FileHelper.ImagePath, $"..{Path.DirectorySeparatorChar}appsettings.json")));
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldNotRecursivelyTraverseResource()
|
|
{
|
|
string path = Path.Combine(FileHelper.ResourcePath, $"..{Path.DirectorySeparatorChar}appsettings.json");
|
|
FileHelper.DeleteResource(path);
|
|
Assert.True(File.Exists(Path.Combine(FileHelper.ResourcePath, $"..{Path.DirectorySeparatorChar}appsettings.json")));
|
|
}
|
|
|
|
[Fact]
|
|
public async void ShouldDeleteResourceAndImage()
|
|
{
|
|
FileHelper.EnsureDirectoryCreated(FileHelper.ResourcePath);
|
|
FileHelper.EnsureDirectoryCreated(FileHelper.ImagePath);
|
|
string? hash = await FileHelper.ParseBase64Image("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8r8NQDwAFCQGsNA7jBAAAAABJRU5ErkJggg==");
|
|
LbpFile? file = LbpFile.FromHash("ed4e2857a2e315e4487ea976d1b398f57b863ff4");
|
|
Assert.True(file != null);
|
|
// Convert resource to png
|
|
FileHelper.LbpFileToPNG(file);
|
|
|
|
Assert.True(hash != null);
|
|
Assert.True(hash.Equals("ed4e2857a2e315e4487ea976d1b398f57b863ff4", StringComparison.InvariantCultureIgnoreCase));
|
|
Assert.True(File.Exists(Path.Combine(FileHelper.ResourcePath, hash)));
|
|
Assert.True(File.Exists(Path.Combine(FileHelper.ImagePath, $"{hash}.png")));
|
|
|
|
FileHelper.DeleteResource(hash);
|
|
Assert.False(File.Exists(Path.Combine(FileHelper.ResourcePath, hash)));
|
|
Assert.False(File.Exists(Path.Combine(FileHelper.ImagePath, $"{hash}.png")));
|
|
}
|
|
} |