public void Edit_NotNull_ViewResultIsNotNull()
        {
            //Arrange
            var guest = new GuestViewModel()
            {
                Id        = 1,
                FirstName = "Petro",
                LastName  = "Petrov"
            };
            var mock = new Mock <IGuestService>();

            mock.Setup(g => g.UpdateGuests(guest.Id, guest));
            var controller = new GuestController(mock.Object);
            //Act
            var result = controller.Edit(guest.Id, guest);

            //Assert
            Assert.IsNotNull(result);
        }
        public void Edit_GuestDoesNotExistPost_ReturnsABadRequestResults()
        {
            // Arrange
            var guestId   = 1;
            var testGuest = new GuestViewModel()
            {
                Id = guestId
            };
            var guestsRepo = new Mock <IGuestService>();

            guestsRepo.Setup(g => g.ReadSingle(It.IsAny <int>())).Throws(It.IsAny <Exception>());
            var controller = new GuestController(guestsRepo.Object);

            // Act
            var result = controller.Edit(guestId);

            // Assert
            Assert.That(result, Is.TypeOf <BadRequestResult>());
        }
        public void Edit_Success_ReturnsARedirectToActionResut()
        {
            // Arrange
            var guestId   = 1;
            var testGuest = new GuestViewModel()
            {
                Id = guestId
            };
            var guestsRepo = new Mock <IGuestService>();

            guestsRepo.Setup(g => g.UpdateGuests(guestId, It.IsAny <GuestViewModel>()));
            var controller = new GuestController(guestsRepo.Object);

            // Act
            var result = controller.Edit(guestId, testGuest);

            // Assert
            var redirectToActionResult = result as RedirectToActionResult;

            Assert.AreEqual("Index", redirectToActionResult.ActionName);
        }
        public void Edit_GuestExists_ReturnsAViewResultWithGuest()
        {
            // Arrange
            var guestId   = 1;
            var testGuest = new GuestViewModel()
            {
                Id = guestId
            };
            var guestsRepo = new Mock <IGuestService>();

            guestsRepo.Setup(g => g.ReadSingle(guestId)).Returns(testGuest);
            var controller = new GuestController(guestsRepo.Object);

            // Act
            var result = controller.Edit(guestId);

            // Assert
            var viewResult = result as ViewResult;
            var model      = viewResult.ViewData.Model as GuestViewModel;

            Assert.AreEqual(guestId, model.Id);
        }
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            switch (myState)
            {
            case FormState.Add:
                bool okayToAdd = ensureSafeProcess();
                if (okayToAdd)
                {
                    guest = PopulateGuest();
                    guestController.Add(guest);
                    if (accountForm == null)
                    {
                        CreateNewAccountForm();
                    }
                    if (accountForm.accountFormClosed)
                    {
                        CreateNewAccountForm();
                    }
                    accountForm.FormDisplay("add");
                    accountForm.Show();
                    this.Close();
                }
                break;

            case FormState.Edit:
                bool okayToEdit = ensureSafeProcess();
                if (okayToEdit)
                {
                    guest = PopulateGuest();
                    guestController.Edit(guest);
                    this.Close();
                }


                break;
            }
        }
Пример #6
0
        private void button2_Click(object sender, EventArgs e) //add guest
        {
            if ((myState == FormState.Add) || ((myState == FormState.WhileBooking) && button2.Text == "Add Guest") ||
                (myState == FormState.Edit))
            {
                Regex validateEmail = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                                @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$");


                //https://msdn.microsoft.com/en-us/library/01escwtf(v=vs.110).aspx



                Regex testForNonNumeric = new Regex(@"\D");

                Regex testForLetters = new Regex(@"^[a-zA-Z ]+$"); // @"^[a-zA-Z ]+$" for space character



                if (FirstNameTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter First Name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //https://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxicon(v=vs.110).aspx
                    FirstNameTextBox.Focus(); //focuses on text box with error

                    return;
                }

                else if (LastNameTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Last Name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    LastNameTextBox.Focus();
                    return;
                }



                else if (TelephoneTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Your Telephone Number", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (TelephoneTextBox.TextLength < 10)
                {
                    MessageBox.Show("Telephone number must contains 10 digits", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (TelephoneTextBox.TextLength > 10)
                {
                    MessageBox.Show("Telephone number must contains 10 digits", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (testForNonNumeric.IsMatch(TelephoneTextBox.Text))
                {
                    MessageBox.Show("Telephone number must contain digits only", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (EmailTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter An Email Address", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EmailTextBox.Focus();
                    return;
                }

                else if (!validateEmail.IsMatch(EmailTextBox.Text))
                {
                    MessageBox.Show("Invalid Email Address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EmailTextBox.Focus();
                    return;
                }


                else
                {
                    //go to next form
                    if (myState == FormState.Add)
                    {
                        guest = PopulateObject();
                        guestController.ADD(guest);
                        MessageBox.Show("Guest successfully added", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearAll();
                        this.Hide();
                    }
                    if (myState == FormState.WhileBooking)
                    {
                        guest = PopulateObject();
                        aBooking.DepositPaid = "false";
                        aBooking.GuestID     = guest.GuestID;

                        bookingController.ADD(aBooking);
                        guestController.ADD(guest);
                        MessageBox.Show("Guest successfully added and booking successfully made", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);


                        //would they like to pay now
                        DialogResult result = MessageBox.Show("Would you like to pay now", "Pay now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            PaymentDetailsForm paymentDetailsForm = new PaymentDetailsForm(paymentController,
                                                                                           aBooking, guest, bookingController);
                            paymentDetailsForm.MdiParent     = (Home)this.MdiParent;    // Setting the MDI Parent
                            paymentDetailsForm.StartPosition = FormStartPosition.CenterParent;
                            this.Hide();
                            paymentDetailsForm.Show();
                        }
                        else
                        {
                            //go straight to the email

                            ConfirmationForm cf = new ConfirmationForm(guest, aBooking);

                            cf.StartPosition = FormStartPosition.CenterParent;
                            cf.Show();
                            this.Hide();
                        }
                        ClearAll();
                    }
                    if (myState == FormState.Edit)
                    {
                        Guest g = new Guest();
                        g.GuestID   = textBox1.Text;
                        g.FirstName = FirstNameTextBox.Text;
                        g.Surname   = LastNameTextBox.Text;

                        g.TelephoneNumber = TelephoneTextBox.Text;
                        g.EmailAddress    = EmailTextBox.Text;


                        DialogResult result = MessageBox.Show("Are you sure you want to edit guest", "Edit Guest", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                        //populate the text boxes
                        if (result == DialogResult.Yes)
                        {
                            //we must delete the guest tell them guest has been successfully deleted
                            guestController.Edit(g);
                            MessageBox.Show("Guest successfully editted", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearAll();

                            this.Hide();
                        }
                        else
                        {
                            //reset the controls
                            showRequiredFields(FormState.Edit);
                        }
                    }
                }
            }

            else if (((myState == FormState.WhileBooking) && (button2.Text == "Verify Guest")) || (myState == FormState.Delete))
            {
                if (GuestIDTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter A Guest ID to search for", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GuestIDTextBox.Focus();
                    return;
                }
                else if (guestController.FindByGuestID(GuestIDTextBox.Text) == null)
                {
                    MessageBox.Show("Guest not found", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GuestIDTextBox.Focus();
                    return;
                }
                else
                {
                    Guest temp = guestController.FindByGuestID(GuestIDTextBox.Text);
                    FirstNameTextBox.Text = temp.FirstName;
                    LastNameTextBox.Text  = temp.Surname;

                    TelephoneTextBox.Text = temp.TelephoneNumber;

                    EmailTextBox.Text   = temp.EmailAddress;
                    GuestIDTextBox.Text = temp.GuestID;


                    if (myState == FormState.WhileBooking)
                    {
                        MessageBox.Show("Guest has been verified", "Verified", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //add the booking
                        aBooking.GuestID     = temp.GuestID;
                        aBooking.DepositPaid = "false";
                        bookingController.ADD(aBooking);
                        MessageBox.Show("Booking has been successfully made", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);


                        //populate the text boxes
                        DialogResult result = MessageBox.Show("Would you like to pay now", "Pay now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            PaymentDetailsForm paymentDetailsForm = new PaymentDetailsForm(paymentController, aBooking, temp, bookingController);
                            paymentDetailsForm.MdiParent     = (Home)this.MdiParent;        // Setting the MDI Parent
                            paymentDetailsForm.StartPosition = FormStartPosition.CenterParent;
                            this.Hide();
                            paymentDetailsForm.Show();
                        }
                        else
                        {
                            //go straight to the email

                            ConfirmationForm cf = new ConfirmationForm(temp, aBooking);

                            cf.StartPosition = FormStartPosition.CenterParent;
                            cf.Show();
                            this.Hide();
                        }
                    }
                    if (myState == FormState.Delete)
                    {
                        DialogResult result = MessageBox.Show("Are you sure you want to delete guest", "Delete guest", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                        //populate the text boxes
                        if (result == DialogResult.Yes)
                        {
                            //we must delete the guest tell them guest has been successfully deleted
                            guestController.Delete(temp);
                            MessageBox.Show("Guest has been deleted", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Hide();
                        }
                        else
                        {
                            //reset the controls
                            showRequiredFields(FormState.Delete);
                        }
                    }
                }
            }
        }