1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Improve testability of API

This commit is contained in:
Dean Herbert 2018-02-16 13:47:30 +09:00
parent e1f81488cd
commit 75dcf72520
5 changed files with 70 additions and 3 deletions

View File

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading;
using osu.Framework;
using osu.Framework.Configuration;
using osu.Framework.Logging;
using osu.Framework.Threading;
@ -16,7 +15,7 @@ using osu.Game.Users;
namespace osu.Game.Online.API
{
public class APIAccess : IUpdateable
public class APIAccess : IAPIProvider
{
private readonly OAuth authentication;
@ -34,7 +33,7 @@ namespace osu.Game.Online.API
public string Password;
public Bindable<User> LocalUser = new Bindable<User>(createGuestUser());
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
public string Token
{

View File

@ -0,0 +1,31 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Game.Users;
namespace osu.Game.Online.API
{
public class DummyAPIAccess : IAPIProvider
{
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
{
Username = @"Dummy",
Id = 1,
});
public bool IsLoggedIn => true;
public void Update()
{
}
public virtual void Queue(APIRequest request)
{
}
public void Register(IOnlineComponent component)
{
}
}
}

View File

@ -0,0 +1,34 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using osu.Framework.Configuration;
using osu.Game.Users;
namespace osu.Game.Online.API
{
public interface IAPIProvider : IUpdateable
{
/// <summary>
/// The local user.
/// </summary>
Bindable<User> LocalUser { get; }
/// <summary>
/// Returns whether the local user is logged in.
/// </summary>
bool IsLoggedIn { get; }
/// <summary>
/// Queue a new request.
/// </summary>
/// <param name="request">The request to perform.</param>
void Queue(APIRequest request);
/// <summary>
/// Register a component to receive state changes.
/// </summary>
/// <param name="component">The component to register.</param>
void Register(IOnlineComponent component);
}
}

View File

@ -105,6 +105,7 @@ namespace osu.Game
Username = LocalConfig.Get<string>(OsuSetting.Username),
Token = LocalConfig.Get<string>(OsuSetting.Token)
});
dependencies.CacheAs<IAPIProvider>(API);
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));

View File

@ -281,6 +281,8 @@
<Compile Include="Database\SingletonContextFactory.cs" />
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
<Compile Include="Graphics\Textures\LargeTextureStore.cs" />
<Compile Include="Online\API\DummyAPIAccess.cs" />
<Compile Include="Online\API\IAPIProvider.cs" />
<Compile Include="Online\API\Requests\GetUserRequest.cs" />
<Compile Include="Migrations\20180125143340_Settings.cs" />
<Compile Include="Migrations\20180125143340_Settings.Designer.cs">