Add a test for realm preservation

This commit is contained in:
pfg 2022-10-09 10:19:21 -04:00
parent edec613724
commit f219c0886d
1 changed files with 36 additions and 0 deletions

View File

@ -9,8 +9,10 @@
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Collections;
using osu.Game.Database;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual;
@ -96,5 +98,39 @@ public void TestForcedRefetchRetrievalWithFiles() => AddStep("run test", () =>
var second = beatmaps.GetWorkingBeatmap(beatmap, true);
Assert.That(first, Is.Not.SameAs(second));
});
[Test]
public void TestSavePreservesCollections() => AddStep("run test", () =>
{
var beatmap = Realm.Run(r => r.Find<BeatmapInfo>(importedSet.Beatmaps.First().ID).Detach());
var map = beatmaps.GetWorkingBeatmap(beatmap);
Assert.That(map.BeatmapInfo.BeatmapSet?.Files, Has.Count.GreaterThan(0));
string initialHash = map.BeatmapInfo.MD5Hash;
var preserveCollection = new BeatmapCollection("test save preserves collection");
preserveCollection.BeatmapMD5Hashes.Add(initialHash);
var noNewCollection = new BeatmapCollection("test save does not introduce new collection");
Realm.Write(r =>
{
r.Add(preserveCollection);
r.Add(noNewCollection);
});
Assert.That(preserveCollection.BeatmapMD5Hashes, Does.Contain(initialHash));
Assert.That(noNewCollection.BeatmapMD5Hashes, Does.Not.Contain(initialHash));
beatmaps.Save(map.BeatmapInfo, map.GetPlayableBeatmap(new OsuRuleset().RulesetInfo));
string finalHash = map.BeatmapInfo.MD5Hash;
Assert.That(finalHash, Is.Not.SameAs(initialHash));
Assert.That(preserveCollection.BeatmapMD5Hashes, Does.Not.Contain(initialHash));
Assert.That(preserveCollection.BeatmapMD5Hashes, Does.Contain(finalHash));
Assert.That(noNewCollection.BeatmapMD5Hashes, Does.Not.Contain(finalHash));
});
}
}