Add enumerable extensions tests

This commit is contained in:
Matt Nadareski
2024-12-01 23:37:27 -05:00
parent bfb4499005
commit ca51733aa2
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using Xunit;
namespace BinaryObjectScanner.Tests
{
public class EnumerableExtensionsTests
{
[Fact]
public void IterateWithAction_EmptyEnumerable_Success()
{
List<string> set = new List<string>();
Action<string> action = (s) => s.ToLowerInvariant();
set.IterateWithAction(action);
Assert.Empty(set);
}
[Fact]
public void IterateWithAction_EmptyAction_Success()
{
List<string> set = ["a", "b", "c"];
Action<string> action = (s) => { };
set.IterateWithAction(action);
Assert.Equal(3, set.Count);
}
[Fact]
public void IterateWithAction_Valid_Success()
{
List<string> set = ["a", "b", "c"];
List<string> actual = new List<string>();
Action<string> action = (s) =>
{
lock (actual)
{
actual.Add(s.ToUpperInvariant());
}
};
set.IterateWithAction(action);
Assert.Equal(3, set.Count);
Assert.Equal(3, actual.Count);
}
}
}