示例#1
0
        private void FixModelAndModelState(QuestionUi questionUi)
        {
            if (questionUi == null)
            {
                return;
            }

            ModelState.Remove("Id");
        }
示例#2
0
        public async Task <ActionResult> Create(QuestionUi question)
        {
            FixModelAndModelState(question);
            if (question != null && ModelState.IsValid)
            {
                await _questionService.AddNewQuestion(question.ConvertToDomain());

                return(RedirectToAction("Index"));
            }

            return(View(question));
        }
示例#3
0
        public async Task <ActionResult> Edit(QuestionUi question)
        {
            var personQualities = await _personQualityService.GetPersonQualities();

            if (ModelState.IsValid)
            {
                await _questionService.UpdateQuestion(question.ConvertToDomain());

                return(RedirectToAction("Index"));
            }

            ViewBag.PersonQualities = personQualities;
            return(View(question));
        }
        public async Task Edit()
        {
            // Действие
            var result = (ViewResult)await _controller.Index(null);

            var questions   = (List <Question>)result.Model;
            var oldQuestion = questions.First();
            var question    = new QuestionUi
            {
                Id              = oldQuestion.Id,
                Name            = "Updated question",
                Text            = oldQuestion.Text,
                QuestionOptions =
                    new List <QuestionOptionUI>
                {
                    new QuestionOptionUI
                    {
                        Number = 0,
                        Text   = "Brand new option",
                        PersonQualitiesWithScores =
                            new List <PersonQualityIdWithScore>
                        {
                            new PersonQualityIdWithScore
                            {
                                PersonQualityId = "PersonQuality1",
                                Score           = -2
                            }
                        }
                    }
                }
            };
            var editResult = await _controller.Edit(question) as RedirectToRouteResult;

            result = (ViewResult)await _controller.Details(oldQuestion.Id);

            var questionAfterEdit = (Question)result.Model;

            // Утверждение
            Assert.IsNotNull(editResult);
            Assert.IsNotNull(questions);
            Assert.IsNotEmpty(questions);
            Assert.AreEqual("Updated question", questionAfterEdit.Name);
            Assert.AreEqual(
                "PersonQuality1",
                questionAfterEdit.Options.Single().PersonQualitiesWithScores.Single().PersonQualityId);
        }