Esempio n. 1
0
        public async void AddSurvey_ValidObjectPassed_ReturnedResponseHasCreatedItem()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.AddAsync(It.IsAny <SurveyDTO>())).Returns((SurveyDTO s) => FakeServicesMethods.AddSurvey(s));
            var controller = new SurveyController(mock.Object);

            // Act
            var survey = new SurveyDTO
            {
                Id        = 1,
                Creator   = "John",
                Date      = DateTime.Now,
                Views     = 3,
                Title     = "Survey 1",
                Questions = new List <QuestionDTO>()
            };
            var result = await controller.AddSurvey(survey);

            var okResult = result as OkObjectResult;

            // Assert
            var item = Assert.IsAssignableFrom <SurveyDTO>(okResult.Value);

            Assert.Equal(1, (okResult.Value as SurveyDTO)?.Id);
        }
Esempio n. 2
0
        public async void AddSurvey_ValidObjectPassed_ReturnsOk()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.AddAsync(It.IsAny <SurveyDTO>())).Returns((SurveyDTO s) => FakeServicesMethods.AddSurvey(s));
            var controller = new SurveyController(mock.Object);

            // Act
            var survey = new SurveyDTO
            {
                Id        = 1,
                Creator   = "John",
                Date      = DateTime.Now,
                Views     = 3,
                Title     = "Survey 1",
                Questions = new List <QuestionDTO>()
            };
            var result = await controller.AddSurvey(survey);

            var okResult = result as OkObjectResult;

            // Assert
            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
        }
        public void AddSurvey_HttpGet_ReturnsCorrectView()
        {
            //Arrange
            SurveyController controller = new SurveyController();

            //Act
            ViewResult result = controller.AddSurvey() as ViewResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("AddSurvey", result.ViewName);
        }
Esempio n. 4
0
        public async void AddSurvey_InvalidObjectPassed_ReturnsBadRequest()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.AddAsync(It.IsAny <SurveyDTO>())).Returns((SurveyDTO s) => FakeServicesMethods.AddSurvey(s));
            var controller = new SurveyController(mock.Object);

            // Act
            var result = await controller.AddSurvey(null);

            var badRequestResult = result as BadRequestResult;

            // Assert
            Assert.NotNull(badRequestResult);
            Assert.Equal(400, badRequestResult.StatusCode);
        }
Esempio n. 5
0
    /*
     * CREATED:    H. L'Heureux         MAR 15 2018
     * MODIFIED:   H. Conant            MAR 27 2018
     *      - Updated method body
     * MODIFIED:   H. Conant            MAR 29 2018
     *      - Updated method body to show error messages
     *
     * Submit_Click()
     * This method checks to make sure the survey has answers in the questions. As long as one question has an answer, it will store the survey in the database and then the question answers.
     *
     * PARAMETERS:
     * object sender - object on the page that is being targeted
     * EventArgs e - event that has triggered the method
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * SurveyController.AddSurvey()
     * SurveyAnswerController.AddSurveyAnswer()
     */
    protected void Submit_Click(object sender, EventArgs e)
    {
        //clear any errors that may have happened
        ErrorMSG.Text   = "";
        ContactErr.Text = "";

        //make a regex for phone number validation
        Regex regex = new Regex(@"^(1-[1-9][0-9][0-9]|[1-9][0-9][0-9])-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$");

        // check that at least one question or customer profile question has been answered
        if (Q1ADDL.SelectedValue != "Unselected" ||
            Q1BDDL.SelectedValue != "Unselected" ||
            Q1CDDL.SelectedValue != "Unselected" ||
            Q1DDDL.SelectedValue != "Unselected" ||
            Q1EDDL.SelectedValue != "Unselected" ||
            Q2DDL.SelectedValue != "Unselected" ||
            Q3DDL.SelectedValue != "Unselected" ||
            Q4DDL.SelectedValue != "Unselected" ||
            (Q5Text.Text.Trim().Length > 0 && Q5Text.Text.Trim().Length < 250) ||
            (AgeDDL.SelectedIndex != 0 && AgeDDL.SelectedIndex != 6) ||
            (GenderDDL.SelectedIndex != 0 && GenderDDL.SelectedIndex != 4) ||
            (ContactDDL.SelectedIndex != 0 && ContactDDL.SelectedIndex != 3)
            )
        {
            //if it has, create a new survey ID for inserting into the database
            int       newSurveyID;
            SurveyDTO newSurvey = new SurveyDTO();

            //insert the survey for todays date
            newSurvey.date = DateTime.Today;
            #region Age
            //get the chosen age range, or set it to prefer not to answer
            if (AgeDDL.SelectedIndex > 0 && AgeDDL.SelectedIndex < 6)
            {
                newSurvey.agegroupid = int.Parse(AgeDDL.SelectedValue);
            }
            else
            {
                newSurvey.agegroupid = 6;
            }
            #endregion

            #region Gender
            //get the chosen gender value, or set it to preferred to not answer
            if (GenderDDL.SelectedIndex > 0 && GenderDDL.SelectedIndex < 4)
            {
                newSurvey.genderid = int.Parse(GenderDDL.SelectedValue);
            }
            else
            {
                newSurvey.genderid = 4;
            }
            #endregion

            #region First Name
            //check that the value is within the database contraint of 40 characters
            if (FirstName.Value.Length > 0 && FirstName.Value.Length <= 40)
            {
                newSurvey.firstname = FirstName.Value;
            }
            else
            {
                //check that there is a value, or show an error message to the user
                if (FirstName.Value.Length == 0)
                {
                    newSurvey.firstname = "";
                }
                else
                {
                    ErrorMSG.Text += "\nYour first name can not be longer than 40 characters. Please try again.";
                }
            }
            #endregion

            #region Bed Number

            /*check that the contact is for in person,
             * and that bed number has a value which is less than 10 characters.
             */
            if (ContactDDL.SelectedIndex == 1 && (BedNumber.Value.ToString().Length > 0 && BedNumber.Value.ToString().Length < 6))
            {
                newSurvey.bednaumber = RoomNumber.Value + "-" + BedNumber.Value;
            }
            else
            {
                //set the value to null, or show the error message
                if (ContactDDL.SelectedIndex == 1 && BedNumber.Value.ToString().Length > 10)
                {
                    ErrorMSG.Text += "Bed number cannot be longer than 4 characters. Please try again.";
                }
                else
                {
                    newSurvey.bednaumber = null;
                }
            }
            #endregion

            #region Phone Number
            if (ContactDDL.SelectedIndex == 2)
            {
                if (regex.Match(PhoneNumber.Value).Success)
                {
                    newSurvey.phonenumber = PhoneNumber.Value;
                }
                else if (regex.Match(PhoneNumber.Value).Success == false)
                {
                    ContactErr.Text += "Your Phone number must be in the following format for us to contact you: 555-555-5555 or 1-555-555-5555. (# = a number)";
                }
            }
            #endregion

            #region Preferred Contact
            // get the contact preferences, or set it to default of prefer to not be contacted
            if (ContactDDL.SelectedIndex > 0)
            {
                if (ContactDDL.SelectedIndex == 1)
                {
                    //if they chose to be contacted, make sure they fill out the necessary fields
                    if (FirstName.Value.Trim().Length == 0 || BedNumber.Value.Trim().Length == 0 || BedNumber.Value.Trim().Length == 0)
                    {
                        ContactErr.Text = "<br>Please make sure you are filling out all fields if you want to be contacted.<br> Otherwise, please choose not to be contacted.<br>";
                    }

                    if (FirstName.Value.Trim().Length == 0)
                    {
                        ContactErr.Text += "<br>Enter your first name.";
                    }
                    if (RoomNumber.Value.Trim().Length == 0)
                    {
                        ContactErr.Text += "<br>Enter your room number (##-##) found at the bottom of your meal/order chit";
                    }
                    if (BedNumber.Value.Trim().Length == 0)
                    {
                        ContactErr.Text += "<br>Enter your bed number";
                    }
                    if (FirstName.Value.Trim().Length > 0 && RoomNumber.Value.Trim().Length > 0 && BedNumber.Value.Trim().Length > 0)
                    {
                        newSurvey.preferredcontact = ContactDDL.SelectedValue;
                    }
                }
                else if (ContactDDL.SelectedIndex == 2)
                {
                    if (FirstName.Value.Trim().Length == 0)
                    {
                        ContactErr.Text += "<br>Enter Your preferred first name";
                    }
                    else if (PhoneNumber.Value.Trim().Length == 0)
                    {
                        ContactErr.Text += "<br>Enter The best phone number to reach you";
                    }
                    else if (FirstName.Value.Trim().Length > 0 && PhoneNumber.Value.Trim().Length > 0)
                    {
                        newSurvey.preferredcontact = ContactDDL.SelectedValue;
                    }
                }
            }
            else
            {
                newSurvey.preferredcontact = "Prefer Not to Be Contacted";
            }
            #endregion

            #region Contacted Yes/No
            if (ContactDDL.SelectedIndex > 0 && ContactDDL.SelectedIndex < 3)
            {
                newSurvey.contactedyn = false;
            }
            else
            {
                newSurvey.contactedyn = null;
            }
            #endregion

            #region Respondent Type ID
            //get the chosen respondent type, an error will display from the required field on the page
            if (ConsumerTypeDDL.SelectedIndex > 0)
            {
                newSurvey.respondenttypeid = int.Parse(ConsumerTypeDDL.SelectedValue);
            }
            #endregion

            #region Unit ID
            //get the chosen unit, an error will display from the required field on the page
            if (UnitListDDL.SelectedIndex > 0)
            {
                newSurvey.unitid = int.Parse(UnitListDDL.SelectedValue);
            }
            #endregion

            //check that there is an error message
            if (ErrorMSG.Text == "" && ContactErr.Text == "")
            {
                //save the new survey ID for the next step - survey answers
                newSurveyID = surveyCont.AddSurvey(newSurvey);

                //Insert -9 questions- into SurveyAnswer, as long as they have an answer
                if (Q1ADDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q1ADDL.SelectedValue), Q1ALabel.Text, Q1ADDL.SelectedItem.Text);
                }
                if (Q1BDDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q1BDDL.SelectedValue), Q1BLabel.Text, Q1BDDL.SelectedItem.Text);
                }
                if (Q1CDDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q1CDDL.SelectedValue), Q1CLabel.Text, Q1CDDL.SelectedItem.Text);
                }
                if (Q1DDDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q1DDDL.SelectedValue), Q1DLabel.Text, Q1DDDL.SelectedItem.Text);
                }
                if (Q1EDDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q1EDDL.SelectedValue), Q1ELabel.Text, Q1EDDL.SelectedItem.Text);
                }
                if (Q2DDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q2DDL.SelectedValue), Q2Label.Text.Substring(3), Q2DDL.SelectedItem.Text);
                }
                if (Q3DDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q3DDL.SelectedValue), Q3Label.Text.Substring(3), Q3DDL.SelectedItem.Text);
                }
                if (Q4DDL.SelectedValue != "Unselected")
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, int.Parse(Q4DDL.SelectedValue), Q4Label.Text.Substring(3), Q4DDL.SelectedItem.Text);
                }
                if (Q5Text.Text.Length > 0 && !string.IsNullOrWhiteSpace(Q5Text.Text.Trim()))
                {
                    surveyAnswerCont.AddSurveyAnswer(newSurveyID, 39, Q5Label.Text.Substring(3), Q5Text.Text.Trim());
                }

                //redirect to thank you page - > survey submited
                Response.Redirect("thankYou.aspx?accesscode=codeword1");
            }
        }
        else if (Q5Text.Text.Trim().Length > 250)
        {
            ErrorMSG.Text += "<br>Additional information about your meal can not be longer than 250 characters.";
        }
        else
        {
            //redirect to thank you page -> no questions answered
            Response.Redirect("thankYou.aspx?accesscode=codeword2");
        }
    }
        private void buttonSend_Click(object sender, RoutedEventArgs e)
        {
            if (baddoc.IsChecked == true)
            {
                survey.DoctorGrade = Grade.BAD;
            }
            else if (gooddoc.IsChecked == true)
            {
                survey.DoctorGrade = Grade.GOOD;
            }
            else if (verygooddoc.IsChecked == true)
            {
                survey.DoctorGrade = Grade.VERYGOOD;
            }
            else
            {
                survey.DoctorGrade = Grade.EXCELLENT;
            }

            if (badstaff.IsChecked == true)
            {
                survey.StaffGrade = Grade.BAD;
            }
            else if (goodstaff.IsChecked == true)
            {
                survey.StaffGrade = Grade.GOOD;
            }
            else if (verygoodstaff.IsChecked == true)
            {
                survey.StaffGrade = Grade.VERYGOOD;
            }
            else
            {
                survey.StaffGrade = Grade.EXCELLENT;
            }

            if (badprivacy.IsChecked == true)
            {
                survey.PrivacyGrade = Grade.BAD;
            }
            else if (goodprivacy.IsChecked == true)
            {
                survey.PrivacyGrade = Grade.GOOD;
            }
            else if (verygoodprivacy.IsChecked == true)
            {
                survey.PrivacyGrade = Grade.VERYGOOD;
            }
            else
            {
                survey.PrivacyGrade = Grade.EXCELLENT;
            }

            survey.Content = comment.Text;

            if (searchSurveyForPatient != null)
            {
                surveyController.EditSurvey(survey);
                HomePageWindow homePageWindow = new HomePageWindow();
                homePageWindow.Show();
                this.Close();
                SuccessfulSendSurvey successfulSendSurvey = new SuccessfulSendSurvey();
                successfulSendSurvey.Show();
            }
            else
            {
                survey.JmbgOfPatient = MainWindow.patient.Jmbg;
                surveyController.AddSurvey(survey);
                HomePageWindow homePageWindow = new HomePageWindow();
                homePageWindow.Show();
                this.Close();
                SuccessfulSendSurvey successfulSendSurvey = new SuccessfulSendSurvey();
                successfulSendSurvey.Show();
            }
        }