public void Get_TakeAllSurveys_ReturnsOkObjectResult() { // Act var result = _controller.GetSurveys(); // Assert Assert.IsType <OkObjectResult>(result); }
public void TestSurvey() { var survey = new List <SurveyEntity> { new SurveyEntity { Id = 1, Info = "{}" }, new SurveyEntity { Id = 2, Info = "{}" }, new SurveyEntity { Id = 3, Info = "{}" } }.AsQueryable(); var mockSet = new Mock <DbSet <SurveyEntity> >(); mockSet.As <IQueryable <SurveyEntity> >().Setup(m => m.Provider).Returns(survey.Provider); mockSet.As <IQueryable <SurveyEntity> >().Setup(m => m.Expression).Returns(survey.Expression); mockSet.As <IQueryable <SurveyEntity> >().Setup(m => m.ElementType).Returns(survey.ElementType); mockSet.As <IQueryable <SurveyEntity> >().Setup(m => m.GetEnumerator()).Returns(() => survey.GetEnumerator()); var mockContext = new Mock <SurveyContext>(); mockContext.Setup(c => c.Surveys).Returns(mockSet.Object); var controller = new SurveyController(mockContext.Object); var result = controller.GetSurveys() as List <SurveyEntity>; Assert.AreEqual(1, result.Count); }
/* * CREATED: H. Conant MAR 13 2018 * MODIFIED: A. Valberg MAR 28 2018 * -Updated fields after adding 2 tables (agegroup & gender) * MODIFIED: H. Conant MAR 31 2018 * -Updated gender and age to repeaters and ODSes * * RetrieveSurveys_Click() * This method runs any code it contains when the "Retrieve Surveys" button is clicked. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowInfoMessage() * MessageUserControl.ShowInfoList() * SurveyController.GetSurveys() * MessageUserControl.ShowErrorMessage() */ protected void RetrieveSurveys_Click(object sender, EventArgs e) { ResultCountLabel.Text = "0"; List <string> message = new List <string>(); SurveyRepeater.DataSource = null; SurveyRepeater.DataBind(); List <int> unitIds = new List <int>(); List <int> genders = new List <int>(); List <int> respodentIds = new List <int>(); List <int> ages = new List <int>(); DateTime dateOne = new DateTime(); DateTime dateTwo = new DateTime(); string pattern = @"^$|^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/][0-9]{4}$"; Regex reg = new Regex(pattern); Match properStartDateFormat = reg.Match(dateStart.Value); Match properEndDateFormat = reg.Match(dateEnd.Value); if (!properStartDateFormat.Success || !properEndDateFormat.Success) { message.Add("Please enter valid date(s) using the pattern mm/dd/yyyy or leave the date fields blank."); } else { if (dateStart.Value != "") { if (DateTime.TryParse(dateStart.Value, out dateOne) == false) { message.Add("Please enter a valid start date value or leave it blank."); } } if (dateEnd.Value != "") { if (DateTime.TryParse(dateEnd.Value, out dateTwo) == false) { message.Add("Please enter a valid end date value or leave it blank."); } } } if (dateStart.Value != "" && dateEnd.Value != "" && dateOne > dateTwo) { message.Add("Please ensure that the provided end date occurs after or on the same day as the provided start date."); } if (dateTwo > DateTime.Today || dateOne > DateTime.Today) { message.Add("Please select dates that are on or before today's date."); } foreach (RepeaterItem item in UnitRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenUnitID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempUntId; int.TryParse(tempHiddenField.Value, out tempUntId); unitIds.Add(tempUntId); } } if (unitIds.Count < 1) { message.Add("Please select at least one unit to filter by."); } foreach (RepeaterItem item in GenderRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenGenderID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempGenderId; int.TryParse(tempHiddenField.Value, out tempGenderId); genders.Add(tempGenderId); } } if (genders.Count < 1) { message.Add("Please select at least one gender to filter by."); } foreach (RepeaterItem item in RespondentTypeRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenRespondentID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempTypeId; int.TryParse(tempHiddenField.Value, out tempTypeId); respodentIds.Add(tempTypeId); } } if (respodentIds.Count < 1) { message.Add("Please select at least one respondent type to filter by."); } foreach (RepeaterItem item in AgeRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenAgeGroupID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempAgeId; int.TryParse(tempHiddenField.Value, out tempAgeId); ages.Add(tempAgeId); } } if (ages.Count < 1) { message.Add("Please select at least one age range to filter by."); } if (message.Count == 1) { MessageUserControl.ShowInfoMessage(message[0]); } else if (message.Count > 1) { MessageUserControl.ShowInfoList("Please address the following errors and try again: ", message); } else { try { List <ExtendedSurveyDTO> surveys = new List <ExtendedSurveyDTO>(); if (dateStart.Value == "" && dateEnd.Value == "") { surveys = surveyController.GetSurveys(unitIds, genders, ages, respodentIds); } else if (dateStart.Value == "" && dateEnd.Value != "") { dateOne = DateTime.MinValue; surveys = surveyController.GetSurveys(unitIds, genders, ages, dateOne, dateTwo, respodentIds); } else if (dateStart.Value != "" && dateEnd.Value == "") { dateTwo = DateTime.Today; dateEnd.Value = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); surveys = surveyController.GetSurveys(unitIds, genders, ages, dateOne, dateTwo, respodentIds); } else { surveys = surveyController.GetSurveys(unitIds, genders, ages, dateOne, dateTwo, respodentIds); } if (surveys.Count < 1) { MessageUserControl.ShowInfoMessage("No surveys found matching the entered search criteria."); } else { ResultCountLabel.Text = (surveys.Count).ToString(); SurveyRepeater.DataSource = surveys; SurveyRepeater.DataBind(); } } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving surveys from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } }