From ca51733aa20d088a13c57f2db4102c117dd3fdde Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sun, 1 Dec 2024 23:37:27 -0500 Subject: [PATCH] Add enumerable extensions tests --- .../EnumerableExtensionsTests.cs | 48 +++++++++++++++++++ .../BinaryObjectScanner.csproj | 19 ++++++++ 2 files changed, 67 insertions(+) create mode 100644 BinaryObjectScanner.Test/EnumerableExtensionsTests.cs diff --git a/BinaryObjectScanner.Test/EnumerableExtensionsTests.cs b/BinaryObjectScanner.Test/EnumerableExtensionsTests.cs new file mode 100644 index 00000000..3caf5115 --- /dev/null +++ b/BinaryObjectScanner.Test/EnumerableExtensionsTests.cs @@ -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 set = new List(); + Action action = (s) => s.ToLowerInvariant(); + + set.IterateWithAction(action); + Assert.Empty(set); + } + + [Fact] + public void IterateWithAction_EmptyAction_Success() + { + List set = ["a", "b", "c"]; + Action action = (s) => { }; + + set.IterateWithAction(action); + Assert.Equal(3, set.Count); + } + + [Fact] + public void IterateWithAction_Valid_Success() + { + List set = ["a", "b", "c"]; + List actual = new List(); + + Action action = (s) => + { + lock (actual) + { + actual.Add(s.ToUpperInvariant()); + } + }; + + set.IterateWithAction(action); + Assert.Equal(3, set.Count); + Assert.Equal(3, actual.Count); + } + } +} \ No newline at end of file diff --git a/BinaryObjectScanner/BinaryObjectScanner.csproj b/BinaryObjectScanner/BinaryObjectScanner.csproj index 91312af5..bdc5ba95 100644 --- a/BinaryObjectScanner/BinaryObjectScanner.csproj +++ b/BinaryObjectScanner/BinaryObjectScanner.csproj @@ -67,6 +67,25 @@ + + + + + + + + + + + + + + + + + + +