mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 16:32:54 +08:00
Add test coverage of proeprty changed subscriptions
This commit is contained in:
parent
cecc746f9e
commit
1485a3a28a
@ -47,6 +47,28 @@ namespace osu.Game.Tests.Database
|
||||
void onChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet? changes, Exception error) => lastChanges = changes;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPropertyChangedSubscription()
|
||||
{
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
bool? receivedValue = null;
|
||||
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
using (realm.SubscribeToPropertyChanged(r => r.All<BeatmapSetInfo>().First(), setInfo => setInfo.Protected, val => receivedValue = val))
|
||||
{
|
||||
Assert.That(receivedValue, Is.False);
|
||||
|
||||
realm.Write(r => r.All<BeatmapSetInfo>().First().Protected = true);
|
||||
|
||||
realm.Run(r => r.Refresh());
|
||||
|
||||
Assert.That(receivedValue, Is.True);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSubscriptionWithContextLoss()
|
||||
{
|
||||
@ -163,5 +185,41 @@ namespace osu.Game.Tests.Database
|
||||
Assert.That(beatmapSetInfo, Is.Null);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPropertyChangedSubscriptionWithContextLoss()
|
||||
{
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
bool? receivedValue = null;
|
||||
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
var subscription = realm.SubscribeToPropertyChanged(
|
||||
r => r.All<BeatmapSetInfo>().First(),
|
||||
setInfo => setInfo.Protected,
|
||||
val => receivedValue = val);
|
||||
|
||||
Assert.That(receivedValue, Is.Not.Null);
|
||||
receivedValue = null;
|
||||
|
||||
using (realm.BlockAllOperations())
|
||||
{
|
||||
}
|
||||
|
||||
// re-registration after context restore.
|
||||
realm.Run(r => r.Refresh());
|
||||
Assert.That(receivedValue, Is.Not.Null);
|
||||
|
||||
subscription.Dispose();
|
||||
receivedValue = null;
|
||||
|
||||
using (realm.BlockAllOperations())
|
||||
Assert.That(receivedValue, Is.Null);
|
||||
|
||||
realm.Run(r => r.Refresh());
|
||||
Assert.That(receivedValue, Is.Null);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user