Add DummyAPIAccess request handler

Make CreateChannelRequest.channel public
This commit is contained in:
Craftplacer
2021-06-05 14:42:16 +02:00
parent ce4bcda803
commit 5e44329e0b
2 changed files with 33 additions and 7 deletions

View File

@ -1,6 +1,7 @@
// 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.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -9,6 +10,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
@ -29,12 +32,9 @@ namespace osu.Game.Tests.Visual.Online
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
// We blindly mark every request as success so that ChannelManager doesn't remove our channel again.
if (API is DummyAPIAccess daa) if (API is DummyAPIAccess daa)
{ {
daa.HandleRequest = (request) => { daa.HandleRequest = dummyAPIHandleRequest;
return true;
};
} }
friend = new User { Id = 0, Username = "Friend" }; friend = new User { Id = 0, Username = "Friend" };
@ -52,6 +52,32 @@ namespace osu.Game.Tests.Visual.Online
}); });
} }
private bool dummyAPIHandleRequest(APIRequest request)
{
switch (request)
{
case GetMessagesRequest messagesRequest:
messagesRequest.TriggerSuccess(new List<Message>(0));
return true;
case CreateChannelRequest createChannelRequest:
var apiChatChannel = new APIChatChannel
{
RecentMessages = new List<Message>(0),
ChannelID = (int)createChannelRequest.Channel.Id
};
createChannelRequest.TriggerSuccess(apiChatChannel);
return true;
case ListChannelsRequest listChannelsRequest:
listChannelsRequest.TriggerSuccess(new List<Channel>(1) { publicChannel });
return true;
default:
return false;
}
}
[Test] [Test]
public void TestPublicChannelMention() public void TestPublicChannelMention()
{ {

View File

@ -11,11 +11,11 @@ namespace osu.Game.Online.API.Requests
{ {
public class CreateChannelRequest : APIRequest<APIChatChannel> public class CreateChannelRequest : APIRequest<APIChatChannel>
{ {
private readonly Channel channel; public readonly Channel Channel;
public CreateChannelRequest(Channel channel) public CreateChannelRequest(Channel channel)
{ {
this.channel = channel; Channel = channel;
} }
protected override WebRequest CreateWebRequest() protected override WebRequest CreateWebRequest()
@ -24,7 +24,7 @@ namespace osu.Game.Online.API.Requests
req.Method = HttpMethod.Post; req.Method = HttpMethod.Post;
req.AddParameter("type", $"{ChannelType.PM}"); req.AddParameter("type", $"{ChannelType.PM}");
req.AddParameter("target_id", $"{channel.Users.First().Id}"); req.AddParameter("target_id", $"{Channel.Users.First().Id}");
return req; return req;
} }