Skip to content

Commit

Permalink
Expose read only collections for source cache (#919)
Browse files Browse the repository at this point in the history
* Expose readonly collections on source cache instead of IEnumerable values

* Update API file
  • Loading branch information
RolandPheasant committed Jul 12, 2024
1 parent 7f2b220 commit 3382f7f
Show file tree
Hide file tree
Showing 43 changed files with 122 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ namespace DynamicData.Cache.Internal
public LockFreeObservableCache(System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source) { }
public int Count { get; }
public System.IObservable<int> CountChanged { get; }
public System.Collections.Generic.IEnumerable<TObject> Items { get; }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TObject>> KeyValues { get; }
public System.Collections.Generic.IEnumerable<TKey> Keys { get; }
public System.Collections.Generic.IReadOnlyList<TObject> Items { get; }
public System.Collections.Generic.IReadOnlyDictionary<TKey, TObject> KeyValues { get; }
public System.Collections.Generic.IReadOnlyList<TKey> Keys { get; }
public System.IObservable<DynamicData.IChangeSet<TObject, TKey>> Connect(System.Func<TObject, bool>? predicate = null, bool suppressEmptyChangeSets = true) { }
public void Dispose() { }
public void Edit(System.Action<DynamicData.ICacheUpdater<TObject, TKey>> editAction) { }
Expand Down Expand Up @@ -874,9 +874,9 @@ namespace DynamicData
where TKey : notnull
{
int Count { get; }
System.Collections.Generic.IEnumerable<TObject> Items { get; }
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TObject>> KeyValues { get; }
System.Collections.Generic.IEnumerable<TKey> Keys { get; }
System.Collections.Generic.IReadOnlyList<TObject> Items { get; }
System.Collections.Generic.IReadOnlyDictionary<TKey, TObject> KeyValues { get; }
System.Collections.Generic.IReadOnlyList<TKey> Keys { get; }
DynamicData.Kernel.Optional<TObject> Lookup(TKey key);
}
public interface IObservableList<T> : System.IDisposable
Expand Down Expand Up @@ -993,9 +993,9 @@ namespace DynamicData
public IntermediateCache(System.IObservable<DynamicData.IChangeSet<TObject, TKey>> source) { }
public int Count { get; }
public System.IObservable<int> CountChanged { get; }
public System.Collections.Generic.IEnumerable<TObject> Items { get; }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TObject>> KeyValues { get; }
public System.Collections.Generic.IEnumerable<TKey> Keys { get; }
public System.Collections.Generic.IReadOnlyList<TObject> Items { get; }
public System.Collections.Generic.IReadOnlyDictionary<TKey, TObject> KeyValues { get; }
public System.Collections.Generic.IReadOnlyList<TKey> Keys { get; }
public System.IObservable<DynamicData.IChangeSet<TObject, TKey>> Connect(System.Func<TObject, bool>? predicate = null, bool suppressEmptyChangeSets = true) { }
public void Dispose() { }
public void Edit(System.Action<DynamicData.ICacheUpdater<TObject, TKey>> updateAction) { }
Expand Down Expand Up @@ -2610,10 +2610,10 @@ namespace DynamicData
public SourceCache(System.Func<TObject, TKey> keySelector) { }
public int Count { get; }
public System.IObservable<int> CountChanged { get; }
public System.Collections.Generic.IEnumerable<TObject> Items { get; }
public System.Collections.Generic.IReadOnlyList<TObject> Items { get; }
public System.Func<TObject, TKey> KeySelector { get; }
public System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TObject>> KeyValues { get; }
public System.Collections.Generic.IEnumerable<TKey> Keys { get; }
public System.Collections.Generic.IReadOnlyDictionary<TKey, TObject> KeyValues { get; }
public System.Collections.Generic.IReadOnlyList<TKey> Keys { get; }
public System.IObservable<DynamicData.IChangeSet<TObject, TKey>> Connect(System.Func<TObject, bool>? predicate = null, bool suppressEmptyChangeSets = true) { }
public void Dispose() { }
public void Edit(System.Action<DynamicData.ISourceUpdater<TObject, TKey>> updateAction) { }
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/AndFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void UpdatingBothProducesResults()
_source2.AddOrUpdate(person);
_results.Messages.Count.Should().Be(1, "Should have no updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand All @@ -92,7 +92,7 @@ public void UpdatingOneProducesOnlyOneUpdate()
_source2.AddOrUpdate(personUpdated);
_results.Messages.Count.Should().Be(2, "Should be 2 updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(personUpdated, "Should be updated person");
_results.Data.Items[0].Should().Be(personUpdated, "Should be updated person");
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions src/DynamicData.Tests/Cache/DisposeManyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ public void ItemsAreDisposedAfterRemovalOrReplacement()
{
new Change<DisposableObject, int>(
reason: ChangeReason.Refresh,
key: _itemsSource.Items.First().Id,
current: _itemsSource.Items.First())
key: _itemsSource.Items[0].Id,
current: _itemsSource.Items[0])
});
_changeSetsSource.OnNext(new ChangeSet<DisposableObject, int>() // Move
{
new Change<DisposableObject, int>(
key: _itemsSource.Items.First().Id,
current: _itemsSource.Items.First(),
key: _itemsSource.Items[0].Id,
current: _itemsSource.Items[0],
currentIndex: 1,
previousIndex: 0)
});
Expand Down
6 changes: 3 additions & 3 deletions src/DynamicData.Tests/Cache/DistinctFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void DuplicatedResultsResultInNoAdditionalMessage()

_results.Messages.Count.Should().Be(1, "Should be 1 update message");
_results.Data.Count.Should().Be(1, "Should be 1 items in the cache");
_results.Data.Items.First().Should().Be(20, "Should 20");
_results.Data.Items[0].Should().Be(20, "Should 20");
}

[Fact]
Expand Down Expand Up @@ -98,7 +98,7 @@ public void FiresAddWhenaNewItemIsAdded()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
_results.Data.Items.First().Should().Be(20, "Should 20");
_results.Data.Items[0].Should().Be(20, "Should 20");
}

[Fact]
Expand All @@ -116,7 +116,7 @@ public void FiresBatchResultOnce()
_results.Data.Count.Should().Be(3, "Should be 3 items in the cache");

_results.Data.Items.Should().BeEquivalentTo(new[] { 20, 21, 22 });
_results.Data.Items.First().Should().Be(20, "Should 20");
_results.Data.Items[0].Should().Be(20, "Should 20");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/DynamicAndFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void UpdatingBothProducesResults()
_source2.AddOrUpdate(person);
_results.Messages.Count.Should().Be(1, "Should have no updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand All @@ -125,7 +125,7 @@ public void UpdatingOneProducesOnlyOneUpdate()
_source2.AddOrUpdate(personUpdated);
_results.Messages.Count.Should().Be(2, "Should be 2 updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(personUpdated, "Should be updated person");
_results.Data.Items[0].Should().Be(personUpdated, "Should be updated person");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/DynamicOrFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void UpdatingBothProducesResultsAndDoesNotDuplicateTheMessage()
_source2.AddOrUpdate(person);
_results.Messages.Count.Should().Be(1, "Should have no updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand All @@ -125,7 +125,7 @@ public void UpdatingOneProducesOnlyOneUpdate()
_source2.AddOrUpdate(personUpdated);
_results.Messages.Count.Should().Be(2, "Should be 2 updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(personUpdated, "Should be updated person");
_results.Data.Items[0].Should().Be(personUpdated, "Should be updated person");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/FilterControllerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void AddMatched()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand Down Expand Up @@ -66,7 +66,7 @@ public void AddNotMatchedAndUpdateMatched()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Messages[0].First().Current.Should().Be(matched, "Should be same person");
_results.Data.Items.First().Should().Be(matched, "Should be same person");
_results.Data.Items[0].Should().Be(matched, "Should be same person");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/FilterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void AddMatched()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand Down Expand Up @@ -59,7 +59,7 @@ public void AddNotMatchedAndUpdateMatched()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Messages[0].First().Current.Should().Be(matched, "Should be same person");
_results.Data.Items.First().Should().Be(matched, "Should be same person");
_results.Data.Items[0].Should().Be(matched, "Should be same person");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/FilterParallelFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void AddMatched()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand Down Expand Up @@ -59,7 +59,7 @@ public void AddNotMatchedAndUpdateMatched()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Messages[0].First().Current.Should().Be(matched, "Should be same person");
_results.Data.Items.First().Should().Be(matched, "Should be same person");
_results.Data.Items[0].Should().Be(matched, "Should be same person");
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions src/DynamicData.Tests/Cache/GroupImmutableFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void FiresOnlyOnceForABatchOfUniqueValues()

_results.Messages.Count.Should().Be(1);
_results.Messages.First().Adds.Should().Be(1);
_results.Data.Items.First().Count.Should().Be(4);
_results.Data.Items[0].Count.Should().Be(4);
}

[Fact]
Expand Down Expand Up @@ -158,7 +158,7 @@ public void UpdateAnItemWillChangedThegroup()
_results.Messages.First().Adds.Should().Be(1);
_results.Messages.Skip(1).First().Adds.Should().Be(1);
_results.Messages.Skip(1).First().Removes.Should().Be(1);
var group = _results.Data.Items.First();
var group = _results.Data.Items[0];
group.Count.Should().Be(1);

group.Key.Should().Be(21);
Expand All @@ -174,7 +174,7 @@ public void UpdatesArePermissible()
_results.Messages.First().Adds.Should().Be(1);
_results.Messages.Skip(1).First().Updates.Should().Be(1);

var group = _results.Data.Items.First();
var group = _results.Data.Items[0];
group.Count.Should().Be(2);
}
}
2 changes: 1 addition & 1 deletion src/DynamicData.Tests/Cache/GroupOnObservableFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void AllGroupsRemovedWhenCleared()
_cache.Clear();

// Assert
_cache.Items.Count().Should().Be(0);
_cache.Items.Count.Should().Be(0);
_results.Messages.Count.Should().Be(2, "1 for Adds and 1 for Removes");
_groupResults.Summary.Overall.Adds.Should().Be(colorCount);
_groupResults.Summary.Overall.Removes.Should().Be(colorCount);
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/GroupOnPropertyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void CanGroupOnAdds()

_results.Data.Count.Should().Be(1);

var firstGroup = _results.Data.Items.First();
var firstGroup = _results.Data.Items[0];

firstGroup.Cache.Count.Should().Be(1);
firstGroup.Key.Should().Be(10);
Expand Down Expand Up @@ -92,7 +92,7 @@ public void Regroup()
person.Age = 20;

_results.Data.Count.Should().Be(1);
var firstGroup = _results.Data.Items.First();
var firstGroup = _results.Data.Items[0];

firstGroup.Cache.Count.Should().Be(1);
firstGroup.Key.Should().Be(20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void CanGroupOnAdds()

_results.Data.Count.Should().Be(1);

var firstGroup = _results.Data.Items.First();
var firstGroup = _results.Data.Items[0];

firstGroup.Count.Should().Be(1);
firstGroup.Key.Should().Be(10);
Expand Down Expand Up @@ -93,7 +93,7 @@ public void Regroup()
person.Age = 20;

_results.Data.Count.Should().Be(1);
var firstGroup = _results.Data.Items.First();
var firstGroup = _results.Data.Items[0];

firstGroup.Count.Should().Be(1);
firstGroup.Key.Should().Be(20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,11 +806,11 @@ private void CheckResultContents(ChangeSetAggregator<IMarket, Guid> marketResult

// These should be subsets of each other
expectedMarkets.Should().BeSubsetOf(marketResults.Data.Items);
marketResults.Data.Items.Count().Should().Be(expectedMarkets.Count);
marketResults.Data.Items.Count.Should().Be(expectedMarkets.Count);

// These should be subsets of each other
expectedPrices.Should().BeSubsetOf(priceResults.Data.Items);
priceResults.Data.Items.Count().Should().Be(expectedPrices.Count);
priceResults.Data.Items.Count.Should().Be(expectedPrices.Count);
}

private void DisposeMarkets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ private void CheckResultContents(ChangeSetAggregator<IMarket, Guid> marketResult

// These should be subsets of each other
expectedMarkets.Should().BeSubsetOf(marketResults.Data.Items);
marketResults.Data.Items.Count().Should().Be(expectedMarkets.Count);
marketResults.Data.Items.Count.Should().Be(expectedMarkets.Count);

// Pair up all the Markets/Prices, Group them by ItemId, and sort each Group by the Market comparer
// Then pull out the first value from each group, which should be the price from the best market for each ItemId
Expand All @@ -1085,7 +1085,7 @@ private void CheckResultContents(ChangeSetAggregator<IMarket, Guid> marketResult

// These should be subsets of each other
expectedPrices.Should().BeSubsetOf(priceResults.Data.Items);
priceResults.Data.Items.Count().Should().Be(expectedPrices.Count);
priceResults.Data.Items.Count.Should().Be(expectedPrices.Count);
}

private void DisposeMarkets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private static void CheckResultContents(IEnumerable<AnimalOwner> owners, ChangeS

// These should be subsets of each other
expectedOwners.Should().BeSubsetOf(ownerResults.Data.Items);
ownerResults.Data.Items.Count().Should().Be(expectedOwners.Count);
ownerResults.Data.Items.Count.Should().Be(expectedOwners.Count);

// All owner animals should be in the results
foreach (var owner in owners)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void OnNextFiresAdd()

results.Messages.Count.Should().Be(1, "Should be 1 updates");
results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
results.Data.Items.First().Should().Be(person, "Should be same person");
results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand All @@ -141,7 +141,7 @@ public void OnNextForAmendedItemFiresUpdate()
results.Messages.Count.Should().Be(2, "Should be 2 message");
results.Messages[1].Updates.Should().Be(1, "Should be 1 updates");
results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
results.Data.Items.First().Should().Be(personamend, "Should be same person");
results.Data.Items[0].Should().Be(personamend, "Should be same person");
}

[Fact]
Expand All @@ -155,6 +155,6 @@ public void OnNextProducesAndAddChangeForSingleItem()

results.Messages.Count.Should().Be(1, "Should be 1 updates");
results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
results.Data.Items.First().Should().Be(person, "Should be same person");
results.Data.Items[0].Should().Be(person, "Should be same person");
}
}
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/OrFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void UpdatingBothProducesResultsAndDoesNotDuplicateTheMessage()
_source2.AddOrUpdate(person);
_results.Messages.Count.Should().Be(1, "Should have no updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand All @@ -81,7 +81,7 @@ public void UpdatingOneProducesOnlyOneUpdate()
_source2.AddOrUpdate(personUpdated);
_results.Messages.Count.Should().Be(2, "Should be 2 updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
_results.Data.Items.First().Should().Be(personUpdated, "Should be updated person");
_results.Data.Items[0].Should().Be(personUpdated, "Should be updated person");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/DynamicData.Tests/Cache/RightJoinManyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void AddLeftOnly()
_people.AddOrUpdate(people);

_result.Data.Count.Should().Be(1);
_result.Data.Items.First().Parent.Should().BeNull();
_result.Data.Items[0].Parent.Should().BeNull();
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicData.Tests/Cache/SizeLimitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Add()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand All @@ -53,7 +53,7 @@ public void AddLessThanLimit()

_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
_results.Data.Items.First().Should().Be(person, "Should be same person");
_results.Data.Items[0].Should().Be(person, "Should be same person");
}

[Fact]
Expand Down
Loading

0 comments on commit 3382f7f

Please sign in to comment.