-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix QuickGrid nullable property sorting by handling UnaryExpression in ToPropertyName #62602
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
27732f6
Initial plan
Copilot 2069e66
Fix QuickGrid nullable property sorting by handling UnaryExpression i…
Copilot 8fd4ad8
Add test project and comprehensive tests for QuickGrid GridSort.ToPro…
Copilot 89aa407
Update test project configuration to match Components test patterns
Copilot d85adee
Add QuickGrid test project to Components solution file
Copilot ca4430e
Add QuickGrid test project to main AspNetCore.slnx solution file
Copilot e5bcb38
Fix compilation error by adding InternalsVisibleTo and proper test st…
Copilot 9fb5f26
Update src/Components/QuickGrid/Microsoft.AspNetCore.Components.Quick…
javiercn eb7b508
Update src/Components/QuickGrid/Microsoft.AspNetCore.Components.Quick…
javiercn 5f36fef
Update src/Components/QuickGrid/Microsoft.AspNetCore.Components.Quick…
javiercn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/test/GridSortTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Globalization; | ||
| using System.Linq.Expressions; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.QuickGrid.Tests; | ||
|
|
||
| public class GridSortTest | ||
| { | ||
| // Test model classes | ||
| private class TestEntity | ||
| { | ||
| public string Name { get; set; } = string.Empty; | ||
| public int Age { get; set; } | ||
| public DateTime? NullableDate { get; set; } | ||
| public int? NullableInt { get; set; } | ||
| public TestChild Child { get; set; } = new(); | ||
| } | ||
|
|
||
| private class TestChild | ||
| { | ||
| public string ChildName { get; set; } = string.Empty; | ||
| public DateTime? ChildNullableDate { get; set; } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_SimpleProperty_ReturnsPropertyName() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, string>> expression = x => x.Name; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByAscending(expression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Single(propertyList); | ||
| Assert.Equal("Name", propertyList.First().PropertyName); | ||
| Assert.Equal(SortDirection.Ascending, propertyList.First().Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_NullableProperty_ReturnsPropertyName() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, DateTime?>> expression = x => x.NullableDate; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByAscending(expression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Single(propertyList); | ||
| Assert.Equal("NullableDate", propertyList.First().PropertyName); | ||
| Assert.Equal(SortDirection.Ascending, propertyList.First().Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_NullableInt_ReturnsPropertyName() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, int?>> expression = x => x.NullableInt; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByAscending(expression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Single(propertyList); | ||
| Assert.Equal("NullableInt", propertyList.First().PropertyName); | ||
| Assert.Equal(SortDirection.Ascending, propertyList.First().Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_NestedProperty_ReturnsNestedPropertyName() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, string>> expression = x => x.Child.ChildName; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByAscending(expression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Single(propertyList); | ||
| Assert.Equal("Child.ChildName", propertyList.First().PropertyName); | ||
| Assert.Equal(SortDirection.Ascending, propertyList.First().Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_NestedNullableProperty_ReturnsNestedPropertyName() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, DateTime?>> expression = x => x.Child.ChildNullableDate; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByAscending(expression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Single(propertyList); | ||
| Assert.Equal("Child.ChildNullableDate", propertyList.First().PropertyName); | ||
| Assert.Equal(SortDirection.Ascending, propertyList.First().Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_DescendingSort_ReturnsCorrectDirection() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, DateTime?>> expression = x => x.NullableDate; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByDescending(expression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Single(propertyList); | ||
| Assert.Equal("NullableDate", propertyList.First().PropertyName); | ||
| Assert.Equal(SortDirection.Descending, propertyList.First().Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_MultipleSort_ReturnsAllProperties() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, string>> firstExpression = x => x.Name; | ||
| Expression<Func<TestEntity, DateTime?>> secondExpression = x => x.NullableDate; | ||
|
|
||
| // Act | ||
| var gridSort = GridSort<TestEntity>.ByAscending(firstExpression) | ||
| .ThenDescending(secondExpression); | ||
| var propertyList = gridSort.ToPropertyList(ascending: true); | ||
|
|
||
| // Assert | ||
| Assert.Equal(2, propertyList.Count); | ||
|
|
||
| var firstProperty = propertyList.First(); | ||
| Assert.Equal("Name", firstProperty.PropertyName); | ||
| Assert.Equal(SortDirection.Ascending, firstProperty.Direction); | ||
|
|
||
| var secondProperty = propertyList.Last(); | ||
| Assert.Equal("NullableDate", secondProperty.PropertyName); | ||
| Assert.Equal(SortDirection.Descending, secondProperty.Direction); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_InvalidExpression_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, string>> invalidExpression = x => x.Name.ToUpper(CultureInfo.InvariantCulture); | ||
|
|
||
| // Act & Assert | ||
| var gridSort = GridSort<TestEntity>.ByAscending(invalidExpression); | ||
| var exception = Assert.Throws<ArgumentException>(() => gridSort.ToPropertyList(ascending: true)); | ||
| Assert.Contains("The supplied expression can't be represented as a property name for sorting", exception.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_MethodCallExpression_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, string>> invalidExpression = x => x.Name.Substring(0, 1); | ||
|
|
||
| // Act & Assert | ||
| var gridSort = GridSort<TestEntity>.ByAscending(invalidExpression); | ||
| var exception = Assert.Throws<ArgumentException>(() => gridSort.ToPropertyList(ascending: true)); | ||
| Assert.Contains("The supplied expression can't be represented as a property name for sorting", exception.Message); | ||
javiercn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void ToPropertyName_ConstantExpression_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| Expression<Func<TestEntity, string>> invalidExpression = x => "constant"; | ||
|
|
||
| // Act & Assert | ||
| var gridSort = GridSort<TestEntity>.ByAscending(invalidExpression); | ||
| var exception = Assert.Throws<ArgumentException>(() => gridSort.ToPropertyList(ascending: true)); | ||
| Assert.Contains("The supplied expression can't be represented as a property name for sorting", exception.Message); | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
...pNetCore.Components.QuickGrid/test/Microsoft.AspNetCore.Components.QuickGrid.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
| <RootNamespace>Microsoft.AspNetCore.Components.QuickGrid.Tests</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Reference Include="Microsoft.AspNetCore.Components.QuickGrid" /> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
|
|
||
| <ItemGroup> | ||
| <Using Include="Xunit" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.