Add test coverage for not updating `LastPlayed` due to newer plays

This commit is contained in:
Bartłomiej Dach 2023-10-30 09:28:37 +01:00
parent c1c8e2968f
commit 0dfb41b796
No known key found for this signature in database
1 changed files with 54 additions and 0 deletions

View File

@ -11,6 +11,8 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.IO.Archives;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
@ -126,6 +128,58 @@ public void TestLastPlayedUpdate(bool isLocalUser)
}
}
[Test]
public void TestLastPlayedNotUpdatedDueToNewerPlays()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
{
try
{
var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var beatmapInfo = beatmap.Beatmaps.First();
var realmAccess = osu.Dependencies.Get<RealmAccess>();
realmAccess.Write(r => r.Find<BeatmapInfo>(beatmapInfo.ID)!.LastPlayed = new DateTimeOffset(2023, 10, 30, 0, 0, 0, TimeSpan.Zero));
var toImport = new ScoreInfo
{
Rank = ScoreRank.B,
TotalScore = 987654,
Accuracy = 0.8,
MaxCombo = 500,
Combo = 250,
User = new APIUser
{
Username = "Test user",
Id = DummyAPIAccess.DUMMY_USER_ID,
},
Date = new DateTimeOffset(2023, 10, 27, 0, 0, 0, TimeSpan.Zero),
OnlineID = 12345,
Ruleset = new OsuRuleset().RulesetInfo,
BeatmapInfo = beatmapInfo
};
var imported = LoadScoreIntoOsu(osu, toImport);
Assert.AreEqual(toImport.Rank, imported.Rank);
Assert.AreEqual(toImport.TotalScore, imported.TotalScore);
Assert.AreEqual(toImport.Accuracy, imported.Accuracy);
Assert.AreEqual(toImport.MaxCombo, imported.MaxCombo);
Assert.AreEqual(toImport.User.Username, imported.User.Username);
Assert.AreEqual(toImport.Date, imported.Date);
Assert.AreEqual(toImport.OnlineID, imported.OnlineID);
Assert.That(imported.BeatmapInfo!.LastPlayed, Is.EqualTo(new DateTimeOffset(2023, 10, 30, 0, 0, 0, TimeSpan.Zero)));
}
finally
{
host.Exit();
}
}
}
[Test]
public void TestImportMods()
{