From 20e18cbe6d4e24bb2399fdabbfc2836be4448bb0 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Mon, 10 Jun 2024 13:30:16 -0400 Subject: [PATCH 1/2] add smoke tests --- dotnet/test/Icons.g.test.cs | 44 +++++++++++++++++++++++++++++++++++++ dotnet/test/Spots.g.test.cs | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 dotnet/test/Icons.g.test.cs create mode 100644 dotnet/test/Spots.g.test.cs diff --git a/dotnet/test/Icons.g.test.cs b/dotnet/test/Icons.g.test.cs new file mode 100644 index 00000000..c559eb0a --- /dev/null +++ b/dotnet/test/Icons.g.test.cs @@ -0,0 +1,44 @@ +using System.Reflection; + +namespace StackExchange.StacksIcons.Test +{ + public class IconsTest + { + [Fact] + public void AllIconsExist() + { + // check every icon to make sure it exists + foreach (var icon in Svg.Lookup) + { + Assert.False(string.IsNullOrEmpty(icon.Value.ToString()), $"Svg `{icon.Key}` does not exist."); + } + } + + [Fact] + public void AllIconsAddedToLookup() + { + // get all the properties from the class via reflection + var props = typeof(Svg).GetProperties(BindingFlags.Static | BindingFlags.Public) + .Select(f => f.Name) + .ToArray(); + + // get all the enum values + var enumCount = Enum.GetNames(typeof(StacksIcon)).Length; + + // fail early if the lengths are not the same + Assert.Equal(enumCount, props.Length); + Assert.Equal(enumCount, Svg.Lookup.Keys.Count()); + + for (var i = 0; i < props.Length; i++) + { + var success = Enum.TryParse(props[i], out var actualEnum); + + // make sure all the properties have a corresponding enum value + Assert.True(success, $"Unable to parse prop `{props[i]}` as {nameof(StacksIcon)} enum."); + + // make sure all the values are represented as Lookup keys + Assert.True(Svg.Lookup.ContainsKey(actualEnum), $"Unable to find prop {props[i]} in Lookup."); + } + } + } +} diff --git a/dotnet/test/Spots.g.test.cs b/dotnet/test/Spots.g.test.cs new file mode 100644 index 00000000..7a9276f7 --- /dev/null +++ b/dotnet/test/Spots.g.test.cs @@ -0,0 +1,44 @@ +using System.Reflection; + +namespace StackExchange.StacksIcons.Test +{ + public class SpotsTest + { + [Fact] + public void AllSpotsExist() + { + // check every icon to make sure it exists + foreach (var icon in Svg.Lookup) + { + Assert.False(string.IsNullOrEmpty(icon.Value.ToString()), $"Svg `{icon.Key}` does not exist."); + } + } + + [Fact] + public void AllSpotsAddedToLookup() + { + // get all the properties from the class via reflection + var props = typeof(Svg.Spot).GetProperties(BindingFlags.Static | BindingFlags.Public) + .Select(f => f.Name) + .ToArray(); + + // get all the enum values + var enumCount = Enum.GetNames(typeof(StacksSpot)).Length; + + // fail early if the lengths are not the same + Assert.Equal(enumCount, props.Length); + Assert.Equal(enumCount, Svg.Spot.Lookup.Keys.Count()); + + for (var i = 0; i < props.Length; i++) + { + var success = Enum.TryParse(props[i], out var actualEnum); + + // make sure all the properties have a corresponding enum value + Assert.True(success, $"Unable to parse prop `{props[i]}` as {nameof(StacksSpot)} enum."); + + // make sure all the values are represented as Lookup keys + Assert.True(Svg.Spot.Lookup.ContainsKey(actualEnum), $"Unable to find prop {props[i]} in Lookup."); + } + } + } +} From 3a91e932925e739a2f868710523fdba8751412a3 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Mon, 10 Jun 2024 13:30:27 -0400 Subject: [PATCH 2/2] drop unused prop --- dotnet/src/Svg.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/src/Svg.cs b/dotnet/src/Svg.cs index 9abdcd0f..936ac4cc 100644 --- a/dotnet/src/Svg.cs +++ b/dotnet/src/Svg.cs @@ -8,7 +8,6 @@ namespace StackExchange.StacksIcons; public static partial class Svg { - private const int MaxReasonableSize = 4500; public static readonly SvgImage Empty = new(string.Empty); public static partial class Spot