-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Concept/Prototype for testing utilities (#870)
- Loading branch information
1 parent
f6a187f
commit 8fd1124
Showing
10 changed files
with
977 additions
and
497 deletions.
There are no files selected for viewing
248 changes: 117 additions & 131 deletions
248
src/DynamicData.Tests/Cache/ExpireAfterFixture.ForSource.cs
Large diffs are not rendered by default.
Oops, something went wrong.
323 changes: 174 additions & 149 deletions
323
src/DynamicData.Tests/Cache/ExpireAfterFixture.ForStream.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
src/DynamicData.Tests/Utilities/CacheItemRecordingObserver.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,71 @@ | ||
using System.Collections.Generic; | ||
using System.Reactive.Concurrency; | ||
|
||
namespace DynamicData.Tests.Utilities; | ||
|
||
public sealed class CacheItemRecordingObserver<TObject, TKey> | ||
: RecordingObserverBase<IChangeSet<TObject, TKey>> | ||
where TObject : notnull | ||
where TKey : notnull | ||
{ | ||
private readonly List<IChangeSet<TObject, TKey>> _recordedChangeSets; | ||
private readonly Dictionary<TKey, TObject> _recordedItemsByKey; | ||
private readonly List<TObject> _recordedItemsSorted; | ||
|
||
public CacheItemRecordingObserver(IScheduler scheduler) | ||
: base(scheduler) | ||
{ | ||
_recordedChangeSets = new(); | ||
_recordedItemsByKey = new(); | ||
_recordedItemsSorted = new(); | ||
} | ||
|
||
public IReadOnlyList<IChangeSet<TObject, TKey>> RecordedChangeSets | ||
=> _recordedChangeSets; | ||
|
||
public IReadOnlyDictionary<TKey, TObject> RecordedItemsByKey | ||
=> _recordedItemsByKey; | ||
|
||
public IReadOnlyList<TObject> RecordedItemsSorted | ||
=> _recordedItemsSorted; | ||
|
||
protected override void OnNext(IChangeSet<TObject, TKey> value) | ||
{ | ||
if (!HasFinalized) | ||
{ | ||
_recordedChangeSets.Add(value); | ||
|
||
foreach (var change in value) | ||
{ | ||
switch (change.Reason) | ||
{ | ||
case ChangeReason.Add: | ||
_recordedItemsByKey.Add(change.Key, change.Current); | ||
if (change.CurrentIndex is not -1) | ||
_recordedItemsSorted.Insert(change.CurrentIndex, change.Current); | ||
break; | ||
|
||
case ChangeReason.Moved: | ||
_recordedItemsSorted.RemoveAt(change.PreviousIndex); | ||
_recordedItemsSorted.Insert(change.CurrentIndex, change.Current); | ||
break; | ||
|
||
case ChangeReason.Remove: | ||
_recordedItemsByKey.Remove(change.Key); | ||
if (change.CurrentIndex is not -1) | ||
_recordedItemsSorted.RemoveAt(change.CurrentIndex); | ||
break; | ||
|
||
case ChangeReason.Update: | ||
_recordedItemsByKey[change.Key] = change.Current; | ||
if (change.CurrentIndex is not -1) | ||
{ | ||
_recordedItemsSorted.RemoveAt(change.PreviousIndex); | ||
_recordedItemsSorted.Insert(change.CurrentIndex, change.Current); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/DynamicData.Tests/Utilities/ListItemRecordingObserver.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,74 @@ | ||
using System.Collections.Generic; | ||
using System.Reactive.Concurrency; | ||
|
||
namespace DynamicData.Tests.Utilities; | ||
|
||
public sealed class ListItemRecordingObserver<T> | ||
: RecordingObserverBase<IChangeSet<T>> | ||
where T : notnull | ||
{ | ||
private readonly List<IChangeSet<T>> _recordedChangeSets; | ||
private readonly List<T> _recordedItems; | ||
|
||
public ListItemRecordingObserver(IScheduler scheduler) | ||
: base(scheduler) | ||
{ | ||
_recordedChangeSets = new(); | ||
_recordedItems = new(); | ||
} | ||
|
||
public IReadOnlyList<IChangeSet<T>> RecordedChangeSets | ||
=> _recordedChangeSets; | ||
|
||
public IReadOnlyList<T> RecordedItems | ||
=> _recordedItems; | ||
|
||
protected override void OnNext(IChangeSet<T> value) | ||
{ | ||
if (!HasFinalized) | ||
{ | ||
_recordedChangeSets.Add(value); | ||
|
||
foreach (var change in value) | ||
{ | ||
switch (change.Reason) | ||
{ | ||
case ListChangeReason.Add: | ||
if (change.Item.CurrentIndex is -1) | ||
_recordedItems.Add(change.Item.Current); | ||
else | ||
_recordedItems.Insert(change.Item.CurrentIndex, change.Item.Current); | ||
break; | ||
|
||
case ListChangeReason.AddRange: | ||
if (change.Range.Index is -1) | ||
_recordedItems.AddRange(change.Range); | ||
else | ||
_recordedItems.InsertRange(change.Range.Index, change.Range); | ||
break; | ||
|
||
case ListChangeReason.Clear: | ||
_recordedItems.Clear(); | ||
break; | ||
|
||
case ListChangeReason.Moved: | ||
_recordedItems.RemoveAt(change.Item.PreviousIndex); | ||
_recordedItems.Insert(change.Item.CurrentIndex, change.Item.Current); | ||
break; | ||
|
||
case ListChangeReason.Remove: | ||
_recordedItems.RemoveAt(change.Item.CurrentIndex); | ||
break; | ||
|
||
case ListChangeReason.RemoveRange: | ||
_recordedItems.RemoveRange(change.Range.Index, change.Range.Count); | ||
break; | ||
|
||
case ListChangeReason.Replace: | ||
_recordedItems[change.Item.CurrentIndex] = change.Item.Current; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.