diff --git a/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResouceTests.cs b/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResouceTests.cs new file mode 100644 index 00000000..b166935b --- /dev/null +++ b/BrickController2/BrickController2.Tests/UI/Images/DeviceImagesResouceTests.cs @@ -0,0 +1,46 @@ +using BrickController2.DeviceManagement; +using BrickController2.Helpers; +using FluentAssertions; +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace BrickController2.Tests.UI.Images; + +public class DeviceImagesResouceTests +{ + public static IEnumerable DeviceTypesData => + Enum.GetValues(typeof(DeviceType)) + .Cast() + .Where(deviceType => deviceType != DeviceType.Unknown) // Exclude Unknown + .Select(deviceType => new object[] { deviceType }); + + [Theory] + [MemberData(nameof(DeviceTypesData))] + public void GetImageResource_DeviceType_SmallImageExists(DeviceType deviceType) + { + var smallImageName = $"{deviceType.ToString().ToLower()}" + "_image_small.png"; + + AssertImageResourceExists(smallImageName); + } + + [Theory] + [MemberData(nameof(DeviceTypesData))] + public void GetImageResource_DeviceType_ImageExists(DeviceType deviceType) + { + var smallImageName = $"{deviceType.ToString().ToLower()}" + "_image.png"; + + AssertImageResourceExists(smallImageName); + } + + private static void AssertImageResourceExists(string immageName) + { + var fullResourceName = ResourceHelper.GetImageResourcePath(immageName); + + var resourceNames = typeof(ResourceHelper).Assembly.GetManifestResourceNames(); + var exists = resourceNames.Contains(fullResourceName); + + exists.Should().BeTrue(); + } +} diff --git a/BrickController2/BrickController2/BrickController2.csproj b/BrickController2/BrickController2/BrickController2.csproj index 7146e441..04eb6688 100644 --- a/BrickController2/BrickController2/BrickController2.csproj +++ b/BrickController2/BrickController2/BrickController2.csproj @@ -12,6 +12,7 @@ + @@ -27,23 +28,23 @@ - - + + - - + + - - - - + + + + diff --git a/BrickController2/BrickController2/Helpers/ResourceHelper.cs b/BrickController2/BrickController2/Helpers/ResourceHelper.cs index 4af23f84..a50921fe 100644 --- a/BrickController2/BrickController2/Helpers/ResourceHelper.cs +++ b/BrickController2/BrickController2/Helpers/ResourceHelper.cs @@ -27,7 +27,10 @@ public static ResourceManager TranslationResourceManager public static ImageSource GetImageResource(string resourceName) { // define sourceAssembly parameter to avoid looking for assembly by Xamarin (via reflection of Assembly.GetCallingAssembly) - return ImageSource.FromResource($"{ImageResourceRootNameSpace}.{resourceName}", typeof(ResourceHelper).Assembly); + var resourcePath = GetImageResourcePath(resourceName); + return ImageSource.FromResource(resourcePath, typeof(ResourceHelper).Assembly); } + + public static string GetImageResourcePath(string resourceName) => $"{ImageResourceRootNameSpace}.{resourceName}"; } } diff --git a/BrickController2/BrickController2/UI/Images/infra_image.png b/BrickController2/BrickController2/UI/Images/infrared_image.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/infra_image.png rename to BrickController2/BrickController2/UI/Images/infrared_image.png diff --git a/BrickController2/BrickController2/UI/Images/infra_image_small.png b/BrickController2/BrickController2/UI/Images/infrared_image_small.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/infra_image_small.png rename to BrickController2/BrickController2/UI/Images/infrared_image_small.png diff --git a/BrickController2/BrickController2/UI/Images/pfx_brick_image.png b/BrickController2/BrickController2/UI/Images/pfxbrick_image.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/pfx_brick_image.png rename to BrickController2/BrickController2/UI/Images/pfxbrick_image.png diff --git a/BrickController2/BrickController2/UI/Images/pfx_brick_image_small.png b/BrickController2/BrickController2/UI/Images/pfxbrick_image_small.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/pfx_brick_image_small.png rename to BrickController2/BrickController2/UI/Images/pfxbrick_image_small.png diff --git a/BrickController2/BrickController2/UI/Images/technic_move.png b/BrickController2/BrickController2/UI/Images/technicmove_image.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/technic_move.png rename to BrickController2/BrickController2/UI/Images/technicmove_image.png diff --git a/BrickController2/BrickController2/UI/Images/technic_move_small.png b/BrickController2/BrickController2/UI/Images/technicmove_image_small.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/technic_move_small.png rename to BrickController2/BrickController2/UI/Images/technicmove_image_small.png diff --git a/BrickController2/BrickController2/UI/Images/wedo2hub_image.png b/BrickController2/BrickController2/UI/Images/wedo2_image.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/wedo2hub_image.png rename to BrickController2/BrickController2/UI/Images/wedo2_image.png diff --git a/BrickController2/BrickController2/UI/Images/wedo2hub_image_small.png b/BrickController2/BrickController2/UI/Images/wedo2_image_small.png similarity index 100% rename from BrickController2/BrickController2/UI/Images/wedo2hub_image_small.png rename to BrickController2/BrickController2/UI/Images/wedo2_image_small.png