Skip to content

Commit

Permalink
Support common base class for model base classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcweber committed Oct 4, 2023
1 parent e57c1ce commit fca5ecd
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Core/Models/GraphElementModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public IGraphElementModel ConfigureMetadata(MemberInfo member, Func<MemberMetada
public IImmutableSet<MemberInfo> Members { get; }


private bool IsWithinModel(MemberInfo memberInfo) => memberInfo.DeclaringType is { } declaringType && IsWithinModel(declaringType);
private bool IsWithinModel(MemberInfo memberInfo) => memberInfo.DeclaringType is { } declaringType && (IsWithinModel(declaringType) || declaringType.IsAssignableFrom(typeof(TBaseType)));

private bool IsWithinModel(Type type) => typeof(TBaseType).IsAssignableFrom(type) && _assemblies.Contains(type.Assembly);

Expand Down
7 changes: 7 additions & 0 deletions test/Core.Tests/Elements/ConcreteVertexElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ExRam.Gremlinq.Core.Tests
{
public sealed class ConcreteVertexElement : VertexElement
{

}
}
7 changes: 7 additions & 0 deletions test/Core.Tests/Elements/EdgeElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ExRam.Gremlinq.Core.Tests
{
public abstract class EdgeElement : Element
{

}
}
7 changes: 7 additions & 0 deletions test/Core.Tests/Elements/Element.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ExRam.Gremlinq.Core.Tests
{
public abstract class Element
{
public string? Id { get; set; }
}
}
7 changes: 7 additions & 0 deletions test/Core.Tests/Elements/VertexElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ExRam.Gremlinq.Core.Tests
{
public abstract class VertexElement : Element
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
Key: {
RawKey: {
EnumName: T,
EnumValue: id
}
},
SerializationBehaviour: IgnoreAlways
}
14 changes: 12 additions & 2 deletions test/Core.Tests/GraphModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace ExRam.Gremlinq.Core.Tests
{
public class GraphModelTest : VerifyBase
{


public GraphModelTest() : base()
{

Expand Down Expand Up @@ -368,5 +366,17 @@ public async Task AddAssemblies()
.Should()
.NotBeNull();
}

[Fact]
public async Task Configuration_IgnoreAlways_Id_when_inheriting_from_Element()
{
await Verify(GraphModel
.FromBaseTypes<VertexElement, EdgeElement>()
.ConfigureVertices(pm => pm
.ConfigureElement<VertexElement>(conf => conf
.IgnoreAlways(p => p.Id)))
.VerticesModel
.GetMetadata(typeof(VertexElement).GetProperty(nameof(VertexElement.Id))!));
}
}
}

0 comments on commit fca5ecd

Please sign in to comment.