mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-27 12:46:15 +00:00
Add some resource tests and other small changes (#638)
* Cleanup custom icon resources and add resource tests * Don't delete old custom icons
This commit is contained in:
parent
87ceca9c63
commit
ace3678da7
4 changed files with 105 additions and 49 deletions
64
ProjectLighthouse.Tests/Tests/ResourceTests.cs
Normal file
64
ProjectLighthouse.Tests/Tests/ResourceTests.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
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")));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue