Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Xunit;

using DynamicData.Kernel;
using DynamicData.Tests.Utilities;

namespace DynamicData.Tests.Cache;

Expand Down Expand Up @@ -46,6 +47,41 @@ public void NotificationsCanBeSuspended()
_results.IsCompleted.Should().BeFalse("IsCompleted should not have fired");
}

// https://github.com/reactivemarbles/DynamicData/issues/1136
[Fact]
public void SuspendedConnectCompletesCorrectly()
{
using var source = new SourceCache<int, int>(static item => item);

using var suspension = source.SuspendNotifications();

source.AddOrUpdate(1);

using var subscription = source.Connect()
.RecordCacheItems(out var results);

results.Error.Should().BeNull("no errors should have occurred");
results.RecordedChangeSets.Should().BeEmpty("notifications should have been suspended");

suspension.Dispose();

results.Error.Should().BeNull("no errors should have occurred");
results.RecordedChangeSets.Should().ContainSingle("notifications should have been resumed");
results.RecordedItemsByKey.Should().BeEquivalentTo(source.KeyValues, "all changes should have propagated to the new subscriber");

source.AddOrUpdate(2);

results.Error.Should().BeNull("no errors should have occurred");
results.RecordedChangeSets.Skip(1).Count().Should().Be(1, "a single additional source operation was performed");
results.RecordedItemsByKey.Should().BeEquivalentTo(source.KeyValues, "all changes should have propagated to the new subscriber");

source.Dispose();

results.Error.Should().BeNull("no errors should have occurred");
results.RecordedChangeSets.Skip(2).Should().BeEmpty("no additional source operations were performed");
results.HasCompleted.Should().BeTrue("the source has been disposed");
}

[Fact]
public void SuspendingNotificationsDoesNotImpactPreview()
{
Expand Down Expand Up @@ -512,22 +548,6 @@ public void OnErrorFiresIfCacheFailsAfterResumingWhileConnectionWasSuspended()
results.Data.Count.Should().Be(1, "the data written before the failure should have arrived");
}

[Fact]
public void OnCompletedFiresIfCacheDisposedAfterResumingWhileWatchWasSuspended()
{
// The tests above cover failure. Completion has to reach an activated watch too, and
// this covers the path through the watch itself rather than through the suspension gate.
var suspend = _source.SuspendNotifications();
var isCompleted = false;
using var subscription = _source.Watch(1).Subscribe(static _ => { }, () => isCompleted = true);
_source.AddOrUpdate(1);

suspend.Dispose();
_source.Dispose();

isCompleted.Should().BeTrue("a watch deferred by a suspension should still complete when the source does");
}

public void Dispose()
{
_source.Dispose();
Expand Down
1 change: 0 additions & 1 deletion src/DynamicData.Tests/Cache/SuspendNotificationsFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
namespace DynamicData.Tests.Cache;

public static partial class SuspendNotificationsFixture;

Loading