diff --git a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt index 55e3576c..0bf3dba9 100644 --- a/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt +++ b/src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt @@ -540,9 +540,9 @@ namespace DynamicData.Cache.Internal public LockFreeObservableCache(System.IObservable> source) { } public int Count { get; } public System.IObservable CountChanged { get; } - public System.Collections.Generic.IEnumerable Items { get; } - public System.Collections.Generic.IEnumerable> KeyValues { get; } - public System.Collections.Generic.IEnumerable Keys { get; } + public System.Collections.Generic.IReadOnlyList Items { get; } + public System.Collections.Generic.IReadOnlyDictionary KeyValues { get; } + public System.Collections.Generic.IReadOnlyList Keys { get; } public System.IObservable> Connect(System.Func? predicate = null, bool suppressEmptyChangeSets = true) { } public void Dispose() { } public void Edit(System.Action> editAction) { } @@ -874,9 +874,9 @@ namespace DynamicData where TKey : notnull { int Count { get; } - System.Collections.Generic.IEnumerable Items { get; } - System.Collections.Generic.IEnumerable> KeyValues { get; } - System.Collections.Generic.IEnumerable Keys { get; } + System.Collections.Generic.IReadOnlyList Items { get; } + System.Collections.Generic.IReadOnlyDictionary KeyValues { get; } + System.Collections.Generic.IReadOnlyList Keys { get; } DynamicData.Kernel.Optional Lookup(TKey key); } public interface IObservableList : System.IDisposable @@ -993,9 +993,9 @@ namespace DynamicData public IntermediateCache(System.IObservable> source) { } public int Count { get; } public System.IObservable CountChanged { get; } - public System.Collections.Generic.IEnumerable Items { get; } - public System.Collections.Generic.IEnumerable> KeyValues { get; } - public System.Collections.Generic.IEnumerable Keys { get; } + public System.Collections.Generic.IReadOnlyList Items { get; } + public System.Collections.Generic.IReadOnlyDictionary KeyValues { get; } + public System.Collections.Generic.IReadOnlyList Keys { get; } public System.IObservable> Connect(System.Func? predicate = null, bool suppressEmptyChangeSets = true) { } public void Dispose() { } public void Edit(System.Action> updateAction) { } @@ -2610,10 +2610,10 @@ namespace DynamicData public SourceCache(System.Func keySelector) { } public int Count { get; } public System.IObservable CountChanged { get; } - public System.Collections.Generic.IEnumerable Items { get; } + public System.Collections.Generic.IReadOnlyList Items { get; } public System.Func KeySelector { get; } - public System.Collections.Generic.IEnumerable> KeyValues { get; } - public System.Collections.Generic.IEnumerable Keys { get; } + public System.Collections.Generic.IReadOnlyDictionary KeyValues { get; } + public System.Collections.Generic.IReadOnlyList Keys { get; } public System.IObservable> Connect(System.Func? predicate = null, bool suppressEmptyChangeSets = true) { } public void Dispose() { } public void Edit(System.Action> updateAction) { } diff --git a/src/DynamicData.Tests/Cache/AndFixture.cs b/src/DynamicData.Tests/Cache/AndFixture.cs index 9b447f20..0f0ec2ad 100644 --- a/src/DynamicData.Tests/Cache/AndFixture.cs +++ b/src/DynamicData.Tests/Cache/AndFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/DisposeManyFixture.cs b/src/DynamicData.Tests/Cache/DisposeManyFixture.cs index b15be5a6..b196e143 100644 --- a/src/DynamicData.Tests/Cache/DisposeManyFixture.cs +++ b/src/DynamicData.Tests/Cache/DisposeManyFixture.cs @@ -99,14 +99,14 @@ public void ItemsAreDisposedAfterRemovalOrReplacement() { new Change( 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() // Move { new Change( - key: _itemsSource.Items.First().Id, - current: _itemsSource.Items.First(), + key: _itemsSource.Items[0].Id, + current: _itemsSource.Items[0], currentIndex: 1, previousIndex: 0) }); diff --git a/src/DynamicData.Tests/Cache/DistinctFixture.cs b/src/DynamicData.Tests/Cache/DistinctFixture.cs index 0363c0c5..fbbd36c7 100644 --- a/src/DynamicData.Tests/Cache/DistinctFixture.cs +++ b/src/DynamicData.Tests/Cache/DistinctFixture.cs @@ -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] @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/DynamicAndFixture.cs b/src/DynamicData.Tests/Cache/DynamicAndFixture.cs index 6793616a..c9b79b54 100644 --- a/src/DynamicData.Tests/Cache/DynamicAndFixture.cs +++ b/src/DynamicData.Tests/Cache/DynamicAndFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/DynamicOrFixture.cs b/src/DynamicData.Tests/Cache/DynamicOrFixture.cs index 7b1b1005..d02c3764 100644 --- a/src/DynamicData.Tests/Cache/DynamicOrFixture.cs +++ b/src/DynamicData.Tests/Cache/DynamicOrFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/FilterControllerFixture.cs b/src/DynamicData.Tests/Cache/FilterControllerFixture.cs index 291ee700..ebe07324 100644 --- a/src/DynamicData.Tests/Cache/FilterControllerFixture.cs +++ b/src/DynamicData.Tests/Cache/FilterControllerFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/FilterFixture.cs b/src/DynamicData.Tests/Cache/FilterFixture.cs index 886ba188..9e901c8c 100644 --- a/src/DynamicData.Tests/Cache/FilterFixture.cs +++ b/src/DynamicData.Tests/Cache/FilterFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/FilterParallelFixture.cs b/src/DynamicData.Tests/Cache/FilterParallelFixture.cs index 14e7ed82..bc141168 100644 --- a/src/DynamicData.Tests/Cache/FilterParallelFixture.cs +++ b/src/DynamicData.Tests/Cache/FilterParallelFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/GroupImmutableFixture.cs b/src/DynamicData.Tests/Cache/GroupImmutableFixture.cs index 0ad2d5c6..8640bccb 100644 --- a/src/DynamicData.Tests/Cache/GroupImmutableFixture.cs +++ b/src/DynamicData.Tests/Cache/GroupImmutableFixture.cs @@ -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] @@ -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); @@ -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); } } diff --git a/src/DynamicData.Tests/Cache/GroupOnObservableFixture.cs b/src/DynamicData.Tests/Cache/GroupOnObservableFixture.cs index 9c2fea74..3e8dd885 100644 --- a/src/DynamicData.Tests/Cache/GroupOnObservableFixture.cs +++ b/src/DynamicData.Tests/Cache/GroupOnObservableFixture.cs @@ -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); diff --git a/src/DynamicData.Tests/Cache/GroupOnPropertyFixture.cs b/src/DynamicData.Tests/Cache/GroupOnPropertyFixture.cs index 89c84e8f..7af36211 100644 --- a/src/DynamicData.Tests/Cache/GroupOnPropertyFixture.cs +++ b/src/DynamicData.Tests/Cache/GroupOnPropertyFixture.cs @@ -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); @@ -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); diff --git a/src/DynamicData.Tests/Cache/GroupOnPropertyWithImmutableStateFixture.cs b/src/DynamicData.Tests/Cache/GroupOnPropertyWithImmutableStateFixture.cs index 90ceb665..2321b6e3 100644 --- a/src/DynamicData.Tests/Cache/GroupOnPropertyWithImmutableStateFixture.cs +++ b/src/DynamicData.Tests/Cache/GroupOnPropertyWithImmutableStateFixture.cs @@ -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); @@ -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); diff --git a/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheFixture.cs b/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheFixture.cs index 2dbc77f9..9d63b5b7 100644 --- a/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheFixture.cs +++ b/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheFixture.cs @@ -806,11 +806,11 @@ private void CheckResultContents(ChangeSetAggregator 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() diff --git a/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheSourceCompareFixture.cs b/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheSourceCompareFixture.cs index 98f6da4d..152cfe9e 100644 --- a/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheSourceCompareFixture.cs +++ b/src/DynamicData.Tests/Cache/MergeManyChangeSetsCacheSourceCompareFixture.cs @@ -1074,7 +1074,7 @@ private void CheckResultContents(ChangeSetAggregator 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 @@ -1085,7 +1085,7 @@ private void CheckResultContents(ChangeSetAggregator 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() diff --git a/src/DynamicData.Tests/Cache/MergeManyChangeSetsListFixture.cs b/src/DynamicData.Tests/Cache/MergeManyChangeSetsListFixture.cs index 1813b23e..f7a4aa2a 100644 --- a/src/DynamicData.Tests/Cache/MergeManyChangeSetsListFixture.cs +++ b/src/DynamicData.Tests/Cache/MergeManyChangeSetsListFixture.cs @@ -459,7 +459,7 @@ private static void CheckResultContents(IEnumerable 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) diff --git a/src/DynamicData.Tests/Cache/ObservableToObservableChangeSetFixture.cs b/src/DynamicData.Tests/Cache/ObservableToObservableChangeSetFixture.cs index a750a008..d4e6ce03 100644 --- a/src/DynamicData.Tests/Cache/ObservableToObservableChangeSetFixture.cs +++ b/src/DynamicData.Tests/Cache/ObservableToObservableChangeSetFixture.cs @@ -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] @@ -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] @@ -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"); } } diff --git a/src/DynamicData.Tests/Cache/OrFixture.cs b/src/DynamicData.Tests/Cache/OrFixture.cs index 809d34dc..720d3f0b 100644 --- a/src/DynamicData.Tests/Cache/OrFixture.cs +++ b/src/DynamicData.Tests/Cache/OrFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/RightJoinManyFixture.cs b/src/DynamicData.Tests/Cache/RightJoinManyFixture.cs index 6f3c63bc..0f8dc894 100644 --- a/src/DynamicData.Tests/Cache/RightJoinManyFixture.cs +++ b/src/DynamicData.Tests/Cache/RightJoinManyFixture.cs @@ -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] diff --git a/src/DynamicData.Tests/Cache/SizeLimitFixture.cs b/src/DynamicData.Tests/Cache/SizeLimitFixture.cs index 2de5c165..bbc67f04 100644 --- a/src/DynamicData.Tests/Cache/SizeLimitFixture.cs +++ b/src/DynamicData.Tests/Cache/SizeLimitFixture.cs @@ -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] @@ -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] diff --git a/src/DynamicData.Tests/Cache/SortAndBindFixture.cs b/src/DynamicData.Tests/Cache/SortAndBindFixture.cs index 723a39cd..db254be1 100644 --- a/src/DynamicData.Tests/Cache/SortAndBindFixture.cs +++ b/src/DynamicData.Tests/Cache/SortAndBindFixture.cs @@ -13,6 +13,19 @@ namespace DynamicData.Tests.Cache; +// Bind to a list +public sealed class SortByAndBindToList : SortAndBindFixture + +{ + protected override (ChangeSetAggregator Aggregrator, IList List) SetUpTests() + { + var list = new List(100); + var aggregator = _source.Connect().SortAndBind(list, _comparer).AsAggregator(); + + return (aggregator, list); + } +} + // Bind to a list public sealed class SortAndBindToList: SortAndBindFixture diff --git a/src/DynamicData.Tests/Cache/SubscribeManyFixture.cs b/src/DynamicData.Tests/Cache/SubscribeManyFixture.cs index 7e8423eb..5d6d2672 100644 --- a/src/DynamicData.Tests/Cache/SubscribeManyFixture.cs +++ b/src/DynamicData.Tests/Cache/SubscribeManyFixture.cs @@ -33,7 +33,7 @@ public void AddedItemWillbeSubscribed() _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().IsSubscribed.Should().Be(true, "Should be subscribed"); + _results.Data.Items[0].IsSubscribed.Should().Be(true, "Should be subscribed"); } public void Dispose() diff --git a/src/DynamicData.Tests/Cache/TransformAsyncFixture.cs b/src/DynamicData.Tests/Cache/TransformAsyncFixture.cs index a8c4c3b0..a40356f4 100644 --- a/src/DynamicData.Tests/Cache/TransformAsyncFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformAsyncFixture.cs @@ -26,7 +26,7 @@ public async Task Add() var firstPerson = await stub.TransformFactory(person); - stub.Results.Data.Items.First().Should().Be(firstPerson, "Should be same person"); + stub.Results.Data.Items[0].Should().Be(firstPerson, "Should be same person"); } [Fact] @@ -183,7 +183,7 @@ public async Task SameKeyChanges() stub.Results.Data.Count.Should().Be(1, "Should result in 1 record"); var lastTransformed = await stub.TransformFactory(people.Last()); - var onlyItemInCache = stub.Results.Data.Items.First(); + var onlyItemInCache = stub.Results.Data.Items[0]; onlyItemInCache.Should().Be(lastTransformed, "Incorrect transform result"); } diff --git a/src/DynamicData.Tests/Cache/TransformFixture.cs b/src/DynamicData.Tests/Cache/TransformFixture.cs index 89fa079b..d149276c 100644 --- a/src/DynamicData.Tests/Cache/TransformFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformFixture.cs @@ -22,7 +22,7 @@ public void Add() stub.Results.Messages.Count.Should().Be(1, "Should be 1 updates"); stub.Results.Data.Count.Should().Be(1, "Should be 1 item in the cache"); - stub.Results.Data.Items.First().Should().Be(stub.TransformFactory(person), "Should be same person"); + stub.Results.Data.Items[0].Should().Be(stub.TransformFactory(person), "Should be same person"); } [Fact] @@ -130,7 +130,7 @@ public void SameKeyChanges() stub.Results.Data.Count.Should().Be(1, "Should result in 1 record"); var lastTransformed = stub.TransformFactory(people.Last()); - var onlyItemInCache = stub.Results.Data.Items.First(); + var onlyItemInCache = stub.Results.Data.Items[0]; onlyItemInCache.Should().Be(lastTransformed, "Incorrect transform result"); } diff --git a/src/DynamicData.Tests/Cache/TransformFixtureParallel.cs b/src/DynamicData.Tests/Cache/TransformFixtureParallel.cs index 1f61a7d7..5ff66a0d 100644 --- a/src/DynamicData.Tests/Cache/TransformFixtureParallel.cs +++ b/src/DynamicData.Tests/Cache/TransformFixtureParallel.cs @@ -38,7 +38,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(_transformFactory(person), "Should be same person"); + _results.Data.Items[0].Should().Be(_transformFactory(person), "Should be same person"); } [Fact] @@ -104,7 +104,7 @@ public void SameKeyChanges() _results.Data.Count.Should().Be(1, "Should result in 1 record"); var lastTransformed = _transformFactory(people.Last()); - var onlyItemInCache = _results.Data.Items.First(); + var onlyItemInCache = _results.Data.Items[0]; // TODO: This is not producing consitent results, the lastTransformed item should be equal to the onlyItemInCache onlyItemInCache.Should().Be(lastTransformed, "Incorrect transform result"); diff --git a/src/DynamicData.Tests/Cache/TransformManyAsyncFixture.cs b/src/DynamicData.Tests/Cache/TransformManyAsyncFixture.cs index c426ef1f..3781b1a2 100644 --- a/src/DynamicData.Tests/Cache/TransformManyAsyncFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformManyAsyncFixture.cs @@ -231,7 +231,7 @@ private static void CheckResultContents(IEnumerable owners, Chan // 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); var allAnimals = expectedOwners.SelectMany(owner => owner.Animals.Items).ToList(); var expectedAnimals = allAnimals.GroupBy(keySelector).Select(group => group.OrderBy(a => a, comparer).First()).ToList(); @@ -247,7 +247,7 @@ private static void CheckResultContents(IEnumerable owners, Chan // 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) diff --git a/src/DynamicData.Tests/Cache/TransformSafeAsyncFixture.cs b/src/DynamicData.Tests/Cache/TransformSafeAsyncFixture.cs index 9221bd1b..6c1f34ef 100644 --- a/src/DynamicData.Tests/Cache/TransformSafeAsyncFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformSafeAsyncFixture.cs @@ -72,7 +72,7 @@ public async Task Add() var firstPerson = await stub.TransformFactory(person); - stub.Results.Data.Items.First().Should().Be(firstPerson, "Should be same person"); + stub.Results.Data.Items[0].Should().Be(firstPerson, "Should be same person"); } [Fact] @@ -139,7 +139,7 @@ public async Task SameKeyChanges() stub.Results.Data.Count.Should().Be(1, "Should result in 1 record"); var lastTransformed = await stub.TransformFactory(people.Last()); - var onlyItemInCache = stub.Results.Data.Items.First(); + var onlyItemInCache = stub.Results.Data.Items[0]; onlyItemInCache.Should().Be(lastTransformed, "Incorrect transform result"); } diff --git a/src/DynamicData.Tests/Cache/TransformSafeFixture.cs b/src/DynamicData.Tests/Cache/TransformSafeFixture.cs index 1f31ec84..cd9aabc7 100644 --- a/src/DynamicData.Tests/Cache/TransformSafeFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformSafeFixture.cs @@ -57,7 +57,7 @@ public void AddWithNoError() _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(_transformFactory(person), "Should be same person"); + _results.Data.Items[0].Should().Be(_transformFactory(person), "Should be same person"); } public void Dispose() @@ -86,7 +86,7 @@ public void UpdateBatch() _results.Messages.Count.Should().Be(1, "Should be 1 messages"); _results.Data.Count.Should().Be(1, "Should 1 item in the cache"); - _results.Data.Items.First().Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); + _results.Data.Items[0].Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); } [Fact] @@ -121,6 +121,6 @@ public void UpdateSucessively() _results.Messages.Count.Should().Be(3, "Should be 3 messages"); _results.Data.Count.Should().Be(1, "Should 1 item in the cache"); - _results.Data.Items.First().Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); + _results.Data.Items[0].Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); } } diff --git a/src/DynamicData.Tests/Cache/TransformSafeParallelFixture.cs b/src/DynamicData.Tests/Cache/TransformSafeParallelFixture.cs index a344e09f..dace5e75 100644 --- a/src/DynamicData.Tests/Cache/TransformSafeParallelFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformSafeParallelFixture.cs @@ -57,7 +57,7 @@ public void AddWithNoError() _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(_transformFactory(person), "Should be same person"); + _results.Data.Items[0].Should().Be(_transformFactory(person), "Should be same person"); } public void Dispose() @@ -86,7 +86,7 @@ public void UpdateBatch() _results.Messages.Count.Should().Be(1, "Should be 1 messages"); _results.Data.Count.Should().Be(1, "Should 1 item in the cache"); - _results.Data.Items.First().Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); + _results.Data.Items[0].Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); } [Fact] @@ -121,6 +121,6 @@ public void UpdateSucessively() _results.Messages.Count.Should().Be(3, "Should be 3 messages"); _results.Data.Count.Should().Be(1, "Should 1 item in the cache"); - _results.Data.Items.First().Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); + _results.Data.Items[0].Should().Be(_transformFactory(update2), "Change 2 shoud be the only item cached"); } } diff --git a/src/DynamicData.Tests/Cache/TransformTreeFixture.cs b/src/DynamicData.Tests/Cache/TransformTreeFixture.cs index e24bb4fb..33bf4457 100644 --- a/src/DynamicData.Tests/Cache/TransformTreeFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformTreeFixture.cs @@ -36,10 +36,10 @@ public void AddMissingChild() _result.Count.Should().Be(1); - var firstNode = _result.Items.First(); + var firstNode = _result.Items[0]; firstNode.Item.Should().Be(boss); - var childNode = firstNode.Children.Items.First(); + var childNode = firstNode.Children.Items[0]; childNode.Item.Should().Be(minion); } @@ -81,7 +81,7 @@ public void BuildTreeFromMixedData() _sourceCache.AddOrUpdate(TransformTreeFixture.CreateEmployees()); _result.Count.Should().Be(2); - var firstNode = _result.Items.First(); + var firstNode = _result.Items[0]; firstNode.Children.Count.Should().Be(3); var secondNode = _result.Items.Skip(1).First(); @@ -157,7 +157,7 @@ public void UpdateAParentNode() _sourceCache.AddOrUpdate(changed); _result.Count.Should().Be(2); - var firstNode = _result.Items.First(); + var firstNode = _result.Items[0]; firstNode.Children.Count.Should().Be(3); firstNode.Item.Name.Should().Be(changed.Name); } @@ -176,7 +176,7 @@ public void UpdateChildNode() _sourceCache.AddOrUpdate(changed); _result.Count.Should().Be(2); - var changedNode = _result.Items.First().Children.Items.First(); + var changedNode = _result.Items[0].Children.Items[0]; changedNode.Parent.Value.Item.Id.Should().Be(1); changedNode.Children.Count.Should().Be(1); diff --git a/src/DynamicData.Tests/Cache/TransformWithInlineUpdateFixture.cs b/src/DynamicData.Tests/Cache/TransformWithInlineUpdateFixture.cs index 88249e34..0be034a1 100644 --- a/src/DynamicData.Tests/Cache/TransformWithInlineUpdateFixture.cs +++ b/src/DynamicData.Tests/Cache/TransformWithInlineUpdateFixture.cs @@ -17,17 +17,17 @@ public void InlineUpdate() var person = new Person("Adult1", 50); stub.Source.AddOrUpdate(person); - var transformedPerson = stub.Results.Data.Items.First(); + var transformedPerson = stub.Results.Data.Items[0]; var personUpdate = new Person("Adult1", 51); stub.Source.AddOrUpdate(personUpdate); - var updatedTransform = stub.Results.Data.Items.First(); + var updatedTransform = stub.Results.Data.Items[0]; updatedTransform.Age.Should().Be(personUpdate.Age, "Age should be updated from 50 to 51."); stub.Results.Messages.Count.Should().Be(2, "Should be 2 updates"); stub.Results.Data.Count.Should().Be(1, "Should be 1 item in the cache"); - transformedPerson.Should().Be(stub.Results.Data.Items.First(), "Should be same transformed person instance."); + transformedPerson.Should().Be(stub.Results.Data.Items[0], "Should be same transformed person instance."); } [Fact] @@ -84,17 +84,17 @@ public void TransformOnRefresh() var person = new Person("Adult1", 50); stub.Source.AddOrUpdate(person); - var transformedPerson = stub.Results.Data.Items.First(); + var transformedPerson = stub.Results.Data.Items[0]; person.Age = 51; stub.Source.Refresh(person); - var updatedTransform = stub.Results.Data.Items.First(); + var updatedTransform = stub.Results.Data.Items[0]; updatedTransform.Age.Should().Be(51, "Age should be updated from 50 to 51."); stub.Results.Messages.Count.Should().Be(2, "Should be 2 updates"); stub.Results.Data.Count.Should().Be(1, "Should be 1 item in the cache"); - transformedPerson.Should().Be(stub.Results.Data.Items.First(), "Should be same transformed person instance."); + transformedPerson.Should().Be(stub.Results.Data.Items[0], "Should be same transformed person instance."); } private class TransformWithInlineUpdateFixtureStub : IDisposable diff --git a/src/DynamicData.Tests/Cache/WatchFixture.cs b/src/DynamicData.Tests/Cache/WatchFixture.cs index 9064cd28..6cc1116b 100644 --- a/src/DynamicData.Tests/Cache/WatchFixture.cs +++ b/src/DynamicData.Tests/Cache/WatchFixture.cs @@ -26,7 +26,7 @@ public void AddWillNotCallDispose() _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().IsDisposed.Should().Be(false, "Should not be disposed"); + _results.Data.Items[0].IsDisposed.Should().Be(false, "Should not be disposed"); } public void Dispose() diff --git a/src/DynamicData.Tests/Cache/WatcherFixture.cs b/src/DynamicData.Tests/Cache/WatcherFixture.cs index 8fde8909..23faff11 100644 --- a/src/DynamicData.Tests/Cache/WatcherFixture.cs +++ b/src/DynamicData.Tests/Cache/WatcherFixture.cs @@ -57,7 +57,7 @@ public void AddNew() _results.Data.Count.Should().Be(1, "Should be 1 item in the cache"); _scheduler.AdvanceBy(TimeSpan.FromMilliseconds(50).Ticks); - var result = _results.Data.Items.First(); + var result = _results.Data.Items[0]; result.UpdateCount.Should().Be(1, "Person should have received 1 update"); result.Completed.Should().Be(false, "Person should have received 1 update"); } diff --git a/src/DynamicData.Tests/List/MergeManyChangeSetsCacheFixture.cs b/src/DynamicData.Tests/List/MergeManyChangeSetsCacheFixture.cs index 547dd1eb..bdac643d 100644 --- a/src/DynamicData.Tests/List/MergeManyChangeSetsCacheFixture.cs +++ b/src/DynamicData.Tests/List/MergeManyChangeSetsCacheFixture.cs @@ -835,7 +835,7 @@ private void CheckResultContents(ChangeSetAggregator marketResults, Cha // 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() diff --git a/src/DynamicData.Tests/Utilities/TestSourceCache.cs b/src/DynamicData.Tests/Utilities/TestSourceCache.cs index f08be159..30fe327d 100644 --- a/src/DynamicData.Tests/Utilities/TestSourceCache.cs +++ b/src/DynamicData.Tests/Utilities/TestSourceCache.cs @@ -32,17 +32,17 @@ public int Count public IObservable CountChanged => _countChanged; - public IEnumerable Items + public IReadOnlyList Items => _source.Items; - public IEnumerable Keys + public IReadOnlyList Keys => _source.Keys; public Func KeySelector => _source.KeySelector; - public IEnumerable> KeyValues - => KeyValues; + public IReadOnlyDictionary KeyValues + => _source.KeyValues; public void Complete() { diff --git a/src/DynamicData/Cache/ChangeAwareCache.cs b/src/DynamicData/Cache/ChangeAwareCache.cs index 9dc98086..65fd131f 100644 --- a/src/DynamicData/Cache/ChangeAwareCache.cs +++ b/src/DynamicData/Cache/ChangeAwareCache.cs @@ -63,6 +63,8 @@ public ChangeAwareCache(Dictionary data) /// public IEnumerable> KeyValues => _data; + internal Dictionary GetDictionary() => _data; + /// /// Adds the item to the cache without checking whether there is an existing value in the cache. /// diff --git a/src/DynamicData/Cache/IObservableCache.cs b/src/DynamicData/Cache/IObservableCache.cs index 1ffb3e18..aaa73fcb 100644 --- a/src/DynamicData/Cache/IObservableCache.cs +++ b/src/DynamicData/Cache/IObservableCache.cs @@ -24,17 +24,17 @@ public interface IObservableCache : IConnectableCache /// Gets the Items. /// - IEnumerable Items { get; } + IReadOnlyList Items { get; } /// /// Gets the keys. /// - IEnumerable Keys { get; } + IReadOnlyList Keys { get; } /// /// Gets the key value pairs. /// - IEnumerable> KeyValues { get; } + IReadOnlyDictionary KeyValues { get; } /// /// Lookup a single item using the specified key. diff --git a/src/DynamicData/Cache/IntermediateCache.cs b/src/DynamicData/Cache/IntermediateCache.cs index 6125c9cd..3e77eff4 100644 --- a/src/DynamicData/Cache/IntermediateCache.cs +++ b/src/DynamicData/Cache/IntermediateCache.cs @@ -46,13 +46,13 @@ public IntermediateCache(IObservable> source) public IObservable CountChanged => _innerCache.CountChanged; /// - public IEnumerable Items => _innerCache.Items; + public IReadOnlyList Items => _innerCache.Items; /// - public IEnumerable Keys => _innerCache.Keys; + public IReadOnlyList Keys => _innerCache.Keys; /// - public IEnumerable> KeyValues => _innerCache.KeyValues; + public IReadOnlyDictionary KeyValues => _innerCache.KeyValues; /// public IObservable> Connect(Func? predicate = null, bool suppressEmptyChangeSets = true) diff --git a/src/DynamicData/Cache/Internal/AnonymousObservableCache.cs b/src/DynamicData/Cache/Internal/AnonymousObservableCache.cs index 5f4e49fe..c7f52e59 100644 --- a/src/DynamicData/Cache/Internal/AnonymousObservableCache.cs +++ b/src/DynamicData/Cache/Internal/AnonymousObservableCache.cs @@ -37,11 +37,11 @@ public AnonymousObservableCache(IObservableCache cache) public IObservable CountChanged => _cache.CountChanged; - public IEnumerable Items => _cache.Items; + public IReadOnlyList Items => _cache.Items; - public IEnumerable Keys => _cache.Keys; + public IReadOnlyList Keys => _cache.Keys; - public IEnumerable> KeyValues => _cache.KeyValues; + public IReadOnlyDictionary KeyValues => _cache.KeyValues; public IObservable> Connect(Func? predicate = null, bool suppressEmptyChangeSets = true) => _cache.Connect(predicate, suppressEmptyChangeSets); diff --git a/src/DynamicData/Cache/Internal/LockFreeObservableCache.cs b/src/DynamicData/Cache/Internal/LockFreeObservableCache.cs index 6c468bb8..5e48a6b5 100644 --- a/src/DynamicData/Cache/Internal/LockFreeObservableCache.cs +++ b/src/DynamicData/Cache/Internal/LockFreeObservableCache.cs @@ -84,13 +84,13 @@ public LockFreeObservableCache() public IObservable CountChanged => _countChanged.StartWith(_innerCache.Count).DistinctUntilChanged(); /// - public IEnumerable Items => _innerCache.Items; + public IReadOnlyList Items => _innerCache.Items.ToArray(); /// - public IEnumerable Keys => _innerCache.Keys; + public IReadOnlyList Keys => _innerCache.Keys.ToArray(); /// - public IEnumerable> KeyValues => _innerCache.KeyValues; + public IReadOnlyDictionary KeyValues => new Dictionary(_innerCache.GetDictionary()); /// public IObservable> Connect(Func? predicate = null, bool suppressEmptyChangeSets = true) => Observable.Defer( diff --git a/src/DynamicData/Cache/Internal/ReaderWriter.cs b/src/DynamicData/Cache/Internal/ReaderWriter.cs index 2ce81f3b..f7a0debf 100644 --- a/src/DynamicData/Cache/Internal/ReaderWriter.cs +++ b/src/DynamicData/Cache/Internal/ReaderWriter.cs @@ -49,13 +49,13 @@ public TKey[] Keys } } - public KeyValuePair[] KeyValues + public IReadOnlyDictionary KeyValues { get { lock (_locker) { - return [.. _data]; + return new Dictionary(_data); } } } diff --git a/src/DynamicData/Cache/ObservableCache.cs b/src/DynamicData/Cache/ObservableCache.cs index dc09600b..0ef8fc1c 100644 --- a/src/DynamicData/Cache/ObservableCache.cs +++ b/src/DynamicData/Cache/ObservableCache.cs @@ -115,11 +115,11 @@ public ObservableCache(Func? keySelector = null) } }); - public IEnumerable Items => _readerWriter.Items; + public IReadOnlyList Items => _readerWriter.Items; - public IEnumerable Keys => _readerWriter.Keys; + public IReadOnlyList Keys => _readerWriter.Keys; - public IEnumerable> KeyValues => _readerWriter.KeyValues; + public IReadOnlyDictionary KeyValues => _readerWriter.KeyValues; public IObservable> Connect(Func? predicate = null, bool suppressEmptyChangeSets = true) => Observable.Create>(observer => diff --git a/src/DynamicData/Cache/SourceCache.cs b/src/DynamicData/Cache/SourceCache.cs index 7959a0bf..8d720cba 100644 --- a/src/DynamicData/Cache/SourceCache.cs +++ b/src/DynamicData/Cache/SourceCache.cs @@ -34,16 +34,16 @@ public sealed class SourceCache(Func keySelector) public IObservable CountChanged => _innerCache.CountChanged; /// - public IEnumerable Items => _innerCache.Items; + public IReadOnlyList Items => _innerCache.Items; /// - public IEnumerable Keys => _innerCache.Keys; + public IReadOnlyList Keys => _innerCache.Keys; /// public Func KeySelector { get; } = keySelector ?? throw new ArgumentNullException(nameof(keySelector)); /// - public IEnumerable> KeyValues => _innerCache.KeyValues; + public IReadOnlyDictionary KeyValues => _innerCache.KeyValues; /// public IObservable> Connect(Func? predicate = null, bool suppressEmptyChangeSets = true) => _innerCache.Connect(predicate, suppressEmptyChangeSets);