-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2335 from marticliment/listview-to-itemsview
Replace ListView with ItemsView
- Loading branch information
Showing
13 changed files
with
249 additions
and
178 deletions.
There are no files selected for viewing
37 changes: 25 additions & 12 deletions
37
src/UniGetUI.Core.Classes.Tests/SortableObservableCollectionTests.cs
This file contains 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 |
---|---|---|
@@ -1,33 +1,46 @@ | ||
using System.Text.Json.Serialization.Metadata; | ||
|
||
namespace UniGetUI.Core.Classes.Tests | ||
{ | ||
public class SortableObservableCollectionTests | ||
{ | ||
class SortableInt : IIndexableListItem | ||
{ | ||
public int Value { get; set; } | ||
public int Index { get; set; } | ||
public SortableInt(int value) { Value = value; } | ||
} | ||
|
||
[Fact] | ||
public void TestSortableCollection() | ||
{ | ||
int EventTriggeredCount = 0; | ||
|
||
SortableObservableCollection<int> SortableCollection = new(); | ||
SortableObservableCollection<SortableInt> SortableCollection = new(); | ||
SortableCollection.CollectionChanged += (s, e) => { EventTriggeredCount++; }; | ||
SortableCollection.SortingSelector = (s) => { return s; }; | ||
SortableCollection.Add(1); | ||
SortableCollection.Add(3); | ||
SortableCollection.Add(4); | ||
SortableCollection.SortingSelector = (s) => { return s.Value; }; | ||
SortableCollection.Add(new(1)); | ||
SortableCollection.Add(new(2)); | ||
SortableCollection.Add(new(4)); | ||
|
||
SortableCollection.BlockSorting = true; | ||
SortableCollection.Add(5); | ||
SortableCollection.Add(2); | ||
SortableCollection.Add(new(5)); | ||
SortableCollection.Add(new(2)); | ||
SortableCollection.BlockSorting = false; | ||
|
||
|
||
SortableCollection.Sort(); | ||
|
||
Assert.Equal(7, EventTriggeredCount); | ||
Assert.Equal(1, SortableCollection[0]); | ||
Assert.Equal(2, SortableCollection[1]); | ||
Assert.Equal(3, SortableCollection[2]); | ||
Assert.Equal(4, SortableCollection[3]); | ||
Assert.Equal(5, SortableCollection[4]); | ||
Assert.Equal(5, SortableCollection.Count); | ||
Assert.Equal(1, SortableCollection[0].Value); | ||
Assert.Equal(2, SortableCollection[1].Value); | ||
Assert.Equal(2, SortableCollection[2].Value); | ||
Assert.Equal(4, SortableCollection[3].Value); | ||
Assert.Equal(5, SortableCollection[4].Value); | ||
|
||
for (int i = 0; i < SortableCollection.Count; i++) | ||
Assert.Equal(i, SortableCollection[i].Index); | ||
} | ||
} | ||
} |
This file contains 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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace UniGetUI.Core.Classes | ||
{ | ||
public interface IIndexableListItem | ||
{ | ||
public int Index { get; set; } | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.