Exemplo n.º 1
0
        public async Task <IActionResult> CreateSurvey([FromBody] Survey survey)
        {
            survey.CreateDate = DateTime.Now;
            survey            = await _surveySvc.CreateSurvey(survey);

            return(Json(survey));
        }
Exemplo n.º 2
0
        public async Task CRUD_Success()
        {
            // arrange
            var survey = new Survey
            {
                Name = "Test survey",
                Status = (int)SurveyStatusEnum.New,
                CreatorName = "test creator",
                Questions = new List<SurveyQuestion>()
                {
                    new SurveyQuestion()
                    {
                        Index = 1,
                        QuestionType = 1,
                        Text = "Q1"
                    },
                    new SurveyQuestion()
                    {
                        Index = 2,
                        QuestionType = 1,
                        Text = "Q2"
                    }
                }
            };

            // Create
            survey = await _testObj.CreateSurvey(survey);

            Assert.False(string.IsNullOrEmpty(survey.Id));
            _sequenceSvcMock.Verify(
                x => x.GetNextValue(It.IsAny<string>()),
                Times.Exactly(survey.Questions.Count())
            );

            // Update
            survey.Questions = new List<SurveyQuestion>()
            {
                new SurveyQuestion() { Index = 1, QuestionType = 1, Text = "Q3" }
            };
            survey = await _testObj.UpdateSurvey(survey);
            survey = await _testObj.GetSurvey(survey.Id);

            Assert.NotNull(survey);
            Assert.Single(survey.Questions);

            // Remove
            await _testObj.CloseSurvey(survey.Id);
            survey = await _testObj.GetSurvey(survey.Id);

            Assert.Equal((int)SurveyStatusEnum.Closed, survey.Status);
        }