@@ -91,17 +91,57 @@ protected override (ChangeSetAggregator<Person, string> Aggregrator, IList<Perso
91
91
}
92
92
93
93
// Bind to a readonly observable collection using binary search
94
- public sealed class SortAndBindWithBinarySearch : SortAndBindFixture
94
+ public sealed class SortAndBindWithBinarySearch1 : SortAndBindFixture
95
95
{
96
96
protected override ( ChangeSetAggregator < Person , string > Aggregrator , IList < Person > List ) SetUpTests ( )
97
97
{
98
- var options = new SortAndBindOptions { UseBinarySearch = true } ;
98
+ var options = new SortAndBindOptions { UseBinarySearch = true , UseReplaceForUpdates = false } ;
99
99
var aggregator = _source . Connect ( ) . SortAndBind ( out var list , _comparer , options ) . AsAggregator ( ) ;
100
100
101
101
return ( aggregator , list ) ;
102
102
}
103
103
}
104
104
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
+
105
145
// Bind to a readonly observable collection - using default comparer
106
146
public sealed class SortAndBindToReadOnlyObservableCollectionDefaultComparer : SortAndBindFixture
107
147
{
@@ -291,9 +331,9 @@ public void InsertAtEnd()
291
331
last . Should ( ) . Be ( toInsert ) ;
292
332
293
333
_boundList . SequenceEqual ( _source . Items . OrderBy ( p => p , _comparer ) ) . Should ( ) . BeTrue ( ) ;
294
-
295
334
}
296
335
336
+
297
337
[ Fact ]
298
338
public void InsertInMiddle ( )
299
339
{
@@ -568,8 +608,6 @@ public void UpdateFirst()
568
608
[ Fact ]
569
609
public void UpdateLast ( )
570
610
{
571
- //TODO: fixed Text
572
-
573
611
var people = _generator . Take ( 100 ) . ToList ( ) ;
574
612
_source . AddOrUpdate ( people ) ;
575
613
@@ -582,9 +620,6 @@ public void UpdateLast()
582
620
int IndexFromKey ( string key ) => people . FindIndex ( p => p . Key == key ) ;
583
621
584
622
people . OrderBy ( p => p , _comparer ) . SequenceEqual ( _boundList ) . Should ( ) . BeTrue ( ) ;
585
-
586
-
587
-
588
623
}
589
624
590
625
0 commit comments