Skip to content

Commit

Permalink
Simplified previous fix for #17. Fixed a broken test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stewienj committed Feb 10, 2021
1 parent 6a3b6a1 commit 41170d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public void Test_ConcurrentObservableSortedCollection_InsertRange()

Assert.AreEqual(returnedObject, collection);
Assert.AreEqual(NotifyCollectionChangedAction.Add, returnedArgs.Action);
Assert.AreEqual(startIndex, returnedArgs.NewStartingIndex);
// Sorted collection doesn't add at the index, so it should be -1
Assert.AreEqual(-1, returnedArgs.NewStartingIndex);
Assert.IsNotNull(returnedArgs.NewItems);
Assert.IsNull(returnedArgs.OldItems);
Assert.AreEqual(toAdd.Count(), returnedArgs.NewItems.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public override void AddRange(IList<T> items)

public override void Reset(IList<T> items) =>
DoReadWriteNotify(
() => new OldAndNew(ImmutableList.ToArray(),items.OrderBy(x => x, _sorter).ToList()),
(oldAndNew) => ImmutableList<T>.Empty.AddRange(oldAndNew.New),
(oldAndNew) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)oldAndNew.Old, 0),
(oldAndNew) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)oldAndNew.New, 0)
// Sort the incoming collection and add it directly to the internal collection.
// Should be quicker than sorting 1 by 1 on insert.
() => ImmutableList.ToArray(),
(oldItems) => ImmutableList<T>.Empty.AddRange(items.OrderBy(x => x, _sorter).ToList()),
(oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (IList)oldItems, 0),
(oldItems) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (IList)items, 0)
);

public override void Insert(int index, T item)
Expand All @@ -75,16 +77,6 @@ public override T this[int index]
Add(value);
}
}

private class OldAndNew {
public OldAndNew(T[] old, List<T> @new)
{
Old = old;
New = @new;
}
public T[] Old;
public List<T> New;
}
}
}

Expand Down

0 comments on commit 41170d3

Please sign in to comment.