🚧 Ajout en test de la convertion d'image avec interface et base64
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

pull/92/head
Rémi LAVERGNE 11 months ago
parent 1ce607ac81
commit 7ecdedf561
No known key found for this signature in database
GPG Key ID: 7BCBAE9031E39160

@ -0,0 +1,29 @@
using System;
using Models.Interfaces;
namespace Models.Game
{
/// <summary>
/// Converter to Base64
/// </summary>
public class Base64Converter : IImageConverter
{
/// <summary>
/// Converts an image to a base64 string
/// </summary>
/// <param name="imagePath">The path to access the image</param>
/// <returns>The base64 string representation of the image</returns>
/// <exception cref="FileNotFoundException">Native .NET exception</exception>
public string ConvertImage(string imagePath)
{
if (!File.Exists(imagePath))
{
// native .NET exception
throw new FileNotFoundException("Image file not found", imagePath);
}
byte[] imageBytes = File.ReadAllBytes(imagePath);
return Convert.ToBase64String(imageBytes);
}
}
}

@ -0,0 +1,15 @@
namespace Models.Interfaces
{
/// <summary>
/// Interface for image converters
/// </summary>
public interface IImageConverter
{
/// <summary>
/// Converter to any type that can be converted to a string (ex: Base64)
/// </summary>
/// <param name="imagePath"></param>
/// <returns></returns>
string ConvertImage(string imagePath);
}
}

@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="Game\" />
<Folder Include="Rules\" />
</ItemGroup>

Loading…
Cancel
Save