public void Setup()
 {
     _talksApi = A.Fake<ITalksApi>();
     _expectedDateTime = DateTime.Now;
     _easyAccessKey = "talk_key";
     _viewModel = CreateFeedbackViewModelStub(_easyAccessKey);
     _expectedResponse = CreateFeedbackViewModelResponse(_viewModel);
 }
Exemplo n.º 2
0
        public IActionResult Index(FeedbackFormViewModel feedbackFormAnswers)
        {
            var feedbackSubmissionResponse = PostFeedbackAnswers(feedbackFormAnswers);

            if (feedbackSubmissionResponse.StatusCode != System.Net.HttpStatusCode.Created)
            {
                feedbackFormAnswers.ErrorMessage = feedbackSubmissionResponse.ReasonPhrase;
                return RedirectToAction("Index", "Feedback", feedbackFormAnswers);
            }
            return View("_feedbackSavedSuccessfully");
            // Can't just redirect, need to forward an error somehow!!
        }
Exemplo n.º 3
0
        private FeedbackFormViewModel MapToViewModel(FeedbackForm form)
        {
            if (form.Questionnaire == null || !form.Questionnaire.Any()) return null;

            var viewModel = new FeedbackFormViewModel();
            viewModel.TalkId = form.TalkId;
            viewModel.TalkName = form.TalkName;
            viewModel.SpeakerName = form.SpeakerName;

            viewModel.Questionnaire = form.Questionnaire.Select(x => new QuestionViewModel
            {
                QuestionId = x.QuestionId,
                IsRequired = x.IsRequired,
                QuestionText = x.QuestionText,
                AnswerType = x.AnswerType,
                Answer = x.Answer
            }).ToList();

            return viewModel;
        }
Exemplo n.º 4
0
        private HttpResponseMessage PostFeedbackAnswers(FeedbackFormViewModel feedbackFormAnswers)
        {
            var easyAccessKey = feedbackFormAnswers.EasyAccessKey;

            var feedbackResponse = new FeedbackResponse
            {
                TalkId = feedbackFormAnswers.TalkId,
                ReviewerId = "",
                Questionnaire = feedbackFormAnswers.Questionnaire.Select(x => new Question
                {
                    QuestionId = x.QuestionId,
                    IsRequired = x.IsRequired,
                    QuestionText = x.QuestionText,
                    AnswerType = x.AnswerType,
                    Answer = x.Answer
                }).ToList(),
                SubmissionTime = DateTime.Now
            };

            var feedbackSubmissionResponse = _talksApi.PostFeedbackForm(easyAccessKey, feedbackResponse);
            return feedbackSubmissionResponse;
        }
        private static FeedbackFormViewModel CreateFeedbackViewModelStub(string _easyAccessKey)
        {
            var temp = TalksApiStubResponse.GetTalkByEasyAccessKey("12345");
            var viewModel = new FeedbackFormViewModel();
            viewModel.TalkId = temp.TalkId;
            viewModel.TalkName = temp.TalkName;
            viewModel.SpeakerName = temp.SpeakerName;
            viewModel.EasyAccessKey = _easyAccessKey;

            viewModel.Questionnaire = temp.Questionnaire.Select(x => new QuestionViewModel
            {
                QuestionId = x.QuestionId,
                IsRequired = x.IsRequired,
                QuestionText = x.QuestionText,
                AnswerType = x.AnswerType,
                Answer = x.Answer
            }).ToList();

            return viewModel;
        }
        private static IList<ValidationResult> CheckForValidationErrors(FeedbackController controller, FeedbackFormViewModel model)
        {
            var validationErrors = ViewModelValidation.Validate(model);

            if (validationErrors.Count > 0)
            {
                controller.ViewData.ModelState.AddModelError(nameof(model.TalkId), validationErrors[0].ErrorMessage);
            }

            return validationErrors;
        }
        private FeedbackResponse CreateFeedbackViewModelResponse(FeedbackFormViewModel model)
        {
            var response = new FeedbackResponse
            {
                TalkId = model.TalkId,
                ReviewerId = "",
                Questionnaire = model.Questionnaire.Select(x => new Question
                {
                    QuestionId = x.QuestionId,
                    IsRequired = x.IsRequired,
                    QuestionText = x.QuestionText,
                    AnswerType = x.AnswerType,
                    Answer = x.Answer
                }).ToList(),
                SubmissionTime = _expectedDateTime
            };

            return response;
        }