mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:03:21 +08:00
Add test for deleting then reimporting
This commit is contained in:
parent
a166932468
commit
8140ffea15
@ -71,6 +71,45 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestImportThenDeleteThenImport()
|
||||||
|
{
|
||||||
|
//unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here.
|
||||||
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost("TestImportThenDeleteThenImport"))
|
||||||
|
{
|
||||||
|
var osu = loadOsu(host);
|
||||||
|
|
||||||
|
var temp = prepareTempCopy(osz_path);
|
||||||
|
Assert.IsTrue(File.Exists(temp));
|
||||||
|
|
||||||
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
|
var imported = manager.Import(temp);
|
||||||
|
|
||||||
|
ensureLoaded(osu);
|
||||||
|
|
||||||
|
manager.Delete(imported.First());
|
||||||
|
|
||||||
|
Assert.IsTrue(manager.GetAllUsableBeatmapSets().Count == 0);
|
||||||
|
Assert.IsTrue(manager.QueryBeatmapSets(_ => true).ToList().Count() == 1);
|
||||||
|
Assert.IsTrue(manager.QueryBeatmapSets(_ => true).First().DeletePending);
|
||||||
|
|
||||||
|
temp = prepareTempCopy(osz_path);
|
||||||
|
Assert.IsTrue(File.Exists(temp));
|
||||||
|
var importedSecondTime = manager.Import(temp);
|
||||||
|
|
||||||
|
ensureLoaded(osu);
|
||||||
|
|
||||||
|
// check the newly "imported" beatmap is actually just the restored previous import. since it matches hash.
|
||||||
|
Assert.IsTrue(imported.First().ID == importedSecondTime.First().ID);
|
||||||
|
Assert.IsTrue(imported.First().Beatmaps.First().ID == importedSecondTime.First().Beatmaps.First().ID);
|
||||||
|
|
||||||
|
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
||||||
|
|
||||||
|
host.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[NonParallelizable]
|
[NonParallelizable]
|
||||||
[Ignore("Binding IPC on Appveyor isn't working (port in use). Need to figure out why")]
|
[Ignore("Binding IPC on Appveyor isn't working (port in use). Need to figure out why")]
|
||||||
@ -166,8 +205,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
int countBeatmaps = 0;
|
int countBeatmaps = 0;
|
||||||
|
|
||||||
waitForOrAssert(() =>
|
waitForOrAssert(() =>
|
||||||
(countBeatmapSetBeatmaps = queryBeatmapSets().First().Beatmaps.Count) ==
|
(countBeatmapSetBeatmaps = queryBeatmapSets().First().Beatmaps.Count) ==
|
||||||
(countBeatmaps = queryBeatmaps().Count()),
|
(countBeatmaps = queryBeatmaps().Count()),
|
||||||
$@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps}).", timeout);
|
$@"Incorrect database beatmap count post-import ({countBeatmaps} but should be {countBeatmapSetBeatmaps}).", timeout);
|
||||||
|
|
||||||
var set = queryBeatmapSets().First();
|
var set = queryBeatmapSets().First();
|
||||||
@ -192,7 +231,10 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
private void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
private void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
||||||
{
|
{
|
||||||
Action waitAction = () => { while (!result()) Thread.Sleep(200); };
|
Action waitAction = () =>
|
||||||
|
{
|
||||||
|
while (!result()) Thread.Sleep(200);
|
||||||
|
};
|
||||||
Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(timeout), failureMessage);
|
Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(timeout), failureMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user