public async Task GetProjectLobbyStateAsync_IfInvalid_ThrowsValidationFailedException() { _validatorMock .Setup(m => m.Validate(It.IsAny <object>())) .Returns(FailedValidationResult); await Assert.ThrowsAsync <ValidationFailedException>(() => _target.GetProjectLobbyStateAsync(Guid.NewGuid())); }
private async Task <CurrentProjectState> CreateCurrentProjectState(Project project, bool userHasAccess) { LobbyState lobbyState; try { var lobbyStateResponse = await _projectLobbyStateController.GetProjectLobbyStateAsync(project.Id); lobbyState = lobbyStateResponse.LobbyState; } catch (NotFoundException) { throw new NotFoundException(ResponseReasons.NotFoundProject); } var guestContext = await _projectGuestContextService.GetProjectGuestContextAsync(); var guestSession = guestContext == null || guestContext.GuestSessionId == Guid.Empty ? null : await _guestSessionRepository.GetItemAsync(guestContext.GuestSessionId); return(new CurrentProjectState { Project = project, GuestSession = guestSession, UserHasAccess = userHasAccess, LobbyState = lobbyState, Message = "Successfully set current project" }); }
private async Task <object> GetProjectLobbyStateAsync(dynamic input) { var projectId = input.projectId; await RequiresAccess() .WithProjectIdExpansion(ctx => projectId) .ExecuteAsync(CancellationToken.None); try { return(await _projectLobbyStateController.GetProjectLobbyStateAsync(projectId)); } catch (ValidationFailedException ex) { Logger.Error($"Validation failed during retrieval of lobby state for project: {projectId}", ex); return(Response.BadRequestValidationFailed(ex.Errors)); } catch (NotFoundException ex) { Logger.Error($"Could not find project lobby state for project: {projectId}", ex); return(Response.NotFound(ResponseReasons.NotFoundProjectLobbyState)); } catch (Exception ex) { Logger.Error($"An error occurred retrieving lobby state for project: {projectId}", ex); return(Response.InternalServerError(ResponseReasons.InternalServerErrorGetProjectLobbyState)); } }