Exemple #1
0
        public void AddreportToDB_AddDamageReportToDataBase_ResultIsTrue()
        {
            //Arrange
            var report = new BoatDamage
            {
                boatId             = 1,
                memberId           = 1,
                boatDamageLevel    = 2,
                boatDamageLocation = "Voor",
                boatDamageReason   = "Sawwy",
                reportDate         = DateTime.Now,
                boatImageBlob      = ""
            };
            var result = false;

            //Act
            //Method is placed inside a try block, so if it cant connect the result is set to false
            try
            {
                BoatDamage.AddReportToDb(report);

                //Check if the member is actually in the database
                using (var context = new BootDB())
                {
                    var Damages = from d in context.BoatDamages
                                  where d.boatId == report.boatId && d.memberId == report.memberId && d.boatDamageLevel == report.boatDamageLevel && d.boatDamageLocation == report.boatDamageLocation && d.boatDamageReason == report.boatDamageReason
                                  select d;

                    if (Damages.ToList().Count > 0)
                    {
                        result = true;
                    }
                }

                //Remove test member form database
                using (var context = new BootDB())
                {
                    context.BoatDamages.Attach(report);
                    context.BoatDamages.Remove(report);
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                result = false;
            }

            //Assert
            Assert.True(result);
        }
        //Method to execute when AddUser button is clicked
        private void ReportDamageButton_Click(object sender, RoutedEventArgs e)
        {
            //Save textBox content to variables for easy access
            var damageLevel = DamageLevel.SelectedIndex + 1; //Add 1 because combobox index start at 0 and values in database vary from 1 to 3
            var location    = LocationBox.Text;
            var reason      = ReasonBox.Text;

            //Check for empty fields, if a field is left empty show an error dialog
            if (!string.IsNullOrWhiteSpace(location) && !string.IsNullOrWhiteSpace(reason))
            {
                try
                {
                    //Convert image to blob
                    var selectedImageString = BoatImages.ImageToBase64(SelectedImageForConversion, System.Drawing.Imaging.ImageFormat.Png);
                    var selectedImageInput  = selectedImageString;

                    //Create new report to add to the DB
                    var boatDamage = new BoatDamage
                    {
                        boatId             = BoatId,
                        memberId           = MemberId,
                        boatDamageLevel    = damageLevel,
                        boatDamageLocation = location,
                        boatDamageReason   = reason,
                        reportDate         = DateTime.Now,
                        boatImageBlob      = selectedImageInput
                    };

                    //Add report to database
                    BoatDamage.AddReportToDb(boatDamage);

                    MessageBox.Show("Schade melding is succesvol toegevoegd.", "Melding toegevoegd", MessageBoxButton.OK, MessageBoxImage.Information);
                    switch (AccessLevel)
                    {
                    case 1:
                        Switcher.Switch(new HomePageMember(FullName, AccessLevel, MemberId));
                        break;

                    case 2:
                        Switcher.Switch(new HomePageMatchCommissioner(FullName, AccessLevel, MemberId));
                        break;

                    case 3:
                        Switcher.Switch(new HomePageMaterialCommissioner(FullName, AccessLevel, MemberId));
                        break;
                    }
                }
                catch (FileTooLargeException)
                {
                    MessageBox.Show("De geselecteerde afbeelding is te groot. (Max. 256kb)", "Bestand te groot", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                catch (Exception exception)
                {
                    //Error message for any other exception that could occur
                    MessageBox.Show(exception.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);
            }
        }