1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 01:02:56 +08:00

Add test coverage of updating via copying changes from detached instance

This commit is contained in:
Dean Herbert 2022-01-12 12:56:42 +09:00
parent 580ad03f8d
commit a307f7e90e

View File

@ -80,6 +80,48 @@ namespace osu.Game.Tests.Database
});
}
[Test]
public void TestUpdateDetachedBeatmapSet()
{
RunTestWithRealmAsync(async (realmFactory, storage) =>
{
using (var importer = new BeatmapModelManager(realmFactory, storage))
using (new RulesetStore(realmFactory, storage))
{
ILive<BeatmapSetInfo>? beatmapSet;
using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
beatmapSet = await importer.Import(reader);
Assert.NotNull(beatmapSet);
Debug.Assert(beatmapSet != null);
BeatmapSetInfo? detachedBeatmapSet = null;
beatmapSet.PerformRead(s => detachedBeatmapSet = s.Detach());
Debug.Assert(detachedBeatmapSet != null);
var newUser = new RealmUser { Username = "peppy", OnlineID = 2 };
detachedBeatmapSet.Beatmaps.First().Metadata.Artist = "New Artist";
detachedBeatmapSet.Beatmaps.First().Metadata.Author = newUser;
Assert.AreNotEqual(detachedBeatmapSet.Status, BeatmapOnlineStatus.Ranked);
detachedBeatmapSet.Status = BeatmapOnlineStatus.Ranked;
beatmapSet.PerformWrite(s => detachedBeatmapSet.CopyChangesToRealm(s));
beatmapSet.PerformRead(s =>
{
Assert.AreEqual(BeatmapOnlineStatus.Ranked, s.Status);
Assert.AreEqual("New Artist", s.Beatmaps.First().Metadata.Artist);
Assert.AreEqual(newUser, s.Beatmaps.First().Metadata.Author);
});
}
});
}
[Test]
public void TestImportBeatmapThenCleanup()
{