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