diff --git a/src/GalaxyCheck.Tests/GenTests/ReflectedGenTests/AboutGeneratingDeepObjects.cs b/src/GalaxyCheck.Tests/GenTests/ReflectedGenTests/AboutGeneratingDeepObjects.cs index 4ec6ba32..d4a5c212 100644 --- a/src/GalaxyCheck.Tests/GenTests/ReflectedGenTests/AboutGeneratingDeepObjects.cs +++ b/src/GalaxyCheck.Tests/GenTests/ReflectedGenTests/AboutGeneratingDeepObjects.cs @@ -3,6 +3,7 @@ using NebulaCheck; using System; using System.Linq; +using Xunit; using Property = NebulaCheck.Property; using Test = NebulaCheck.Test; @@ -58,5 +59,20 @@ select Property.ForThese(() => .Throw() .WithMessage("Error while running generator ReflectedGen: detected circular reference on type '*ClassWithRecursiveProperty' at path '$.Property'"); }); + + [Fact] + public void ItCanHandleDeepErrors() + { + // Arrange + var gen = GalaxyCheck.Gen.Create() + .OverrideMember(x => x.Property.Property, GalaxyCheck.Gen.Advanced.Error("Error", "Error")); + + Action action = () => gen.SampleOne(seed: 0, size: 0); + + action.Should() + .Throw() + .WithMessage("Error while running generator Error at path '$.Property': Error"); + } + } } diff --git a/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/CollectionReflectedGenHandler.cs b/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/CollectionReflectedGenHandler.cs index b1810dbb..15314155 100644 --- a/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/CollectionReflectedGenHandler.cs +++ b/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/CollectionReflectedGenHandler.cs @@ -49,6 +49,7 @@ public IGen CreateGen(IReflectedGenHandler innerHandler, Type type, ReflectedGen { typeof(HashSet<>), nameof(CreateHashSetGen) }, { typeof(ISet<>), nameof(CreateHashSetGen) }, { typeof(ImmutableHashSet<>), nameof(CreateImmutableHashSetGen) }, + { typeof(ICollection<>), nameof(CreateListGen) } }; private static IGen> CreateIReadOnlyListGen(IGen elementGen) => elementGen.ListOf(); diff --git a/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/ErrorDiagnosticReflectedGenHandler.cs b/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/ErrorDiagnosticReflectedGenHandler.cs new file mode 100644 index 00000000..088aa70a --- /dev/null +++ b/src/GalaxyCheck/Gens/ReflectedGenHelpers/ReflectedGenHandlers/ErrorDiagnosticReflectedGenHandler.cs @@ -0,0 +1,14 @@ +using System; + +namespace GalaxyCheck.Gens.ReflectedGenHelpers.ReflectedGenHandlers +{ + internal class ErrorDiagnosticReflectedGenHandler : IReflectedGenHandler + { + public bool CanHandleGen(Type type, ReflectedGenHandlerContext context) => true; + + public IGen CreateGen(IReflectedGenHandler innerHandler, Type type, ReflectedGenHandlerContext context) + { + return innerHandler.CreateGen(type, context); + } + } +}