diff --git a/osu.Game.Tests/Database/RealmLiveTests.cs b/osu.Game.Tests/Database/RealmLiveTests.cs index 33aa1afb89..41a81382f8 100644 --- a/osu.Game.Tests/Database/RealmLiveTests.cs +++ b/osu.Game.Tests/Database/RealmLiveTests.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading.Tasks; using NUnit.Framework; -using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Models; using Realms; @@ -18,15 +17,15 @@ namespace osu.Game.Tests.Database public class RealmLiveTests : RealmTest { [Test] - public void TestLiveCastability() + public void TestLiveEquality() { RunTestWithRealm((realmFactory, _) => { - RealmLive beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive(); + ILive beatmap = realmFactory.CreateContext().Write(r => r.Add(new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata()))).ToLive(); - ILive iBeatmap = beatmap; + ILive beatmap2 = realmFactory.CreateContext().All().First().ToLive(); - Assert.AreEqual(0, iBeatmap.Value.Length); + Assert.AreEqual(beatmap, beatmap2); }); } diff --git a/osu.Game/Database/EntityFrameworkLive.cs b/osu.Game/Database/EntityFrameworkLive.cs index 1d7b53911a..0fe8fea1ff 100644 --- a/osu.Game/Database/EntityFrameworkLive.cs +++ b/osu.Game/Database/EntityFrameworkLive.cs @@ -3,6 +3,8 @@ using System; +#nullable enable + namespace osu.Game.Database { public class EntityFrameworkLive : ILive where T : class @@ -30,5 +32,7 @@ public void PerformWrite(Action perform) } public T Value { get; } + + public bool Equals(ILive? other) => ID == other?.ID; } } diff --git a/osu.Game/Database/ILive.cs b/osu.Game/Database/ILive.cs index 9359b09eaf..ed2b926782 100644 --- a/osu.Game/Database/ILive.cs +++ b/osu.Game/Database/ILive.cs @@ -9,7 +9,8 @@ namespace osu.Game.Database /// A wrapper to provide access to database backed classes in a thread-safe manner. /// /// The databased type. - public interface ILive where T : class // TODO: Add IHasGuidPrimaryKey once we don't need EF support any more. + public interface ILive : IEquatable> + where T : class // TODO: Add IHasGuidPrimaryKey once we don't need EF support any more. { Guid ID { get; } diff --git a/osu.Game/Database/IPostImports.cs b/osu.Game/Database/IPostImports.cs index b3b83f23ef..adb3a7108d 100644 --- a/osu.Game/Database/IPostImports.cs +++ b/osu.Game/Database/IPostImports.cs @@ -8,7 +8,7 @@ namespace osu.Game.Database { - public interface IPostImports + public interface IPostImports where TModel : class { /// diff --git a/osu.Game/Database/RealmLive.cs b/osu.Game/Database/RealmLive.cs index abb69644d6..d988a81739 100644 --- a/osu.Game/Database/RealmLive.cs +++ b/osu.Game/Database/RealmLive.cs @@ -107,5 +107,7 @@ public T Value // this matches realm's internal thread validation (see https://github.com/realm/realm-dotnet/blob/903b4d0b304f887e37e2d905384fb572a6496e70/Realm/Realm/Native/SynchronizationContextScheduler.cs#L72) private bool isCorrectThread => (fetchedContext != null && SynchronizationContext.Current == fetchedContext) || fetchedThreadId == Thread.CurrentThread.ManagedThreadId; + + public bool Equals(ILive? other) => ID == other?.ID; } }