mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 03:22:55 +08:00
Add test coverage of token failure scenarios
This commit is contained in:
parent
04b874bb00
commit
6e8d4e382e
@ -1,10 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Testing;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Online.Solo;
|
using osu.Game.Online.Solo;
|
||||||
@ -21,14 +21,74 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||||
|
|
||||||
|
protected override bool HasCustomSteps => true;
|
||||||
|
|
||||||
protected override TestPlayer CreatePlayer(Ruleset ruleset)
|
protected override TestPlayer CreatePlayer(Ruleset ruleset)
|
||||||
{
|
{
|
||||||
SelectedMods.Value = new[] { ruleset.GetAllMods().OfType<ModNoFail>().First() };
|
SelectedMods.Value = new[] { ruleset.GetAllMods().OfType<ModNoFail>().First() };
|
||||||
return new TestPlayer(false);
|
return new TestPlayer(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUpSteps]
|
[Test]
|
||||||
public override void SetUpSteps()
|
public void TestNoSubmissionOnResultsWithNoToken()
|
||||||
|
{
|
||||||
|
prepareTokenResponse(false);
|
||||||
|
|
||||||
|
CreateTest(() => { });
|
||||||
|
|
||||||
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
||||||
|
|
||||||
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
||||||
|
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));
|
||||||
|
|
||||||
|
AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
|
||||||
|
|
||||||
|
AddAssert("ensure no submission", () => !Player.SubmissionRequested);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSubmissionOnResults()
|
||||||
|
{
|
||||||
|
prepareTokenResponse(true);
|
||||||
|
|
||||||
|
CreateTest(() => { });
|
||||||
|
|
||||||
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
||||||
|
|
||||||
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
||||||
|
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));
|
||||||
|
|
||||||
|
AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
|
||||||
|
|
||||||
|
AddAssert("ensure submission", () => Player.SubmissionRequested);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNoSubmissionOnExitWithNoToken()
|
||||||
|
{
|
||||||
|
prepareTokenResponse(false);
|
||||||
|
|
||||||
|
CreateTest(() => { });
|
||||||
|
|
||||||
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
||||||
|
AddStep("exit", () => Player.Exit());
|
||||||
|
|
||||||
|
AddAssert("ensure no submission", () => !Player.SubmissionRequested);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSubmissionOnExit()
|
||||||
|
{
|
||||||
|
prepareTokenResponse(true);
|
||||||
|
|
||||||
|
CreateTest(() => { });
|
||||||
|
|
||||||
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
||||||
|
AddStep("exit", () => Player.Exit());
|
||||||
|
AddUntilStep("wait for submission", () => Player.SubmissionRequested);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareTokenResponse(bool validToken)
|
||||||
{
|
{
|
||||||
AddStep("Prepare test API", () =>
|
AddStep("Prepare test API", () =>
|
||||||
{
|
{
|
||||||
@ -37,38 +97,16 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
switch (request)
|
switch (request)
|
||||||
{
|
{
|
||||||
case CreateSoloScoreRequest tokenRequest:
|
case CreateSoloScoreRequest tokenRequest:
|
||||||
tokenRequest.TriggerSuccess(new APIScoreToken { ID = 1234 });
|
if (validToken)
|
||||||
|
tokenRequest.TriggerSuccess(new APIScoreToken { ID = 1234 });
|
||||||
|
else
|
||||||
|
tokenRequest.TriggerFailure(new Exception());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
base.SetUpSteps();
|
|
||||||
|
|
||||||
// Ensure track has actually running before attempting to seek
|
|
||||||
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestSubmissionOnResults()
|
|
||||||
{
|
|
||||||
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
||||||
|
|
||||||
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));
|
|
||||||
|
|
||||||
AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
|
|
||||||
|
|
||||||
AddUntilStep("wait for submission", () => Player.SubmissionRequested);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestSubmissionOnExit()
|
|
||||||
{
|
|
||||||
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
|
||||||
AddStep("exit", () => Player.Exit());
|
|
||||||
AddUntilStep("wait for submission", () => Player.SubmissionRequested);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user