Exemple #1
0
        /// <summary>
        /// "Create" - button clicked.
        /// Validates and creates a new room.
        /// Redirect to Dashboard page if successfull.
        /// </summary>
        public async void CreateButtonClicked()
        {
            using (UserDialogs.Instance.Loading("Creating room..."))
            {
                List <IStreamingPlatform> selectedStreamingPlatforms = new List <IStreamingPlatform>();
                foreach (HelperModel selectedItem in this.SelectedHelperModels)
                {
                    selectedStreamingPlatforms.Add(selectedItem.StreamingPlatform);
                }

                // Run validation on input fields.
                string[] roomNameErrors = DefaultValidator.ValidRoomName(this.RoomName);
                bool     streamingPlatformsHasBeenSelected = selectedStreamingPlatforms.Count > 0;

                // Check for errors
                if (roomNameErrors.Length == 0 && streamingPlatformsHasBeenSelected)
                {
                    // No errors
                    // Create room
                    try
                    {
                        IUser  owner    = this._userService.CurrentUser;
                        string roomName = this.RoomName;

                        // Create room
                        await this._roomService.CreateRoomAsync(owner, roomName, selectedStreamingPlatforms);

                        // Redirect to login page
                        RedirectToMainPage();
                    }
                    catch (Exception e)
                    {
                        // An unexpected error occured, so user could not be created.
                        // Show generic error message to user.
                        ShowAlert("An error occured. Room could not be created.");
                    }
                }
                else
                {
                    // Errors in user input.
                    // Display errors.
                    string errorMessage = "Invalid room data:" + System.Environment.NewLine;

                    foreach (var error in roomNameErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }

                    if (!streamingPlatformsHasBeenSelected)
                    {
                        errorMessage += System.Environment.NewLine + "No streaming service has been selected!";
                    }

                    ShowAlert(errorMessage);
                }
            }
        }
Exemple #2
0
        public void ValidRoomName_ValidValues_ShouldReturnEmptyErrorList(string validateString)
        {
            // Arrange
            string testString = validateString;

            // Act
            var errorList = DefaultValidator.ValidRoomName(validateString);

            // Assert
            Assert.IsEmpty(errorList);
        }