@@ -91,17 +91,57 @@ protected override (ChangeSetAggregator<Person, string> Aggregrator, IList<Perso
9191}
9292
9393// Bind to a readonly observable collection using binary search
94- public sealed class SortAndBindWithBinarySearch : SortAndBindFixture
94+ public sealed class SortAndBindWithBinarySearch1 : SortAndBindFixture
9595{
9696 protected override ( ChangeSetAggregator < Person , string > Aggregrator , IList < Person > List ) SetUpTests ( )
9797 {
98- var options = new SortAndBindOptions { UseBinarySearch = true } ;
98+ var options = new SortAndBindOptions { UseBinarySearch = true , UseReplaceForUpdates = false } ;
9999 var aggregator = _source . Connect ( ) . SortAndBind ( out var list , _comparer , options ) . AsAggregator ( ) ;
100100
101101 return ( aggregator , list ) ;
102102 }
103103}
104104
105+ public sealed class SortAndBindWithBinarySearch2 : SortAndBindFixture
106+ {
107+ protected override ( ChangeSetAggregator < Person , string > Aggregrator , IList < Person > List ) SetUpTests ( )
108+ {
109+ var options = new SortAndBindOptions { UseBinarySearch = true , UseReplaceForUpdates = true } ;
110+ var aggregator = _source . Connect ( ) . SortAndBind ( out var list , _comparer , options ) . AsAggregator ( ) ;
111+
112+ return ( aggregator , list ) ;
113+ }
114+ }
115+
116+ public class SortAndBindBinarySearch_ForSameKeyAndObjectValues : IDisposable
117+ {
118+ private readonly List < int > _target = new ( ) ;
119+ private readonly SourceCache < int , int > _strings = new ( i=> i ) ;
120+
121+ [ Theory ]
122+ [ InlineData ( false ) ]
123+ [ InlineData ( true ) ]
124+ public void UpdateAnyWhereShouldNotBreak ( bool useReplaceForUpdates )
125+ {
126+ var options = new SortAndBindOptions { UseBinarySearch = true , UseReplaceForUpdates = useReplaceForUpdates } ;
127+
128+ using var subscription = _strings . Connect ( ) . SortAndBind ( _target , SortExpressionComparer < int > . Ascending ( i=> i ) , options ) . Subscribe ( ) ;
129+
130+ var items = Enumerable . Range ( 1 , 10 ) . ToList ( ) ;
131+
132+ _strings . AddOrUpdate ( items ) ;
133+ _strings . AddOrUpdate ( 1 ) ;
134+ _strings . AddOrUpdate ( 5 ) ;
135+ _strings . AddOrUpdate ( 10 ) ;
136+
137+ _target . SequenceEqual ( items ) . Should ( ) . BeTrue ( ) ;
138+ }
139+
140+ public void Dispose ( ) => _strings . Dispose ( ) ;
141+ }
142+
143+
144+
105145// Bind to a readonly observable collection - using default comparer
106146public sealed class SortAndBindToReadOnlyObservableCollectionDefaultComparer : SortAndBindFixture
107147{
@@ -291,9 +331,9 @@ public void InsertAtEnd()
291331 last . Should ( ) . Be ( toInsert ) ;
292332
293333 _boundList . SequenceEqual ( _source . Items . OrderBy ( p => p , _comparer ) ) . Should ( ) . BeTrue ( ) ;
294-
295334 }
296335
336+
297337 [ Fact ]
298338 public void InsertInMiddle ( )
299339 {
@@ -568,8 +608,6 @@ public void UpdateFirst()
568608 [ Fact ]
569609 public void UpdateLast ( )
570610 {
571- //TODO: fixed Text
572-
573611 var people = _generator . Take ( 100 ) . ToList ( ) ;
574612 _source . AddOrUpdate ( people ) ;
575613
@@ -582,9 +620,6 @@ public void UpdateLast()
582620 int IndexFromKey ( string key ) => people . FindIndex ( p => p . Key == key ) ;
583621
584622 people . OrderBy ( p => p , _comparer ) . SequenceEqual ( _boundList ) . Should ( ) . BeTrue ( ) ;
585-
586-
587-
588623 }
589624
590625
0 commit comments