5 changed files with 145 additions and 2 deletions
@ -0,0 +1,22 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> |
||||
|
<PropertyGroup> |
||||
|
<TargetFrameworks>netcoreapp2.0;net47</TargetFrameworks> |
||||
|
<LangVersion>latest</LangVersion> |
||||
|
<OutputType>Library</OutputType> |
||||
|
<IsTestProject>true</IsTestProject> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="..\..\build\UnitTests.NetCore.targets" /> |
||||
|
<Import Project="..\..\build\UnitTests.NetFX.props" /> |
||||
|
<Import Project="..\..\build\Moq.props" /> |
||||
|
<Import Project="..\..\build\XUnit.props" /> |
||||
|
<Import Project="..\..\build\Rx.props" /> |
||||
|
<Import Project="..\..\build\Microsoft.Reactive.Testing.props" /> |
||||
|
<Import Project="..\..\build\Base.props" /> |
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj" /> |
||||
|
<ProjectReference Include="..\Avalonia.UnitTests\Avalonia.UnitTests.csproj" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> |
||||
|
</ItemGroup> |
||||
|
</Project> |
||||
@ -0,0 +1,94 @@ |
|||||
|
using System.Linq; |
||||
|
using Avalonia.Collections; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Controls.DataGrid.UnitTests.Collections |
||||
|
{ |
||||
|
|
||||
|
public class DataGridSortDescriptionTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void OrderBy_Orders_Correctly_When_Ascending() |
||||
|
{ |
||||
|
var items = new[] |
||||
|
{ |
||||
|
new Item("b", "b"), |
||||
|
new Item("a", "a"), |
||||
|
new Item("c", "c"), |
||||
|
}; |
||||
|
var expectedResult = items.OrderBy(i => i.Prop1).ToList(); |
||||
|
var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop1), @descending: false); |
||||
|
|
||||
|
sortDescription.Initialize(typeof(Item)); |
||||
|
var result = sortDescription.OrderBy(items).ToList(); |
||||
|
|
||||
|
Assert.Equal(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void OrderBy_Orders_Correctly_When_Descending() |
||||
|
{ |
||||
|
var items = new[] |
||||
|
{ |
||||
|
new Item("b", "b"), |
||||
|
new Item("a", "a"), |
||||
|
new Item("c", "c"), |
||||
|
}; |
||||
|
var expectedResult = items.OrderByDescending(i => i.Prop1).ToList(); |
||||
|
var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop1), @descending: true); |
||||
|
|
||||
|
sortDescription.Initialize(typeof(Item)); |
||||
|
var result = sortDescription.OrderBy(items).ToList(); |
||||
|
|
||||
|
Assert.Equal(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void ThenBy_Orders_Correctly_When_Ascending() |
||||
|
{ |
||||
|
var items = new[] |
||||
|
{ |
||||
|
new Item("a", "b"), |
||||
|
new Item("a", "a"), |
||||
|
new Item("a", "c"), |
||||
|
}.OrderBy(i => i.Prop1); |
||||
|
var expectedResult = items.ThenBy(i => i.Prop2).ToList(); |
||||
|
var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop2), @descending: false); |
||||
|
|
||||
|
sortDescription.Initialize(typeof(Item)); |
||||
|
var result = sortDescription.ThenBy((IOrderedEnumerable<object>)items).ToList(); |
||||
|
|
||||
|
Assert.Equal(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void ThenBy_Orders_Correctly_When_Descending() |
||||
|
{ |
||||
|
var items = new[] |
||||
|
{ |
||||
|
new Item("a", "b"), |
||||
|
new Item("a", "a"), |
||||
|
new Item("a", "c"), |
||||
|
}.OrderBy(i => i.Prop1); |
||||
|
var expectedResult = items.ThenByDescending(i => i.Prop2).ToList(); |
||||
|
var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop2), @descending: true); |
||||
|
|
||||
|
sortDescription.Initialize(typeof(Item)); |
||||
|
var result = sortDescription.ThenBy((IOrderedEnumerable<object>)items).ToList(); |
||||
|
|
||||
|
Assert.Equal(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
private class Item |
||||
|
{ |
||||
|
public Item(string prop1, string prop2) |
||||
|
{ |
||||
|
Prop1 = prop1; |
||||
|
Prop2 = prop2; |
||||
|
} |
||||
|
|
||||
|
public string Prop1 { get; } |
||||
|
public string Prop2 { get; } |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue