-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
1,093 additions
and
802 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Livet.StatefulModel; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Livet.NUnit.StatefulModel | ||
{ | ||
[TestFixture] | ||
public class ConvertingTest | ||
{ | ||
[Test] | ||
public void ToReadOnlyTest() | ||
{ | ||
var src = new ObservableSynchronizedCollection<string>(); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Livet.Test/StatefulModel/FilteredObservableCollectionTest.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Livet.StatefulModel; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text; | ||
|
||
namespace Livet.NUnit.StatefulModel | ||
{ | ||
[TestFixture] | ||
public class FilteredObservableCollectionTest | ||
{ | ||
private FilteredObservableCollection<string> _target; | ||
private List<NotifyCollectionChangedEventArgs> _collectionChanged; | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_target = new FilteredObservableCollection<string>(x => !x.Contains("x")); | ||
_collectionChanged = new List<NotifyCollectionChangedEventArgs>(); | ||
_target.CollectionChanged += (_, e) => _collectionChanged.Add(e); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_target = null; | ||
_collectionChanged = null; | ||
} | ||
|
||
[Test] | ||
public void BasicUsage() | ||
{ | ||
_target.Add("aaa"); | ||
_target.Add("axa"); | ||
_target.Add("bbb"); | ||
_target.Add("bxb"); | ||
_target.Is("aaa", "bbb"); | ||
|
||
_collectionChanged.SelectMany(x => x.NewItems.Cast<string>()) | ||
.Is("aaa", "bbb"); | ||
_collectionChanged.Select(x => x.Action) | ||
.Is( | ||
NotifyCollectionChangedAction.Add, | ||
NotifyCollectionChangedAction.Add | ||
); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
Livet.Test/StatefulModel/ObservableSynchronizedCollectionTest.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Livet.StatefulModel; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Livet.NUnit.StatefulModel | ||
{ | ||
[TestFixture] | ||
public class ObservableSynchronizedCollectionTest | ||
{ | ||
private ObservableSynchronizedCollection<string> _target; | ||
private List<NotifyCollectionChangedEventArgs> _collectionChanged; | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_target = new ObservableSynchronizedCollection<string>(); | ||
_collectionChanged = new List<NotifyCollectionChangedEventArgs>(); | ||
_target.CollectionChanged += (_, args) => _collectionChanged.Add(args); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_target = null; | ||
_collectionChanged = null; | ||
} | ||
|
||
[Test] | ||
public void ConstructorTest() | ||
{ | ||
var c = new ObservableSynchronizedCollection<string>(new[] { "a", "b", "c" }); | ||
c.Count.Is(3); | ||
} | ||
|
||
[Test] | ||
public void BasicUsage() | ||
{ | ||
_target.Count.Is(0); | ||
|
||
_target.Add("xxx"); | ||
_collectionChanged.Count.Is(1); | ||
var collectionChangedEventArgs = _collectionChanged.First(); | ||
collectionChangedEventArgs.IsNotNull(); | ||
collectionChangedEventArgs.Action.Is(NotifyCollectionChangedAction.Add); | ||
collectionChangedEventArgs.NewItems.Count.Is(1); | ||
collectionChangedEventArgs.NewItems.Cast<string>().First().Is("xxx"); | ||
} | ||
|
||
[Test] | ||
public void InsertTest() | ||
{ | ||
_target.Add("1"); | ||
_target.Add("2"); | ||
_target.Insert(1, "xxx"); | ||
|
||
_target.Is("1", "xxx", "2"); | ||
_collectionChanged.SelectMany(x => x.NewItems.Cast<string>()) | ||
.Is("1", "2", "xxx"); | ||
_collectionChanged.Select(x => x.Action) | ||
.Is(NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Add); | ||
} | ||
|
||
[Test] | ||
public void RemoveTest() | ||
{ | ||
_target.Add("1"); | ||
_target.Add("2"); | ||
|
||
_target.Remove("1"); | ||
_target.Is("2"); | ||
|
||
_collectionChanged.Select(x => x.Action) | ||
.Is(NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Remove); | ||
_collectionChanged.SelectMany(x => x.NewItems?.Cast<string>() ?? Enumerable.Empty<string>()) | ||
.Is("1", "2"); | ||
_collectionChanged.Last().OldItems.Count.Is(1); | ||
_collectionChanged.Last().OldItems.Cast<string>().Is("1"); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Livet.Test/StatefulModel/SortedObservableCollectionTest.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Livet.StatefulModel; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text; | ||
|
||
namespace Livet.NUnit.StatefulModel | ||
{ | ||
[TestFixture] | ||
public class SortedObservableCollectionTest | ||
{ | ||
private SortedObservableCollection<(int key, string value), int> _target; | ||
private List<NotifyCollectionChangedEventArgs> _collectionChanged; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_target = new SortedObservableCollection<(int key, string value), int>(x => x.key); | ||
_collectionChanged = new List<NotifyCollectionChangedEventArgs>(); | ||
_target.CollectionChanged += (_, e) => _collectionChanged.Add(e); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_target = null; | ||
_collectionChanged = null; | ||
} | ||
|
||
[Test] | ||
public void BasicUsage() | ||
{ | ||
_target.Add((100, "max")); | ||
_target.Add((0, "min")); | ||
_target.Add((50, "mid")); | ||
|
||
_target.Count.Is(3); | ||
_target.Is( | ||
(0, "min"), | ||
(50, "mid"), | ||
(100, "max") | ||
); | ||
|
||
_collectionChanged.Select(x => x.Action) | ||
.Is(NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Add, NotifyCollectionChangedAction.Add); | ||
_collectionChanged.Select(x => x.NewStartingIndex) | ||
.Is(0, 0, 1); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
Livet.Test/StatefulModel/SynchronizationContextCollectionTest.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Livet.StatefulModel; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text; | ||
using System.Threading; | ||
|
||
namespace Livet.NUnit.StatefulModel | ||
{ | ||
[TestFixture] | ||
public class SynchronizationContextCollectionTest | ||
{ | ||
private TestSynchronizationContext _context; | ||
private SynchronizationContextCollection<string> _target; | ||
private List<NotifyCollectionChangedEventArgs> _collectionChanged; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_context = new TestSynchronizationContext(); | ||
_target = new SynchronizationContextCollection<string>(_context); | ||
_collectionChanged = new List<NotifyCollectionChangedEventArgs>(); | ||
_target.CollectionChanged += (_, e) => _collectionChanged.Add(e); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
_target = null; | ||
_context = null; | ||
} | ||
|
||
[Test] | ||
public void BasicUsage() | ||
{ | ||
_target.Add("a"); | ||
_target.Add("b"); | ||
_target.Add("c"); | ||
_target.Remove("b"); | ||
_target[1] = "C"; | ||
|
||
_target.Is("a", "C"); | ||
_context.Count.Is(5); | ||
|
||
_collectionChanged.Select(x => x.Action) | ||
.Is( | ||
NotifyCollectionChangedAction.Add, | ||
NotifyCollectionChangedAction.Add, | ||
NotifyCollectionChangedAction.Add, | ||
NotifyCollectionChangedAction.Remove, | ||
NotifyCollectionChangedAction.Replace | ||
); | ||
_collectionChanged.SelectMany(x => x.NewItems?.Cast<string>() ?? Enumerable.Empty<string>()) | ||
.Is("a", "b", "c", "C"); | ||
_collectionChanged[3].OldItems.Cast<string>().Is("b"); | ||
_collectionChanged[4].Is( | ||
x => x.Action == NotifyCollectionChangedAction.Replace && x.NewItems.Cast<string>().ElementAt(0) == "C" && x.NewStartingIndex == 1); | ||
} | ||
|
||
class TestSynchronizationContext : SynchronizationContext | ||
{ | ||
public int Count { get; set; } | ||
public override void Post(SendOrPostCallback d, object state) | ||
{ | ||
Count++; | ||
d(state); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.