public void Given_I_Call_GetSurvey_Then_I_Get_The_Correct_Survey_Returned(string instrument1Name) { //arrange var survey1Mock = new Mock <ISurvey>(); survey1Mock.Setup(s => s.Name).Returns(instrument1Name); const string instrument2Name = "Instrument2"; var survey2Mock = new Mock <ISurvey>(); survey2Mock.Setup(s => s.Name).Returns(instrument2Name); var surveyItems = new List <ISurvey> { survey1Mock.Object, survey2Mock.Object }; _surveyCollectionMock = new Mock <ISurveyCollection>(); _surveyCollectionMock.Setup(s => s.GetEnumerator()).Returns(() => surveyItems.GetEnumerator()); _serverParkMock.Setup(s => s.Surveys).Returns(_surveyCollectionMock.Object); //act var result = _sut.GetSurvey(_connectionModel, instrument1Name, _serverParkName); //assert Assert.NotNull(result); Assert.IsInstanceOf <ISurvey>(result); Assert.AreSame(survey1Mock.Object, result); Assert.AreEqual(instrument1Name, result.Name); }
public IActionResult Get(string no) { var survey = _survey.GetSurvey(no); if (survey == null) { return(NotFound()); } return(new ObjectResult(survey)); }
public void TestSurveyCRUD() { SurveyService service = new SurveyService(); string surveyName = "MySurvey"; DTO.Survey survey = new DTO.Survey() { Name = surveyName }; survey.Questions.Add(new Question() { AnswerType = AnswerTypes.boolean, Sequence = 1, Text = "Do you like this question?" }); List <PossibleAnswer> answers = new List <PossibleAnswer>(); answers.Add(new PossibleAnswer() { Answer = "1", Sequence = 1 }); answers.Add(new PossibleAnswer() { Answer = "2", Sequence = 2 }); survey.Questions.Add(new Question() { AnswerType = AnswerTypes.list, Sequence = 2, Text = "If you like oranges press one. If you like apples press two.", PossibleAnswers = answers }); service.InsertSurvey(survey); DTO.Survey expectedSurvey = service.GetSurvey(surveyName); Assert.IsNotNull(expectedSurvey, "Could not find survey with a name of " + surveyName); Assert.AreEqual(expectedSurvey.Name, survey.Name, "Survey names do not match"); string userId = "1234"; int uid = service.InsertUser("joe tester", userId, "0001"); User user = service.GetUserByUserId(userId); Assert.IsNotNull(user, "Could not find user with ID of " + userId); service.InsertResponse("No", expectedSurvey.Questions[0].Id, user.Id); user = service.GetUserByUserId(userId); Assert.IsNotNull(user, "Could not find user with ID of " + userId + " after adding response to question."); Assert.AreEqual(1, user.SurveyResponses.Count, "Expected 1 survey response but there are " + user.SurveyResponses.Count.ToString()); }
public async Task <IActionResult> SubmitSurvey(string id) { Survey survey = await SurveyService.GetSurvey(id); List <String> selectedRadios = new List <string>(); Dictionary <int, String> selectedOptions = new Dictionary <int, String>(); var i = 0; foreach (var question in survey.Questions) { i++; var qns = "qns" + i; selectedRadios.Add(qns); } // Obtains selected radio item value and stores in dictionary var j = 0; foreach (String radio in selectedRadios) { selectedOptions.Add(j, Request.Form[radio]); j++; } GenerateResult generateResult = new GenerateResult(selectedOptions, survey.Set); float score = await generateResult.GetScore(); switch (survey.Type) { case "openness": break; case "conscientiousness": break; case "extraversion": break; case "agreeableness": break; case "neuroticism": break; } ViewBag.score = score; ViewBag.message = generateResult.GetMessage(score); return(View("Result")); }
public void GetSurvey_ValidRequestNoAnswers_ShouldReturnTemplate() { var expected = new Survey { Template = "template", Answers = "", Submitted = false }; mockSurveyRepository.Setup(repository => repository.GetSurveyByUid("testUid")).Returns(expected); var actual = surveyService.GetSurvey("testUid"); actual.Should().Be(expected.Template); }
public WelcomePage(User user) { InitializeComponent(); WelcomeLabel.Text = "Welcome, " + user.Name + "!"; // Populate surveys to listview var surveys = AsyncContext.Run(SurveyService.GetSurveys); var tableItems = new List <string>(); for (var i = 0; i < surveys.Count; i++) { tableItems.Add(surveys[i].No + " " + surveys[i].Title); } SurveyListView.ItemsSource = tableItems; SurveyListView.ItemSelected += async(sender, e) => { // Play sound effect var assembly = typeof(AdventureLearn).GetTypeInfo().Assembly; Stream audioStream = assembly.GetManifestResourceStream("AdventureLearn.Sounds." + "button.mp3"); var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current; player.Load(audioStream); player.Play(); if (e.SelectedItem == null) { return; } SurveyListView.SelectedItem = null; // deselect row string selectedItem = (string)e.SelectedItem; string id = selectedItem.Split(' ')[0]; Survey survey = await SurveyService.GetSurvey(id); await Navigation.PushAsync(new SurveyPage(survey, user)); }; }
public override CallFlow BuildCallFlow() { CallFlow flow = new CallFlow(); //Create Service/Domain Layer for accessing survey information SurveyService service = new SurveyService(); //Get a survey named MySurvey Service.DTO.Survey survey = service.GetSurvey("MySurvey"); //If we did not get a survey back there is an error. Tell the caller. if (survey == null) { flow.AddState(new VoiceState("noSurvey", new Exit("noSurvey", "Error finding survey in database. Goodbye.")), true); return(flow); } //If we got here then we have a survey from the database. //Create a greeting and on the exit action from this state //get the user we seeded from the database. In a real survey //application we would prompt the user for their id and pin //to identify them. State greeting = new VoiceState("greeting", new Say("greeting", "Please take our short survey")) .AddOnExitAction(delegate(CallFlow cf, State state, Event e) { SurveyService sservice = new SurveyService(); User user = sservice.GetUserByUserId("001"); int uid = 0; if (user != null) { uid = user.Id; } cf.Ctx.SetGlobal <int>("userId", uid); }); flow.AddState(greeting, true); State prevState = greeting; int questionNum = 0; int questionCount = survey.Questions.Count; //Iterate through the survey questions and add them to our callflow. foreach (Question question in survey.Questions) { questionNum++; string questionId = question.Id.ToString(); bool lastQuestion = questionNum == questionCount; prevState.AddTransition("continue", questionId, null); Ask askQuestion = new Ask(questionId); askQuestion.initialPrompt.Add(new Prompt(question.Text)); if (question.AnswerType == AnswerTypes.boolean) { askQuestion.grammar = new Grammar(new BuiltinGrammar(BuiltinGrammar.GrammarType.boolean)); } else { askQuestion.grammar = new Grammar("possibleAnswers", question.PossibleAnswers.Select(p => p.Answer).ToList()); } State questionState = ViewStateBuilder.Build(questionId, askQuestion); questionState.AddOnExitAction(delegate(CallFlow cf, State state, Event e) { SurveyService sservice = new SurveyService(); string response = state.jsonArgs; int userId = cf.Ctx.GetGlobalAs <int>("userId"); int qId = Int32.Parse(state.Id); sservice.InsertResponse(response, qId, userId); }); flow.AddState(questionState); prevState = questionState; } //Take the last question in the survey and add a transition to the application exit. prevState.AddTransition("continue", "goodbye", null); //Tell the caller goodbye and hangup flow.AddState(new VoiceState("goodbye", new Exit("goodbye", "Thank you for taking our survey. Goodbye."))); return(flow); }
public async Task <IActionResult> TakeSurvey(string id) { Survey survey = await SurveyService.GetSurvey(id); return(View("Survey", survey)); }