mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 16:02:58 +08:00
Add test coverage of failed imports
This commit is contained in:
parent
ad8a710a69
commit
5345018d4c
@ -18,6 +18,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -387,6 +388,41 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task TestModelCreationFailureDoesntReturn()
|
||||||
|
{
|
||||||
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(ImportBeatmapTest)))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
var importer = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
|
var progressNotification = new ImportProgressNotification();
|
||||||
|
|
||||||
|
var zipStream = new MemoryStream();
|
||||||
|
|
||||||
|
using (var zip = ZipArchive.Create())
|
||||||
|
zip.SaveTo(zipStream, new ZipWriterOptions(CompressionType.Deflate));
|
||||||
|
|
||||||
|
var imported = await importer.Import(
|
||||||
|
progressNotification,
|
||||||
|
new ImportTask(zipStream, string.Empty)
|
||||||
|
);
|
||||||
|
|
||||||
|
checkBeatmapSetCount(osu, 0);
|
||||||
|
checkBeatmapCount(osu, 0);
|
||||||
|
|
||||||
|
Assert.IsEmpty(imported);
|
||||||
|
Assert.AreEqual(ProgressNotificationState.Cancelled, progressNotification.State);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
host.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestRollbackOnFailure()
|
public async Task TestRollbackOnFailure()
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.IO.Archives;
|
using osu.Game.IO.Archives;
|
||||||
using osu.Game.Models;
|
using osu.Game.Models;
|
||||||
|
using osu.Game.Overlays.Notifications;
|
||||||
using osu.Game.Stores;
|
using osu.Game.Stores;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
using Realms;
|
using Realms;
|
||||||
@ -367,6 +368,34 @@ namespace osu.Game.Tests.Database
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestModelCreationFailureDoesntReturn()
|
||||||
|
{
|
||||||
|
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||||
|
{
|
||||||
|
using var importer = new BeatmapImporter(realmFactory, storage);
|
||||||
|
using var store = new RealmRulesetStore(realmFactory, storage);
|
||||||
|
|
||||||
|
var progressNotification = new ImportProgressNotification();
|
||||||
|
|
||||||
|
var zipStream = new MemoryStream();
|
||||||
|
|
||||||
|
using (var zip = ZipArchive.Create())
|
||||||
|
zip.SaveTo(zipStream, new ZipWriterOptions(CompressionType.Deflate));
|
||||||
|
|
||||||
|
var imported = await importer.Import(
|
||||||
|
progressNotification,
|
||||||
|
new ImportTask(zipStream, string.Empty)
|
||||||
|
);
|
||||||
|
|
||||||
|
checkBeatmapSetCount(realmFactory.Context, 0);
|
||||||
|
checkBeatmapCount(realmFactory.Context, 0);
|
||||||
|
|
||||||
|
Assert.IsEmpty(imported);
|
||||||
|
Assert.AreEqual(ProgressNotificationState.Cancelled, progressNotification.State);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestRollbackOnFailure()
|
public void TestRollbackOnFailure()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user