From cb3fd8c4840a01becc16755b87921fb39fdf39d5 Mon Sep 17 00:00:00 2001 From: Sam Xu Date: Fri, 12 Jul 2024 16:12:31 -0700 Subject: [PATCH] Fixes #1144: Enable retrieve the clr element type from GroupbyWrapper Enable write the apply result using OData payload --- .../Controllers/v1/CustomersController.cs | 24 ++++++++++++- .../Common/TypeHelper.cs | 17 +++++++++ .../Edm/DefaultODataTypeMapper.cs | 5 +++ .../Serialization/ODataSerializerProvider.cs | 8 +++++ .../Query/Expressions/AggregationBinder.cs | 16 ++++----- .../Query/Expressions/QueryBinder.cs | 2 +- .../Query/Expressions/QueryBinderContext.cs | 2 +- .../Query/Wrapper/AggregationWrapper.cs | 10 +++--- .../Wrapper/DynamicTypeWrapperConverter.cs | 26 +++++++------- .../Wrapper/EntitySetAggregationWrapper.cs | 10 +++--- .../Query/Wrapper/FlatteningWrapperOfT.cs | 3 +- .../Query/Wrapper/GroupByWrapper.cs | 11 +++--- .../Wrapper/NoGroupByAggregationWrapper.cs | 10 +++--- .../Query/Wrapper/NoGroupByWrapper.cs | 10 +++--- .../Commons/TypeHelperTest.cs | 8 ++--- .../DynamicTypeWrapperConverterTests.cs | 36 +++++++++---------- .../SelectExpandWrapperConverterTests.cs | 4 +-- 17 files changed, 128 insertions(+), 74 deletions(-) diff --git a/sample/ODataRoutingSample/Controllers/v1/CustomersController.cs b/sample/ODataRoutingSample/Controllers/v1/CustomersController.cs index 55edc3e13..86c1ae8e6 100644 --- a/sample/ODataRoutingSample/Controllers/v1/CustomersController.cs +++ b/sample/ODataRoutingSample/Controllers/v1/CustomersController.cs @@ -39,7 +39,29 @@ public CustomersController(MyDataContext context) } } - // For example: http://localhost:5000/v1/customers?$apply=groupby((Name), aggregate($count as count))&$orderby=name desc + // For example: http://localhost:5000/v1/customers?$apply=groupby((Name), aggregate($count as count))&$orderby=Name desc + /* You could get: +{ + "@odata.context": "http://localhost:5000/v1/$metadata#Customers(Name,count)", + "value": [ + { + "@odata.id": null, + "Name": "Sam", + "count": 2 + }, + { + "@odata.id": null, + "Name": "Peter", + "count": 1 + }, + { + "@odata.id": null, + "Name": "Jonier", + "count": 1 + } + ] +} + */ [HttpGet] [EnableQuery] public IActionResult Get() diff --git a/src/Microsoft.AspNetCore.OData/Common/TypeHelper.cs b/src/Microsoft.AspNetCore.OData/Common/TypeHelper.cs index 360e80b8c..678315464 100644 --- a/src/Microsoft.AspNetCore.OData/Common/TypeHelper.cs +++ b/src/Microsoft.AspNetCore.OData/Common/TypeHelper.cs @@ -36,12 +36,29 @@ public static bool IsDynamicTypeWrapper(this Type type) return (type != null && typeof(DynamicTypeWrapper).IsAssignableFrom(type)); } + public static bool IsCollectionDynamicTypeWrapper(this Type type) + { + if (!IsCollection(type, out Type elementType)) + { + return false; + } + + //while (elementType != null && elementType != typeof(object)) + //{ + // elementType = elementType.BaseType; + //} + + return elementType.IsDynamicTypeWrapper(); + } + public static bool IsDeltaSetWrapper(this Type type, out Type entityType) => IsTypeWrapper(typeof(DeltaSet<>), type, out entityType); public static bool IsSelectExpandWrapper(this Type type, out Type entityType) => IsTypeWrapper(typeof(SelectExpandWrapper<>), type, out entityType); public static bool IsComputeWrapper(this Type type, out Type entityType) => IsTypeWrapper(typeof(ComputeWrapper<>), type, out entityType); + public static bool IsGroupByWrapper(this Type type, out Type entityType) => IsTypeWrapper(typeof(GroupByWrapper<>), type, out entityType); + private static bool IsTypeWrapper(Type wrappedType, Type type, out Type entityType) { if (type == null) diff --git a/src/Microsoft.AspNetCore.OData/Edm/DefaultODataTypeMapper.cs b/src/Microsoft.AspNetCore.OData/Edm/DefaultODataTypeMapper.cs index f6de16954..cb2748017 100644 --- a/src/Microsoft.AspNetCore.OData/Edm/DefaultODataTypeMapper.cs +++ b/src/Microsoft.AspNetCore.OData/Edm/DefaultODataTypeMapper.cs @@ -248,6 +248,11 @@ private IEdmType GetEdmType(IEdmModel edmModel, Type clrType, bool testCollectio elementClrType = entityType; } + if (elementClrType.IsGroupByWrapper(out entityType)) + { + elementClrType = entityType; + } + IEdmType elementType = GetEdmType(edmModel, elementClrType, testCollections: false); if (elementType != null) { diff --git a/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataSerializerProvider.cs b/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataSerializerProvider.cs index 74c62fed2..14dbc19bc 100644 --- a/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataSerializerProvider.cs +++ b/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataSerializerProvider.cs @@ -121,6 +121,14 @@ public virtual IODataSerializer GetODataPayloadSerializer(Type type, HttpRequest { return _serviceProvider.GetRequiredService(); } + else if (type.IsDynamicTypeWrapper()) + { + return _serviceProvider.GetRequiredService(); + } + else if (type.IsCollectionDynamicTypeWrapper()) + { + return _serviceProvider.GetRequiredService(); + } IEdmModel model = request.GetModel(); diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/AggregationBinder.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/AggregationBinder.cs index 982060916..7165b28d1 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/AggregationBinder.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/AggregationBinder.cs @@ -48,7 +48,7 @@ internal AggregationBinder(ODataQuerySettings settings, IAssemblyResolver assemb case TransformationNodeKind.Aggregate: var aggregateClause = this._transformation as AggregateTransformationNode; _aggregateExpressions = FixCustomMethodReturnTypes(aggregateClause.AggregateExpressions); - ResultClrType = typeof(NoGroupByAggregationWrapper); + ResultClrType = typeof(NoGroupByAggregationWrapper<>).MakeGenericType(elementType); break; case TransformationNodeKind.GroupBy: var groupByClause = this._transformation as GroupByTransformationNode; @@ -66,15 +66,15 @@ internal AggregationBinder(ODataQuerySettings settings, IAssemblyResolver assemb } } - _groupByClrType = typeof(GroupByWrapper); - ResultClrType = typeof(AggregationWrapper); + _groupByClrType = typeof(GroupByWrapper<>).MakeGenericType(elementType); + ResultClrType = typeof(AggregationWrapper<>).MakeGenericType(elementType); break; default: throw new NotSupportedException(String.Format(CultureInfo.InvariantCulture, SRResources.NotSupportedTransformationKind, transformation.Kind)); } - _groupByClrType = _groupByClrType ?? typeof(NoGroupByWrapper); + _groupByClrType = _groupByClrType ?? typeof(NoGroupByWrapper<>).MakeGenericType(elementType); } private static Expression WrapDynamicCastIfNeeded(Expression propertyAccessor) @@ -393,7 +393,7 @@ MethodInfo selectManyMethod properties.Add(new NamedPropertyExpression(Expression.Constant(aggExpression.Alias), CreateAggregationExpression(innerAccum, aggExpression, selectedElementType))); } - var nestedResultType = typeof(EntitySetAggregationWrapper); + var nestedResultType = typeof(EntitySetAggregationWrapper<>).MakeGenericType(this.ElementType); var wrapperProperty = nestedResultType.GetProperty("Container"); wrapperTypeMemberAssignments.Add(Expression.Bind(wrapperProperty, AggregationPropertyContainer.CreateNextNamedPropertyContainer(properties))); @@ -589,10 +589,10 @@ private IQueryable BindGroupBy(IQueryable query) // }) List properties = CreateGroupByMemberAssignments(_groupingProperties); - var wrapperProperty = typeof(GroupByWrapper).GetProperty(GroupByContainerProperty); + var wrapperProperty = typeof(GroupByWrapper<>).GetProperty(GroupByContainerProperty); List wta = new List(); wta.Add(Expression.Bind(wrapperProperty, AggregationPropertyContainer.CreateNextNamedPropertyContainer(properties))); - groupLambda = Expression.Lambda(Expression.MemberInit(Expression.New(typeof(GroupByWrapper)), wta), LambdaParameter); + groupLambda = Expression.Lambda(Expression.MemberInit(Expression.New(typeof(GroupByWrapper<>).MakeGenericType(ElementType)), wta), LambdaParameter); } else { @@ -616,7 +616,7 @@ private List CreateGroupByMemberAssignments(IEnumerable } else { - var wrapperProperty = typeof(GroupByWrapper).GetProperty(GroupByContainerProperty); + var wrapperProperty = typeof(GroupByWrapper<>).GetProperty(GroupByContainerProperty); List wta = new List(); wta.Add(Expression.Bind(wrapperProperty, AggregationPropertyContainer.CreateNextNamedPropertyContainer(CreateGroupByMemberAssignments(grpProp.ChildTransformations)))); properties.Add(new NamedPropertyExpression(Expression.Constant(propertyName), Expression.MemberInit(Expression.New(typeof(GroupByWrapper)), wta))); diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs index 613fa7970..4193f3e35 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs @@ -1096,7 +1096,7 @@ internal Expression CreatePropertyAccessExpression(Expression source, QueryBinde // return GetFlattenedPropertyExpression(propertyPath, context) // ?? ConvertNonStandardPrimitives(GetPropertyExpression(source, (!propertyPath.Contains("\\", StringComparison.Ordinal) ? "Instance\\" : String.Empty) + propertyName), context); - bool isAggregated = context.ElementClrType == typeof(AggregationWrapper); + bool isAggregated = context.ElementClrType == typeof(AggregationWrapper<>); return GetFlattenedPropertyExpression(propertyPath, context) ?? ConvertNonStandardPrimitives(GetPropertyExpression(source, propertyName, isAggregated), context); diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinderContext.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinderContext.cs index ef5e6f26d..8e8fab6d2 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinderContext.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinderContext.cs @@ -63,7 +63,7 @@ public QueryBinderContext(IEdmModel model, ODataQuerySettings querySettings, Typ ElementType = Model.GetEdmTypeReference(ElementClrType)?.Definition; // Check if element type is null and not of AggregationWrapper type and not of NoGroupByAggregationWrapper type. - if (ElementType == null && ElementClrType != typeof(AggregationWrapper) && ElementClrType != typeof(NoGroupByAggregationWrapper)) + if (ElementType == null && !typeof(GroupByWrapper).IsAssignableFrom(ElementClrType)) { throw new ODataException(Error.Format(SRResources.ClrTypeNotInModel, ElementClrType.FullName)); } diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/AggregationWrapper.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/AggregationWrapper.cs index 5548f582a..dfe943119 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/AggregationWrapper.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/AggregationWrapper.cs @@ -11,18 +11,18 @@ namespace Microsoft.AspNetCore.OData.Query.Wrapper { - internal class AggregationWrapper : GroupByWrapper + internal class AggregationWrapper : GroupByWrapper { } - internal class AggregationWrapperConverter : JsonConverter + internal class AggregationWrapperConverter : JsonConverter> { - public override AggregationWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override AggregationWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, nameof(AggregationWrapper))); + throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, typeof(AggregationWrapper).Name)); } - public override void Write(Utf8JsonWriter writer, AggregationWrapper value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, AggregationWrapper value, JsonSerializerOptions options) { if (value != null) { diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/DynamicTypeWrapperConverter.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/DynamicTypeWrapperConverter.cs index 82c376a45..da795d9dc 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/DynamicTypeWrapperConverter.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/DynamicTypeWrapperConverter.cs @@ -59,32 +59,32 @@ public override JsonConverter CreateConverter(Type type, JsonSerializerOptions o { return (JsonConverter)Activator.CreateInstance(typeof(FlatteningWrapperConverter<>).MakeGenericType(new Type[] { elementType })); } - } - else - { - if (type == typeof(AggregationWrapper)) + //} + //else + //{ + if (type == typeof(AggregationWrapper<>)) { - return (JsonConverter)Activator.CreateInstance(typeof(AggregationWrapperConverter)); + return (JsonConverter)Activator.CreateInstance(typeof(AggregationWrapperConverter<>).MakeGenericType(new Type[] { elementType })); } - if (type == typeof(EntitySetAggregationWrapper)) + if (type == typeof(EntitySetAggregationWrapper<>)) { - return (JsonConverter)Activator.CreateInstance(typeof(EntitySetAggregationWrapperConverter)); + return (JsonConverter)Activator.CreateInstance(typeof(EntitySetAggregationWrapperConverter<>).MakeGenericType(new Type[] { elementType })); } - if (type == typeof(GroupByWrapper)) + if (type == typeof(GroupByWrapper<>)) { - return (JsonConverter)Activator.CreateInstance(typeof(GroupByWrapperConverter)); + return (JsonConverter)Activator.CreateInstance(typeof(GroupByWrapperConverter<>).MakeGenericType(new Type[] { elementType })); } - if (type == typeof(NoGroupByAggregationWrapper)) + if (type == typeof(NoGroupByAggregationWrapper<>)) { - return (JsonConverter)Activator.CreateInstance(typeof(NoGroupByAggregationWrapperConverter)); + return (JsonConverter)Activator.CreateInstance(typeof(NoGroupByAggregationWrapperConverter<>).MakeGenericType(new Type[] { elementType })); } - if (type == typeof(NoGroupByWrapper)) + if (type == typeof(NoGroupByWrapper<>)) { - return (JsonConverter)Activator.CreateInstance(typeof(NoGroupByWrapperConverter)); + return (JsonConverter)Activator.CreateInstance(typeof(NoGroupByWrapperConverter<>).MakeGenericType(new Type[] { elementType })); } } diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/EntitySetAggregationWrapper.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/EntitySetAggregationWrapper.cs index a02c08c93..4959c09a9 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/EntitySetAggregationWrapper.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/EntitySetAggregationWrapper.cs @@ -11,18 +11,18 @@ namespace Microsoft.AspNetCore.OData.Query.Wrapper { - internal class EntitySetAggregationWrapper : GroupByWrapper + internal class EntitySetAggregationWrapper : GroupByWrapper { } - internal class EntitySetAggregationWrapperConverter : JsonConverter + internal class EntitySetAggregationWrapperConverter : JsonConverter> { - public override EntitySetAggregationWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override EntitySetAggregationWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, nameof(EntitySetAggregationWrapper))); + throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, typeof(EntitySetAggregationWrapper).Name)); } - public override void Write(Utf8JsonWriter writer, EntitySetAggregationWrapper value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, EntitySetAggregationWrapper value, JsonSerializerOptions options) { if (value != null) { diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/FlatteningWrapperOfT.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/FlatteningWrapperOfT.cs index 4cf37eb9e..b74f4ec0b 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/FlatteningWrapperOfT.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/FlatteningWrapperOfT.cs @@ -6,13 +6,12 @@ //------------------------------------------------------------------------------ using System; -using System.Diagnostics.Contracts; using System.Text.Json; using System.Text.Json.Serialization; namespace Microsoft.AspNetCore.OData.Query.Wrapper { - internal class FlatteningWrapper : GroupByWrapper + internal class FlatteningWrapper : GroupByWrapper { // TODO: how to use 'Source'? public T Source { get; set; } diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/GroupByWrapper.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/GroupByWrapper.cs index 5bc0ff162..b1296e36e 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/GroupByWrapper.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/GroupByWrapper.cs @@ -15,6 +15,9 @@ namespace Microsoft.AspNetCore.OData.Query.Wrapper { + internal class GroupByWrapper : GroupByWrapper + { } + internal class GroupByWrapper : DynamicTypeWrapper { private Dictionary _values; @@ -86,14 +89,14 @@ private void EnsureValues() } } - internal class GroupByWrapperConverter : JsonConverter + internal class GroupByWrapperConverter : JsonConverter> { - public override GroupByWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override GroupByWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, nameof(GroupByWrapper))); + throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, typeof(GroupByWrapper).Name)); } - public override void Write(Utf8JsonWriter writer, GroupByWrapper value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, GroupByWrapper value, JsonSerializerOptions options) { if (value != null) { diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByAggregationWrapper.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByAggregationWrapper.cs index 972b817e2..a42a9b6ee 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByAggregationWrapper.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByAggregationWrapper.cs @@ -11,18 +11,18 @@ namespace Microsoft.AspNetCore.OData.Query.Wrapper { - internal class NoGroupByAggregationWrapper : GroupByWrapper + internal class NoGroupByAggregationWrapper : GroupByWrapper { } - internal class NoGroupByAggregationWrapperConverter : JsonConverter + internal class NoGroupByAggregationWrapperConverter : JsonConverter> { - public override NoGroupByAggregationWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override NoGroupByAggregationWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, nameof(NoGroupByAggregationWrapper))); + throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, typeof(NoGroupByAggregationWrapper).Name)); } - public override void Write(Utf8JsonWriter writer, NoGroupByAggregationWrapper value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, NoGroupByAggregationWrapper value, JsonSerializerOptions options) { if (value != null) { diff --git a/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByWrapper.cs b/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByWrapper.cs index 9d90c7a7a..33e6b192a 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByWrapper.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Wrapper/NoGroupByWrapper.cs @@ -11,18 +11,18 @@ namespace Microsoft.AspNetCore.OData.Query.Wrapper { - internal class NoGroupByWrapper : GroupByWrapper + internal class NoGroupByWrapper : GroupByWrapper { } - internal class NoGroupByWrapperConverter : JsonConverter + internal class NoGroupByWrapperConverter : JsonConverter> { - public override NoGroupByWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override NoGroupByWrapper Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, nameof(NoGroupByWrapper))); + throw new NotImplementedException(Error.Format(SRResources.JsonConverterDoesnotSupportRead, typeof(NoGroupByWrapper).Name)); } - public override void Write(Utf8JsonWriter writer, NoGroupByWrapper value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, NoGroupByWrapper value, JsonSerializerOptions options) { if (value != null) { diff --git a/test/Microsoft.AspNetCore.OData.Tests/Commons/TypeHelperTest.cs b/test/Microsoft.AspNetCore.OData.Tests/Commons/TypeHelperTest.cs index 245fbb193..5ed887c7e 100644 --- a/test/Microsoft.AspNetCore.OData.Tests/Commons/TypeHelperTest.cs +++ b/test/Microsoft.AspNetCore.OData.Tests/Commons/TypeHelperTest.cs @@ -23,13 +23,13 @@ namespace Microsoft.AspNetCore.OData.Tests.Commons public class TypeHelperTest { [Theory] - [InlineData(typeof(AggregationWrapper), true)] + [InlineData(typeof(AggregationWrapper), true)] [InlineData(typeof(ComputeWrapper), true)] - [InlineData(typeof(EntitySetAggregationWrapper), true)] + [InlineData(typeof(EntitySetAggregationWrapper), true)] [InlineData(typeof(FlatteningWrapper), true)] [InlineData(typeof(GroupByWrapper), true)] - [InlineData(typeof(NoGroupByAggregationWrapper), true)] - [InlineData(typeof(NoGroupByWrapper), true)] + [InlineData(typeof(NoGroupByAggregationWrapper), true)] + [InlineData(typeof(NoGroupByWrapper), true)] [InlineData(typeof(object), false)] [InlineData(typeof(SelectExpandWrapper), false)] [InlineData(null, false)] diff --git a/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/DynamicTypeWrapperConverterTests.cs b/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/DynamicTypeWrapperConverterTests.cs index 9314a1325..b7bb7399b 100644 --- a/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/DynamicTypeWrapperConverterTests.cs +++ b/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/DynamicTypeWrapperConverterTests.cs @@ -19,13 +19,13 @@ namespace Microsoft.AspNetCore.OData.Tests.Query.Wrapper public class DynamicTypeWrapperConverterTests { [Theory] - [InlineData(typeof(AggregationWrapper), true)] + [InlineData(typeof(AggregationWrapper), true)] [InlineData(typeof(ComputeWrapper), true)] - [InlineData(typeof(EntitySetAggregationWrapper), true)] + [InlineData(typeof(EntitySetAggregationWrapper), true)] [InlineData(typeof(FlatteningWrapper), true)] [InlineData(typeof(GroupByWrapper), true)] - [InlineData(typeof(NoGroupByAggregationWrapper), true)] - [InlineData(typeof(NoGroupByWrapper), true)] + [InlineData(typeof(NoGroupByAggregationWrapper), true)] + [InlineData(typeof(NoGroupByWrapper), true)] [InlineData(typeof(object), false)] [InlineData(typeof(SelectExpandWrapper), false)] [InlineData(null, false)] @@ -39,13 +39,13 @@ public void CanConvertWorksForDynamicTypeWrapper(Type type, bool expected) } [Theory] - [InlineData(typeof(AggregationWrapper), typeof(AggregationWrapperConverter))] + [InlineData(typeof(AggregationWrapper), typeof(AggregationWrapperConverter))] [InlineData(typeof(ComputeWrapper), typeof(ComputeWrapperConverter))] - [InlineData(typeof(EntitySetAggregationWrapper), typeof(EntitySetAggregationWrapperConverter))] + [InlineData(typeof(EntitySetAggregationWrapper), typeof(EntitySetAggregationWrapperConverter))] [InlineData(typeof(FlatteningWrapper), typeof(FlatteningWrapperConverter))] - [InlineData(typeof(GroupByWrapper), typeof(GroupByWrapperConverter))] - [InlineData(typeof(NoGroupByAggregationWrapper), typeof(NoGroupByAggregationWrapperConverter))] - [InlineData(typeof(NoGroupByWrapper), typeof(NoGroupByWrapperConverter))] + [InlineData(typeof(GroupByWrapper), typeof(GroupByWrapperConverter))] + [InlineData(typeof(NoGroupByAggregationWrapper), typeof(NoGroupByAggregationWrapperConverter))] + [InlineData(typeof(NoGroupByWrapper), typeof(NoGroupByWrapperConverter))] [InlineData(typeof(object), null)] [InlineData(typeof(SelectExpandWrapper), null)] [InlineData(null, null)] @@ -73,20 +73,20 @@ public void CreateConverterWorksForDynamicTypeWrapper(Type type, Type expected) public void AggregationWrapperConverter_Works_AggregationWrapper() { // Arrange & Act & Assert - TestDynamicTypeWrapperConverterRead(); + TestDynamicTypeWrapperConverterRead>(); // Arrange & Act & Assert - TestDynamicTypeWrapperConverterWrite(); + TestDynamicTypeWrapperConverterWrite>(); } [Fact] public void EntitySetAggregationWrapperConverter_Works_EntitySetAggregationWrapper() { // Arrange & Act & Assert - TestDynamicTypeWrapperConverterRead(); + TestDynamicTypeWrapperConverterRead>(); // Arrange & Act & Assert - TestDynamicTypeWrapperConverterWrite(); + TestDynamicTypeWrapperConverterWrite>(); } [Fact] @@ -103,20 +103,20 @@ public void GroupByWrapperWrapperConverter_Works_GroupByWrapper() public void NoGroupByAggregationWrapperConverter_Works_NoGroupByAggregationWrapper() { // Arrange & Act & Assert - TestDynamicTypeWrapperConverterRead(); + TestDynamicTypeWrapperConverterRead>(); // Arrange & Act & Assert - TestDynamicTypeWrapperConverterWrite(); + TestDynamicTypeWrapperConverterWrite>(); } [Fact] public void NoGroupByWrapperWrapperConverter_Works_NoGroupByWrapper() { // Arrange & Act & Assert - TestDynamicTypeWrapperConverterRead(); + TestDynamicTypeWrapperConverterRead>(); // Arrange & Act & Assert - TestDynamicTypeWrapperConverterWrite(); + TestDynamicTypeWrapperConverterWrite>(); } internal static void TestDynamicTypeWrapperConverterRead() where T : GroupByWrapper @@ -131,7 +131,7 @@ internal static void TestDynamicTypeWrapperConverterRead() where T : GroupByW // Act ReadOnlySpan jsonReadOnlySpan = Encoding.UTF8.GetBytes("any"); Utf8JsonReader reader = new Utf8JsonReader(jsonReadOnlySpan); - typeConverter.Read(ref reader, typeof(AggregationWrapper), options); + typeConverter.Read(ref reader, typeof(AggregationWrapper), options); } catch (NotImplementedException ex) { diff --git a/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/SelectExpandWrapperConverterTests.cs b/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/SelectExpandWrapperConverterTests.cs index e2268bca1..bedd965a8 100644 --- a/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/SelectExpandWrapperConverterTests.cs +++ b/test/Microsoft.AspNetCore.OData.Tests/Query/Wrapper/SelectExpandWrapperConverterTests.cs @@ -29,7 +29,7 @@ public class SelectExpandWrapperConverterTests [InlineData(typeof(SelectSome), true)] [InlineData(typeof(SelectExpandWrapper), false)] [InlineData(typeof(FlatteningWrapper), false)] - [InlineData(typeof(NoGroupByWrapper), false)] + [InlineData(typeof(NoGroupByWrapper), false)] [InlineData(typeof(object), false)] [InlineData(null, false)] public void CanConvertWorksForSelectExpandWrapper(Type type, bool expected) @@ -49,7 +49,7 @@ public void CanConvertWorksForSelectExpandWrapper(Type type, bool expected) [InlineData(typeof(SelectExpandWrapper), typeof(SelectExpandWrapperConverter))] [InlineData(typeof(SelectExpandWrapper), null)] [InlineData(typeof(FlatteningWrapper), null)] - [InlineData(typeof(NoGroupByWrapper), null)] + [InlineData(typeof(NoGroupByWrapper), null)] [InlineData(typeof(object), null)] [InlineData(null, null)] public void CreateConverterWorksForSelectExpandWrapper(Type type, Type expected)