public async Task UserChangesMods() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", AllowedMods = new[] { new APIMod(new OsuModFlashlight()), new APIMod(new OsuModApproachDifferent()) }, }); var setMods = new[] { new APIMod(new OsuModApproachDifferent()) }; await Hub.ChangeUserMods(setMods); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Equal(setMods, room.Users.First().Mods); } setMods = new[] { new APIMod(new OsuModApproachDifferent()), new APIMod(new OsuModFlashlight()) }; await Hub.ChangeUserMods(setMods); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Equal(setMods, room.Users.First().Mods); } }
public async Task UserSelectsDisallowedModsThrows() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeSettings(new MultiplayerRoomSettings { RulesetID = 2, BeatmapChecksum = "checksum", AllowedMods = new[] { new APIMod(new CatchModHidden()), }, }); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeUserMods(new[] { new APIMod(new CatchModHidden()), // this should cause the complete setting change to fail, including the hidden mod application. new APIMod(new CatchModDaycore()) })); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Empty(room.Users.First().Mods); } }
public async Task ChangingSettingsMarksReadyUsersAsIdle() { MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { Name = "bestest room ever", BeatmapChecksum = "checksum" }; await Hub.JoinRoom(ROOM_ID); MultiplayerRoom?room; using (var usage = Hub.GetRoom(ROOM_ID)) { // unsafe, but just for tests. room = usage.Item; Debug.Assert(room != null); } await Hub.ChangeState(MultiplayerUserState.Ready); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Ready), Times.Once); Assert.All(room.Users, u => Assert.Equal(MultiplayerUserState.Ready, u.State)); await Hub.ChangeSettings(testSettings); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Idle), Times.Once); Assert.All(room.Users, u => Assert.Equal(MultiplayerUserState.Idle, u.State)); }
public async Task ChangingDisallowedModsRemovesUserMods() { await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser); await Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", AllowedMods = new[] { new APIMod(new OsuModApproachDifferent()), new APIMod(new OsuModFlashlight()), new APIMod(new OsuModHardRock()) }, }); await Hub.ChangeUserMods(new[] { new APIMod(new OsuModFlashlight()), new APIMod(new OsuModApproachDifferent()) }); assertUserMods(USER_ID, "FL", "AD"); SetUserContext(ContextUser2); await Hub.ChangeUserMods(new[] { new APIMod(new OsuModHardRock()), new APIMod(new OsuModApproachDifferent()) }); assertUserMods(USER_ID_2, "HR", "AD"); SetUserContext(ContextUser); await Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", AllowedMods = new[] { new APIMod(new OsuModFlashlight()), new APIMod(new OsuModHardRock()) }, }); assertUserMods(USER_ID, "FL"); assertUserMods(USER_ID_2, "HR"); void assertUserMods(int userId, params string[] modAcronyms) { Receiver.Verify(c => c.UserModsChanged(userId, It.Is <IEnumerable <APIMod> >(mods => mods.Select(m => m.Acronym).SequenceEqual(modAcronyms))), Times.Once); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); var userMods = room.Users.Single(u => u.UserID == userId).Mods; Assert.Equal(modAcronyms, userMods.Select(m => m.Acronym)); } } }
public async Task ChangingSettingsToCustomRulesetThrows(int rulesetID) { MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { BeatmapID = 1234, BeatmapChecksum = "checksum", RulesetID = rulesetID, }; await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(testSettings)); }
public async Task UserCantChangeSettingsWhenGameIsActive() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); await Hub.StartMatch(); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(new MultiplayerRoomSettings())); }
public async Task ChangingSettingsToCustomizedBeatmapThrows() { Database.Setup(d => d.GetBeatmapChecksumAsync(9999)).ReturnsAsync("correct checksum"); MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { BeatmapID = 9999, BeatmapChecksum = "incorrect checksum", }; await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(testSettings)); }
public async Task HostSetsInvalidRequiredModsForRulesetThrows() { await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", RulesetID = 3, RequiredMods = new[] { new APIMod(new OsuModBlinds()), }, })); }
public async Task ChangingSettingsToNonExistentBeatmapThrows() { Database.Setup(d => d.GetBeatmapChecksumAsync(3333)).ReturnsAsync((string?)null); MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { BeatmapID = 3333, BeatmapChecksum = "checksum", }; await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(testSettings)); }
public async Task HostSetsInvalidRequiredModsCombinationThrows() { await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", RulesetID = 0, RequiredMods = new[] { new APIMod(new OsuModHidden()), new APIMod(new OsuModApproachDifferent()), }, })); }
public async Task RoomSettingsUpdateNotifiesOtherUsers() { MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { BeatmapID = 1234567, BeatmapChecksum = "checksum", RulesetID = 2 }; await Hub.JoinRoom(ROOM_ID); await Hub.ChangeSettings(testSettings); Receiver.Verify(r => r.SettingsChanged(testSettings), Times.Once); }
public async Task HostCanSetIncompatibleAllowedModsCombination() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", RulesetID = 0, AllowedMods = new[] { // setting an incompatible combination should be allowed. // will be enforced at the point of a user choosing from the allowed mods. new APIMod(new OsuModFlashlight()), new APIMod(new OsuModApproachDifferent()), }, }); }
public async Task HostSetsOverlappingRequiredAllowedMods() { await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(new MultiplayerRoomSettings { BeatmapChecksum = "checksum", RequiredMods = new[] { new APIMod(new OsuModFlashlight()), }, AllowedMods = new[] { // if a mod is in RequiredMods it shouldn't also be in AllowedMods. new APIMod(new OsuModFlashlight()), }, })); }
public async Task ChangingSettingsUpdatesModel() { MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { Name = "bestest room ever", BeatmapChecksum = "checksum" }; await Hub.JoinRoom(ROOM_ID); await Hub.ChangeSettings(testSettings); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Equal(testSettings.Name, room.Settings.Name); } }
public async Task ServerDoesNotAcceptClientPlaylistItemId() { await Hub.JoinRoom(ROOM_ID); MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { Name = "bestest room ever", BeatmapChecksum = "checksum", PlaylistItemId = 1 }; await Hub.ChangeSettings(testSettings); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Equal(0, room.Settings.PlaylistItemId); Receiver.Verify(r => r.SettingsChanged(room.Settings), Times.Once); } }
public async Task UserSelectsInvalidModsForRulesetThrows() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeSettings(new MultiplayerRoomSettings { RulesetID = 2, BeatmapChecksum = "checksum", AllowedMods = new[] { new APIMod(new CatchModHidden()), }, }); await Hub.ChangeUserMods(new[] { new APIMod(new CatchModHidden()) }); IEnumerable <APIMod> originalMods; using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); originalMods = room.Users.First().Mods; Assert.NotEmpty(originalMods); } await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeUserMods(new[] { new APIMod(new OsuModApproachDifferent()) })); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Equal(originalMods, room.Users.First().Mods); } }
public async Task ChangingRulesetRemovesInvalidUserMods() { await Hub.JoinRoom(ROOM_ID); var roomSettings = new MultiplayerRoomSettings { BeatmapChecksum = "checksum", AllowedMods = new[] { new APIMod(new OsuModApproachDifferent()) }, }; await Hub.ChangeSettings(roomSettings); await Hub.ChangeUserMods(new[] { new APIMod(new OsuModApproachDifferent()) }); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.NotEmpty(room.Users.First().Mods); } await Hub.ChangeSettings(new MultiplayerRoomSettings { RulesetID = 2, BeatmapChecksum = "checksum", }); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Empty(room.Users.First().Mods); } }
public async Task UserCantChangeSettingsWhenNotJoinedRoom() { await Assert.ThrowsAsync <NotJoinedRoomException>(() => Hub.ChangeSettings(new MultiplayerRoomSettings())); }