mirror of https://github.com/ppy/osu
Add a test for realm preservation
This commit is contained in:
parent
edec613724
commit
f219c0886d
|
@ -9,8 +9,10 @@
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Collections;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
|
@ -96,5 +98,39 @@ public void TestForcedRefetchRetrievalWithFiles() => AddStep("run test", () =>
|
||||||
var second = beatmaps.GetWorkingBeatmap(beatmap, true);
|
var second = beatmaps.GetWorkingBeatmap(beatmap, true);
|
||||||
Assert.That(first, Is.Not.SameAs(second));
|
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