More automated tests

This commit is contained in:
smoogipoo
2018-12-25 11:59:08 +09:00
parent 626ec85ae8
commit 23d21a45e5
2 changed files with 27 additions and 13 deletions

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -28,9 +29,9 @@ namespace osu.Game.Tests.Visual
public TestCaseLoungeRoomsContainer() public TestCaseLoungeRoomsContainer()
{ {
RoomsContainer rooms; RoomsContainer container;
Child = rooms = new RoomsContainer Child = container = new RoomsContainer
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -38,20 +39,32 @@ namespace osu.Game.Tests.Visual
JoinRequested = joinRequested JoinRequested = joinRequested
}; };
int roomId = 0; AddStep("clear rooms", () => roomManager.Rooms.Clear());
AddStep("Add room", () => roomManager.Rooms.Add(new Room AddStep("add rooms", () =>
{ {
Name = { Value = $"Room {++roomId}"}, for (int i = 0; i < 3; i++)
Host = { Value = new User { Username = "Host" } }, {
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) } roomManager.Rooms.Add(new Room
})); {
RoomID = { Value = i },
AddStep("Remove selected", () => Name = { Value = $"Room {i}" },
{ Host = { Value = new User { Username = "Host" } },
if (rooms.SelectedRoom.Value != null) EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
roomManager.Rooms.Remove(rooms.SelectedRoom.Value); });
}
}); });
AddAssert("has 2 rooms", () => container.Rooms.Count == 3);
AddStep("remove first room", () => roomManager.Rooms.Remove(roomManager.Rooms.FirstOrDefault()));
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
AddStep("select first room", () => container.Rooms.First().Action?.Invoke());
AddAssert("first room selected", () => container.SelectedRoom.Value == roomManager.Rooms.First());
AddStep("join first room", () => container.Rooms.First().Action?.Invoke());
AddAssert("first room joined", () => roomManager.Rooms.First().Status.Value is JoinedRoomStatus);
} }
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus(); private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();

View File

@ -25,6 +25,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
private readonly IBindableCollection<Room> rooms = new BindableCollection<Room>(); private readonly IBindableCollection<Room> rooms = new BindableCollection<Room>();
private readonly FillFlowContainer<DrawableRoom> roomFlow; private readonly FillFlowContainer<DrawableRoom> roomFlow;
public IReadOnlyList<DrawableRoom> Rooms => roomFlow;
[Resolved] [Resolved]
private IRoomManager roomManager { get; set; } private IRoomManager roomManager { get; set; }