Fix AccountCreationOverlay tests and better complete dummy api's behaviour

This commit is contained in:
Dean Herbert
2019-03-22 11:55:35 +09:00
parent 6058f994e1
commit dc004910d7
3 changed files with 68 additions and 9 deletions

View File

@ -1,12 +1,15 @@
// 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.
using System.Collections.Generic;
using System.Threading;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Users;
namespace osu.Game.Online.API
{
public class DummyAPIAccess : IAPIProvider
public class DummyAPIAccess : Component, IAPIProvider
{
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
{
@ -20,7 +23,29 @@ namespace osu.Game.Online.API
public string Endpoint => "http://localhost";
public APIState State => LocalUser.Value.Id == 1 ? APIState.Offline : APIState.Online;
private APIState state = APIState.Online;
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
public APIState State
{
get => state;
private set
{
APIState oldState = state;
APIState newState = value;
state = value;
if (oldState != newState)
{
Scheduler.Add(delegate
{
components.ForEach(c => c.APIStateChanged(this, newState));
});
}
}
}
public virtual void Queue(APIRequest request)
{
@ -28,28 +53,36 @@ namespace osu.Game.Online.API
public void Register(IOnlineComponent component)
{
// todo: add support
Scheduler.Add(delegate { components.Add(component); });
component.APIStateChanged(this, state);
}
public void Unregister(IOnlineComponent component)
{
// todo: add support
Scheduler.Add(delegate { components.Remove(component); });
}
public void Login(string username, string password)
{
LocalUser.Value = new User
{
Username = @"Dummy",
Username = username,
Id = 1001,
};
State = APIState.Online;
}
public void Logout()
{
LocalUser.Value = new GuestUser();
State = APIState.Offline;
}
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) => null;
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
{
Thread.Sleep(200);
return null;
}
}
}