Skip to content

Commit

Permalink
add smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b-kelly committed Jun 10, 2024
1 parent c4e7649 commit 20e18cb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
44 changes: 44 additions & 0 deletions dotnet/test/Icons.g.test.cs
Original file line number Diff line number Diff line change
@@ -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<StacksIcon>(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.");
}
}
}
}
44 changes: 44 additions & 0 deletions dotnet/test/Spots.g.test.cs
Original file line number Diff line number Diff line change
@@ -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<StacksSpot>(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.");
}
}
}
}

0 comments on commit 20e18cb

Please sign in to comment.