Skip to content

🌍 #373 Support ICollection<> #375

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NebulaCheck;
using System;
using System.Linq;
using Xunit;
using Property = NebulaCheck.Property;
using Test = NebulaCheck.Test;

Expand Down Expand Up @@ -58,5 +59,20 @@ select Property.ForThese(() =>
.Throw<GalaxyCheck.Exceptions.GenErrorException>()
.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<ClassWithOneNestedProperty>()
.OverrideMember(x => x.Property.Property, GalaxyCheck.Gen.Advanced.Error<object>("Error", "Error"));

Action action = () => gen.SampleOne(seed: 0, size: 0);

action.Should()
.Throw<GalaxyCheck.Exceptions.GenErrorException>()
.WithMessage("Error while running generator Error at path '$.Property': Error");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyList<T>> CreateIReadOnlyListGen<T>(IGen<T> elementGen) => elementGen.ListOf();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}