Skip to content
Merged
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
104 changes: 104 additions & 0 deletions LinQL.Tests/Translation/TranslationProviderTests.Inheritance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#pragma warning disable CA1852 // Seal internal types
#nullable enable
namespace LinQL.Tests.Translation;

using LinQL.Description;

public partial class TranslationProviderTests
{
[Fact]
public void SimpleSelectInterface() => this.Test<InterfaceRootType, object>(x => x.SimpleType!.Number);

[Fact]
public void SelectInterfaceCastConcreteType()
=> this.Test<InterfaceRootType, object>(x => ((SomeOtherSimpleType)x.SimpleType!)!.Float);

[Fact]
public void SelectAllFieldsInterfaceCastConcreteType()
=> this.Test<InterfaceRootType, object>(x => (SomeOtherSimpleType)x.SimpleType!);

[Fact]
public void SelectInterfaceAsConcreteType()
=> this.Test<InterfaceRootType, object>(x => (x.SimpleType as SomeOtherSimpleType)!.Float);

[Fact]
public void SelectAllFieldsInterfaceAsConcreteType()
=> this.Test<InterfaceRootType, object>(x => (x.SimpleType as SomeOtherSimpleType)!);

[Fact]
public void SelectAllFieldsInterfaceOnConcreteType()
=> this.Test<InterfaceRootType, object?>(x =>
x.SimpleType.On((SomeOtherSimpleType y) => y.Number.ToString())
.On((SimpleScalarType y) => y.Text!));

[Fact]
public void SelectInterfaceArray()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces.OfType<SomeOtherSimpleType>().Select(y => new { y.Number, y.Text, y.Float }));

[Fact]
public void SelectInterfaceArrayAllFieldsOnType()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces.OfType<SomeOtherSimpleType>());

[Fact]
public void SelectInterfaceArrayCastConcreteType()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces.Select(y => new { ((SomeOtherSimpleType)y).Float, y.Text }));

[Fact]
public void SelectInterfaceArrayAsConcreteType()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces.Select(y => new { (y as SomeOtherSimpleType)!.Float, y.Text }));

[Fact]
public void SelectInterfaceArrayAsConcreteTypeWithOperation()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces.Select(y => new { Number = (y as SomeOtherSimpleType)!.Operation.GetNumber("123"), y.Text }));

[Fact]
public void SelectInterfaceArrayOnConcreteType()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces
.Select(y => y.On((SimpleScalarType z) => z.Text)
.On((SomeOtherSimpleType z) => z.Float.ToString()!)));

[Fact]
public void SelectInterfaceArrayMultipleTypes()
=> this.Test<InterfaceRootType, object>(x => new
{
Types = x.ArrayOfInterfaces.OfType<SimpleScalarType>().Select(y => new { y.Number, y.Text }),
OtherTypes = x.ArrayOfInterfaces.OfType<SomeOtherSimpleType>().Select(y => new { y.Number, y.Text, y.Float }),
});

[Fact]
public void SelectInterfaceArrayMultipleTypesSelectAll()
=> this.Test<InterfaceRootType, object>(x => new
{
Types = x.ArrayOfInterfaces.OfType<SimpleScalarType>().Select(y => y.SelectAll()),
OtherTypes = x.ArrayOfInterfaces.OfType<SomeOtherSimpleType>().Select(y => y.SelectAll()),
});

[Fact]
public void MultipleProjectionsWithOn()
=> this.Test<MultipleTypeInheritence, object>(
x => x.IAmObject
.On((Implementaion1 y) => y.Text)
.On((Implementaion2 y) => y.Value)
.On((Implementaion3 y) => y.Date)
.On((Implementaion4 y) => y.Amount)
.On((Implementaion5 y) => new { y.Id, Texts = y.Collection.Select(z => z.Text) })
);

[OperationType]
private class MultipleTypeInheritence : RootType<MultipleTypeInheritence>
{
public IAmInterface IAmObject { get; set; } = default!;
}

private interface IAmInterface;

private record Implementaion1(string Text) : IAmInterface;

private record Implementaion2(int Value) : IAmInterface;

private record Implementaion3(DateOnly Date) : IAmInterface;

private record Implementaion4(float Amount) : IAmInterface;

private record Implementaion5(Guid Id, List<SimpleScalarType> Collection) : IAmInterface;
}
74 changes: 74 additions & 0 deletions LinQL.Tests/Translation/TranslationProviderTests.Operations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#pragma warning disable CA1852 // Seal internal types
#nullable enable
namespace LinQL.Tests.Translation;

public partial class TranslationProviderTests
{
[Fact]
public void SimpleOperation()
=> this.Test<SimpleOperationType, object>(x => new { x.Float, x.GetNumber().Number });

[Fact]
public void OperationWithConstantParameters()
=> this.Test<OperationWithScalarParametersType, object>(x => new { x.Float, x.GetNumber("123").Number });

[Fact]
public void OperationWithObjectParameters()
=> this.Test<OperationWithTypeParametersType, object>(x => new { x.Float, x.GetNumber(new SimpleScalarType()).Number });

[Fact]
public void OperationWithVariableMemberParameters()
{
var input = new SimpleScalarType { Number = 123, Text = "321" };

this.Test<OperationWithScalarParametersType, object>(x => new { x.GetNumber(input.Text).Number });
}

[Fact]
public void OperationWithVariableParameters()
{
var input = new SimpleScalarType { Number = 123, Text = "321" };

this.Test<OperationWithTypeParametersType, object>(x => new { x.GetNumber(input).Number });
}

[Fact]
public void OperationWithNullableVariableParameters()
{
var input = new SimpleScalarType { Number = 123, Text = "321" };

this.Test<OperationWithNullableTypeParametersType, object>(x => new { x.GetNumber(input)!.Number });
}

[Fact]
public void NestedOperationWithVariableParameters()
{
var input = new SimpleScalarType { Number = 123, Text = "321" };

this.Test<NestedOperationType, object>(x => new
{
x.Operation.GetNumber(input.Text).Number,
x.Text,
});
}

[Fact]
public void NestedOperationInOperation()
{
var input = new SimpleScalarType { Number = 123, Text = "321" };

this.Test<NestedOperationInOperationType, object>(x => new
{
x.Operation(input.Number).Operation.GetNumber(input.Text).Number,
x.Text,
});
}

[Fact]
public void ScalarArrayOperation()
=> this.Test<ScalarArray, int[]>(x => x.GetNumbers());

[Fact]
public void ScalarArrayOperationWithArguments()
=> this.Test<ScalarArray, int[]>(x => x.GetFilteredNumbers(1));
}
55 changes: 55 additions & 0 deletions LinQL.Tests/Translation/TranslationProviderTests.Projection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#pragma warning disable CA1852 // Seal internal types
#nullable enable
namespace LinQL.Tests.Translation;

public partial class TranslationProviderTests
{
[Fact]
public void SelectAllNestedFields() => this.Test<NestedClassType, object>(x => x.Nested!);

[Fact]
public void SelectAllWithHelperNestedFields() => this.Test<NestedClassType, object>(x => x.Nested!.SelectAll());

[Fact]
public void SelectAllNestedFieldsFromOperation() => this.Test<NestedOperationType, object>(x => x.Operation.GetNumber("123")!);

[Fact]
public void SelectAllNestedFieldsWithHelperFromOperation() => this.Test<NestedOperationType, object>(x => x.Operation.GetNumber("123")!.SelectAll());

[Fact]
public void SelectFromArray() => this.Test<NestedArrayType, object>(x => x.Types.Select(x => new
{
x.Text,
x.Number,
}));

[Fact]
public void RenameField() => this.Test<RenamedType, object>(x => x.Text);

[Fact]
public void RenameOperation() => this.Test<RenamedType, object>(x => x.GetObject());

[Fact]
public void ProjectArrayOfInterface()
=> this.Test<InterfaceRootType, object>(x => x.ArrayOfInterfaces.Select(a => new Projection(a.Number, a.Text)));

[Fact]
public void ProjectIEnumerableOfInterface()
=> this.Test<InterfaceRootType, object>(x => x.EnumerableOfInterfaces.Select(a => new Projection(a.Number, a.Text)));

[Fact]
public void ProjectListOfInterface()
=> this.Test<InterfaceRootType, object>(x => x.ListOfInterfaces.Select(a => new Projection(a.Number, a.Text)));

[Fact]
public void Project()
=> this.Test<NestedOperationType, Projection>(x => x.Operation.GetNumber("project me").Project(y => new Projection(y.Number, y.Text)));

[Fact]
public void ProjectAcrossMultipleLevels()
=> this.Test<NestedOperationType, Projection>(x => new Projection(x.Number, x.Operation.GetNumber("project me").Project(y => y.Text)));

[Fact]
public void ProjectSameOperationMultipleTimes()
=> this.Test<NestedOperationType, NestedProjection>(x => new NestedProjection(x.Operation.Float, x.Operation.GetNumber("project me").Project(y => new Projection(y.Number, y.Text))));
}
30 changes: 30 additions & 0 deletions LinQL.Tests/Translation/TranslationProviderTests.Simple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma warning disable CA1852 // Seal internal types
#nullable enable
namespace LinQL.Tests.Translation;

public partial class TranslationProviderTests
{
[Fact]
public void ScalarOnRoot()
=> this.Test<ScalarOnRootType, object>(x => x.GetNumber());

[Fact]
public void Simple()
=> this.Test<SimpleScalarType, object>(x => new { x.Number, x.Text });

[Fact]
public void NestedMemberFlatten()
=> this.Test<NestedClassType, object>(x => new { x.Float, x.Nested!.Number, x.Nested.Text });

[Fact]
public void NestedMember()
=> this.Test<NestedClassType, object>(x => new { x.Float, Nested = new { x.Nested!.Number } });

[Fact]
public void BasicInclude()
=> this.TestInclude<NestedOperationType, object>(x => x.Operation, x => x.Include(y => y.Operation.GetNumber("123")));

[Fact]
public void ScalarArrayFields()
=> this.Test<ScalarArray, string[]>(x => x.Strings);
}
Loading
Loading