test
This commit is contained in:
parent
f0f766940b
commit
25ae432a40
@ -22,7 +22,7 @@ namespace ObservableCollections
|
|||||||
ISortableSynchronizedView<T, TView> CreateSortableView<TView>(Func<T, TView> transform);
|
ISortableSynchronizedView<T, TView> CreateSortableView<TView>(Func<T, TView> transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ISynchronizedView<T, TView> : IReadOnlyCollection<(T, TView)>, IDisposable
|
public interface ISynchronizedView<T, TView> : IReadOnlyCollection<(T Value, TView View)>, IDisposable
|
||||||
{
|
{
|
||||||
object SyncRoot { get; }
|
object SyncRoot { get; }
|
||||||
event NotifyCollectionChangedEventHandler<T>? RoutingCollectionChanged;
|
event NotifyCollectionChangedEventHandler<T>? RoutingCollectionChanged;
|
||||||
|
@ -15,4 +15,8 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\ObservableCollections\ObservableCollections.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
42
tests/ObservableCollections.Tests/ObservableListTest.cs
Normal file
42
tests/ObservableCollections.Tests/ObservableListTest.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ObservableCollections.Tests
|
||||||
|
{
|
||||||
|
public class ObservableListTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void View()
|
||||||
|
{
|
||||||
|
var reference = new ObservableCollection<int>();
|
||||||
|
var list = new ObservableList<int>();
|
||||||
|
var view = list.CreateView(x => new ViewContainer<int>(x));
|
||||||
|
|
||||||
|
list.Add(10); reference.Add(10); // 0
|
||||||
|
list.Add(50); reference.Add(50); // 1
|
||||||
|
list.Add(30); reference.Add(30); // 2
|
||||||
|
list.Add(20); reference.Add(20); // 3
|
||||||
|
list.Add(40); reference.Add(40); // 4
|
||||||
|
|
||||||
|
void Equal(params int[] expected)
|
||||||
|
{
|
||||||
|
reference.Should().Equal(expected);
|
||||||
|
list.Should().Equal(expected);
|
||||||
|
view.Select(x => x.Value).Should().Equal(expected);
|
||||||
|
view.Select(x => x.View).Should().Equal(expected.Select(x => new ViewContainer<int>(x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Equal(10, 50, 30, 20, 40);
|
||||||
|
|
||||||
|
reference.Move(3, 1);
|
||||||
|
list.Move(3, 1);
|
||||||
|
Equal(10, 20, 50, 30, 40);
|
||||||
|
|
||||||
|
reference.Insert(2, 99);
|
||||||
|
list.Insert(2, 99);
|
||||||
|
Equal(10, 20, 99, 50, 30, 40);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace ObservableCollections.Tests
|
|
||||||
{
|
|
||||||
public class UnitTest1
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void Test1()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
27
tests/ObservableCollections.Tests/ViewContainer.cs
Normal file
27
tests/ObservableCollections.Tests/ViewContainer.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ObservableCollections.Tests
|
||||||
|
{
|
||||||
|
public struct ViewContainer<T> : IEquatable<T>
|
||||||
|
{
|
||||||
|
public ViewContainer(T value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Value { get; }
|
||||||
|
|
||||||
|
public static implicit operator ViewContainer<T>(T value) => new ViewContainer<T>(value);
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Value.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(T other)
|
||||||
|
{
|
||||||
|
return EqualityComparer<T>.Default.Equals(Value, other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user