Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dotnet smoke tests #313

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dotnet/src/Svg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.");
}
}
}
}
Loading