From 2bf048944af20dc2ba9099bf87513ceb3e7d319c Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 24 Jul 2019 15:24:11 -0600 Subject: [PATCH] Added ability to filter on RunForEach and added name of structure to WriteValues --- UnitTests/CSharpRunner/TestHelper.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/UnitTests/CSharpRunner/TestHelper.cs b/UnitTests/CSharpRunner/TestHelper.cs index 0bb213a2..0c270618 100644 --- a/UnitTests/CSharpRunner/TestHelper.cs +++ b/UnitTests/CSharpRunner/TestHelper.cs @@ -8,13 +8,16 @@ namespace Vanara.PInvoke.Tests { public static class TestHelper { - public static void RunForEach(Type lib, string name, Func makeParam, Action action = null, Action error = null) where TEnum : Enum + public static void RunForEach(Type lib, string name, Func makeParam, Action action = null, Action error = null) where TEnum : Enum => + RunForEach(lib, name, makeParam, (e, ex) => error?.Invoke(ex), action); + + public static void RunForEach(Type lib, string name, Func makeParam, Action error = null, Action action = null, CorrespondingAction? filter = null) where TEnum : Enum { var mi = lib.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Where(m => m.IsGenericMethod && m.Name == name).First(); if (mi is null) throw new ArgumentException("Unable to find method."); foreach (var e in Enum.GetValues(typeof(TEnum)).Cast()) { - var type = CorrespondingTypeAttribute.GetCorrespondingTypes(e).FirstOrDefault(); + var type = (filter.HasValue ? CorrespondingTypeAttribute.GetCorrespondingTypes(e, filter.Value) : CorrespondingTypeAttribute.GetCorrespondingTypes(e)).FirstOrDefault(); if (type is null) { TestContext.WriteLine($"No corresponding type found for {e}."); @@ -29,7 +32,7 @@ namespace Vanara.PInvoke.Tests } catch (Exception ex) { - error?.Invoke(ex); + error?.Invoke(e, ex.InnerException); } } } @@ -37,6 +40,7 @@ namespace Vanara.PInvoke.Tests public static void WriteValues(this object value) { var json = JsonConvert.SerializeObject(value, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter(), new SizeTConverter()); + TestContext.WriteLine(value.GetType().Name); TestContext.WriteLine(json); }