mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +08:00
Add a test for realm preservation
This commit is contained in:
parent
edec613724
commit
f219c0886d
@ -9,8 +9,10 @@ using osu.Framework.Extensions;
|
||||
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 @@ namespace osu.Game.Tests.Beatmaps
|
||||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user