mirror of
https://github.com/ppy/osu.git
synced 2025-01-09 02:24:10 +08:00
Add failing tests for looking up users by online ID if present when importing scores
This commit is contained in:
parent
554ead0d9d
commit
bd869b6cdc
@ -287,7 +287,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUserLookedUpForOnlineScore()
|
public void TestUserLookedUpByUsernameForOnlineScoreIfUserIDMissing()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
@ -301,6 +301,9 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
switch (req)
|
switch (req)
|
||||||
{
|
{
|
||||||
case GetUserRequest userRequest:
|
case GetUserRequest userRequest:
|
||||||
|
if (userRequest.Lookup != "Test user")
|
||||||
|
return false;
|
||||||
|
|
||||||
userRequest.TriggerSuccess(new APIUser
|
userRequest.TriggerSuccess(new APIUser
|
||||||
{
|
{
|
||||||
Username = "Test user",
|
Username = "Test user",
|
||||||
@ -350,7 +353,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUserLookedUpForLegacyOnlineScore()
|
public void TestUserLookedUpByUsernameForLegacyOnlineScore()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
@ -364,6 +367,9 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
switch (req)
|
switch (req)
|
||||||
{
|
{
|
||||||
case GetUserRequest userRequest:
|
case GetUserRequest userRequest:
|
||||||
|
if (userRequest.Lookup != "Test user")
|
||||||
|
return false;
|
||||||
|
|
||||||
userRequest.TriggerSuccess(new APIUser
|
userRequest.TriggerSuccess(new APIUser
|
||||||
{
|
{
|
||||||
Username = "Test user",
|
Username = "Test user",
|
||||||
@ -413,7 +419,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUserNotLookedUpForOfflineScore()
|
public void TestUserNotLookedUpForOfflineScoreIfUserIDMissing()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
@ -427,6 +433,9 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
switch (req)
|
switch (req)
|
||||||
{
|
{
|
||||||
case GetUserRequest userRequest:
|
case GetUserRequest userRequest:
|
||||||
|
if (userRequest.Lookup != "Test user")
|
||||||
|
return false;
|
||||||
|
|
||||||
userRequest.TriggerSuccess(new APIUser
|
userRequest.TriggerSuccess(new APIUser
|
||||||
{
|
{
|
||||||
Username = "Test user",
|
Username = "Test user",
|
||||||
@ -476,6 +485,73 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestUserLookedUpByOnlineIDIfPresent([Values] bool isOnlineScore)
|
||||||
|
{
|
||||||
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
|
var api = (DummyAPIAccess)osu.API;
|
||||||
|
api.HandleRequest = req =>
|
||||||
|
{
|
||||||
|
switch (req)
|
||||||
|
{
|
||||||
|
case GetUserRequest userRequest:
|
||||||
|
if (userRequest.Lookup != "5555")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
userRequest.TriggerSuccess(new APIUser
|
||||||
|
{
|
||||||
|
Username = "Some other guy",
|
||||||
|
CountryCode = CountryCode.DE,
|
||||||
|
Id = 5555
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
|
||||||
|
|
||||||
|
var toImport = new ScoreInfo
|
||||||
|
{
|
||||||
|
Rank = ScoreRank.B,
|
||||||
|
TotalScore = 987654,
|
||||||
|
Accuracy = 0.8,
|
||||||
|
MaxCombo = 500,
|
||||||
|
Combo = 250,
|
||||||
|
User = new APIUser { Id = 5555 },
|
||||||
|
Date = DateTimeOffset.Now,
|
||||||
|
Ruleset = new OsuRuleset().RulesetInfo,
|
||||||
|
BeatmapInfo = beatmap.Beatmaps.First()
|
||||||
|
};
|
||||||
|
if (isOnlineScore)
|
||||||
|
toImport.OnlineID = 12345;
|
||||||
|
|
||||||
|
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.Date, imported.Date);
|
||||||
|
Assert.AreEqual(toImport.OnlineID, imported.OnlineID);
|
||||||
|
Assert.AreEqual("Some other guy", imported.RealmUser.Username);
|
||||||
|
Assert.AreEqual(5555, imported.RealmUser.OnlineID);
|
||||||
|
Assert.AreEqual(CountryCode.DE, imported.RealmUser.CountryCode);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
host.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ScoreInfo LoadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
|
public static ScoreInfo LoadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
|
||||||
{
|
{
|
||||||
// clone to avoid attaching the input score to realm.
|
// clone to avoid attaching the input score to realm.
|
||||||
|
Loading…
Reference in New Issue
Block a user