Esempio n. 1
0
        public void CheckForInvalidName_EnterNameThatIsIncorrect_ResultIsFalse()
        {
            //Arrange
            var boatname = "Líaçià-950*Amsterdam";
            var result   = false;

            //Act
            try
            {
                //The method CheckForInvalidCharacters has a void return type and throws a FormatException when the the string contains invalid characters
                InputValidation.CheckForInvalidCharacters(boatname);
                result = true;
            }
            catch (FormatException)
            {
                result = false;
            }

            //Assert
            Assert.False(result);
        }
        private void UpdateBoat()
        {
            var boatNameInput       = BoatNameBox.Text;
            var boatTypeInput       = Boat.AssignSelectedType(BoatTypeBox.Text);
            var boatYoutubeUrlInput = YoutubeUrlBox.Text;

            if (!string.IsNullOrWhiteSpace(boatNameInput) && BoatTypeBox.SelectedValue != null)
            {
                try
                {
                    InputValidation.CheckForInvalidCharacters(boatNameInput);
                    InputValidation.IsYoutubeUrl(boatYoutubeUrlInput);

                    var selectedImageString = BoatImages.ImageToBase64(SelectedImageForConversion, System.Drawing.Imaging.ImageFormat.Png);
                    var selectedImageInput  = selectedImageString;


                    if (System.Windows.Forms.MessageBox.Show("Weet u zeker dat u deze wijzigingen wil toepassen?", "Bevestiging",
                                                             System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question,
                                                             System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
                    {
                        using (var context = new BootDB())
                        {
                            var boot  = context.Boats.SingleOrDefault(b => b.boatId == BoatId);
                            var image = context.BoatImages.SingleOrDefault(i => i.boatId == BoatId);

                            boot.boatName       = boatNameInput;
                            boot.boatTypeId     = boatTypeInput;
                            boot.boatYoutubeUrl = YoutubeUrlBox.Text;

                            if (!string.IsNullOrWhiteSpace(selectedImageInput))
                            {
                                image.boatImageBlob = selectedImageInput;
                            }

                            context.SaveChanges();
                        }
                    }
                    Switcher.Switch(new boatOverviewScreen(FullName, AccessLevel, MemberId));
                }
                catch (FormatException)
                {
                    //Warning message for FormatException
                    MessageBox.Show("De ingevulde boot naam is niet geldig\n(let op: speciale tekens zijn niet toegestaan)", "Ongeldige waarde", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (InvalidYoutubeUrlException)
                {
                    //Warning message for InvalidYoutubeUrlException
                    MessageBox.Show("Vul een geldige YouTube URL in", "Ongeldige URL", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (FileTooLargeException)
                {
                    MessageBox.Show("De geselecteerde afbeelding is te groot. (Max. 256kb)", "Bestand te groot", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (Exception ex)
                {
                    //Error message for any other exception that could occur
                    MessageBox.Show(ex.Message, "Een fout is opgetreden", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Vul alle velden in.", "Niet alle velden zijn ingevuld", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }