mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Fix multiple tests via null checks and changing ToLive
to Detach
flow
This commit is contained in:
parent
13401a8846
commit
e74a5022c9
@ -10,6 +10,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO.Archives;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -142,7 +143,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||
|
||||
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.BeatmapInfo.ID))!.Value);
|
||||
Assert.That(scoreManager.Query(s => s.Equals(imported)).Value.DeletePending, Is.EqualTo(true));
|
||||
Assert.That(scoreManager.Query(s => s.Equals(imported)).DeletePending, Is.EqualTo(true));
|
||||
|
||||
var secondImport = await LoadScoreIntoOsu(osu, imported);
|
||||
Assert.That(secondImport, Is.Null);
|
||||
@ -187,7 +188,7 @@ namespace osu.Game.Tests.Scores.IO
|
||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||
await scoreManager.Import(score, archive);
|
||||
|
||||
return scoreManager.Query(_ => true).Value;
|
||||
return scoreManager.Query(_ => true).Detach();
|
||||
}
|
||||
|
||||
internal class TestArchiveReader : ArchiveReader
|
||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Tests.Skins
|
||||
private void load()
|
||||
{
|
||||
var imported = beatmaps.Import(new ZipArchiveReader(TestResources.OpenResource("Archives/ogg-beatmap.osz"))).GetResultSafely();
|
||||
beatmap = beatmaps.GetWorkingBeatmap(imported.Value.Beatmaps[0]);
|
||||
beatmap = beatmaps.GetWorkingBeatmap(imported?.Value.Beatmaps[0]);
|
||||
beatmap.LoadTrack();
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,6 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
BeatmapSetInfo imported = null;
|
||||
AddStep($"import beatmap {i}", () =>
|
||||
{
|
||||
var difficulty = new BeatmapDifficulty();
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "SomeArtist",
|
||||
@ -115,18 +114,18 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
OnlineID = i * 1024,
|
||||
Metadata = metadata,
|
||||
BaseDifficulty = difficulty,
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
OnlineID = i * 2048,
|
||||
Metadata = metadata,
|
||||
BaseDifficulty = difficulty,
|
||||
BaseDifficulty = new BeatmapDifficulty(),
|
||||
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
|
||||
},
|
||||
}
|
||||
}).GetResultSafely().Value;
|
||||
}).GetResultSafely()?.Value;
|
||||
});
|
||||
|
||||
AddAssert($"import {i} succeeded", () => imported != null);
|
||||
|
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
AddStep("store selection", () => selection = carousel.SelectedBeatmapInfo);
|
||||
if (isIterating)
|
||||
AddUntilStep("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(selection));
|
||||
AddUntilStep("selection changed", () => !carousel.SelectedBeatmapInfo?.Equals(selection) == true);
|
||||
else
|
||||
AddUntilStep("selection not changed", () => carousel.SelectedBeatmapInfo.Equals(selection));
|
||||
}
|
||||
|
@ -200,6 +200,7 @@ namespace osu.Game.Beatmaps
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||
public BeatmapInfo? QueryBeatmap(Expression<Func<BeatmapInfo, bool>> query) => beatmapModelManager.QueryBeatmap(query)?.Detach();
|
||||
// TODO: move detach to usages?
|
||||
|
||||
/// <summary>
|
||||
/// Saves an <see cref="IBeatmap"/> file against a given <see cref="BeatmapInfo"/>.
|
||||
|
@ -491,10 +491,10 @@ namespace osu.Game
|
||||
ScoreInfo databasedScoreInfo = null;
|
||||
|
||||
if (score.OnlineID > 0)
|
||||
databasedScoreInfo = ScoreManager.Query(s => s.OnlineID == score.OnlineID)?.Value;
|
||||
databasedScoreInfo = ScoreManager.Query(s => s.OnlineID == score.OnlineID);
|
||||
|
||||
if (score is ScoreInfo scoreInfo)
|
||||
databasedScoreInfo ??= ScoreManager.Query(s => s.Hash == scoreInfo.Hash)?.Value;
|
||||
databasedScoreInfo ??= ScoreManager.Query(s => s.Hash == scoreInfo.Hash);
|
||||
|
||||
if (databasedScoreInfo == null)
|
||||
{
|
||||
|
@ -49,10 +49,10 @@ namespace osu.Game.Scoring
|
||||
/// </summary>
|
||||
/// <param name="query">The query.</param>
|
||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||
public ILive<ScoreInfo> Query(Expression<Func<ScoreInfo, bool>> query)
|
||||
public ScoreInfo Query(Expression<Func<ScoreInfo, bool>> query)
|
||||
{
|
||||
using (var context = contextFactory.CreateContext())
|
||||
return context.All<ScoreInfo>().FirstOrDefault(query)?.ToLive(contextFactory);
|
||||
return context.All<ScoreInfo>().FirstOrDefault(query)?.Detach();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -63,6 +64,9 @@ namespace osu.Game.Scoring
|
||||
if (!model.Ruleset.IsManaged)
|
||||
model.Ruleset = realm.Find<RulesetInfo>(model.Ruleset.ShortName);
|
||||
|
||||
if (string.IsNullOrEmpty(model.StatisticsJson))
|
||||
model.StatisticsJson = JsonConvert.SerializeObject(model.Statistics);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ namespace osu.Game.Screens.Select
|
||||
newRoot.AddChildren(beatmapSets.Select(createCarouselSet).Where(g => g != null));
|
||||
|
||||
root = newRoot;
|
||||
if (selectedBeatmapSet != null && !beatmapSets.Contains(selectedBeatmapSet.BeatmapSet))
|
||||
if (selectedBeatmapSet != null && (!selectedBeatmapSet.BeatmapSet.IsManaged || !beatmapSets.Contains(selectedBeatmapSet.BeatmapSet)))
|
||||
selectedBeatmapSet = null;
|
||||
|
||||
Scroll.Clear(false);
|
||||
|
@ -59,8 +59,15 @@ namespace osu.Game.Stores
|
||||
beatmapSet.Beatmaps.AddRange(createBeatmapDifficulties(beatmapSet.Files, realm));
|
||||
|
||||
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
|
||||
{
|
||||
b.BeatmapSet = beatmapSet;
|
||||
|
||||
// ensure we aren't trying to add a new ruleset to the database
|
||||
// this can happen in tests, mostly
|
||||
if (!b.Ruleset.IsManaged)
|
||||
b.Ruleset = realm.Find<RulesetInfo>(b.Ruleset.ShortName);
|
||||
}
|
||||
|
||||
validateOnlineIds(beatmapSet, realm);
|
||||
|
||||
bool hadOnlineIDs = beatmapSet.Beatmaps.Any(b => b.OnlineID > 0);
|
||||
|
@ -409,18 +409,18 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
public override Task<APIBeatmap> GetAPIBeatmap(int beatmapId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
IBeatmapSetInfo? set = roomManager.ServerSideRooms.SelectMany(r => r.Playlist)
|
||||
.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
||||
?? beatmaps.QueryBeatmap(b => b.OnlineID == beatmapId)?.BeatmapSet;
|
||||
IBeatmapInfo? beatmap = roomManager.ServerSideRooms.SelectMany(r => r.Playlist)
|
||||
.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value
|
||||
?? beatmaps.QueryBeatmap(b => b.OnlineID == beatmapId);
|
||||
|
||||
if (set == null)
|
||||
if (beatmap == null)
|
||||
throw new InvalidOperationException("Beatmap not found.");
|
||||
|
||||
return Task.FromResult(new APIBeatmap
|
||||
{
|
||||
BeatmapSet = new APIBeatmapSet { OnlineID = set.OnlineID },
|
||||
BeatmapSet = new APIBeatmapSet { OnlineID = beatmap.BeatmapSet?.OnlineID ?? -1 },
|
||||
OnlineID = beatmapId,
|
||||
Checksum = set.Beatmaps.First(b => b.OnlineID == beatmapId).MD5Hash
|
||||
Checksum = beatmap.MD5Hash
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user