Beispiel #1
0
        public async Task <ActionResult <IEnumerable <AnswerModel> > > Get()
        {
            var answers = await _answerManager.Get();

            var answersModel = _mapper.Map <IEnumerable <AnswerModel> >(answers);

            return(Ok(answersModel));
        }
Beispiel #2
0
        public async Task WhenGetAnswer_ThenGetSuccessful()
        {
            //?Given
            var answerList = new List <Answer>
            {
                new Answer
                {
                    User           = "******",
                    Id             = "1234",
                    AnswerSelected = new List <AnswerSelected>
                    {
                        new AnswerSelected
                        {
                            IdOption            = "1234",
                            OptionDescription   = "this is a description",
                            IdQuestion          = "1234",
                            QuestionDescription = "this is a decription"
                        }
                    }
                }
            };

            _mockAnswerReposotory.Setup(x => x.Get())
            .ReturnsAsync(answerList);

            //?When
            var result = await _answerManager.Get();

            //?Then
            var expected = answerList.FirstOrDefault();
            var actual   = result.ToList().FirstOrDefault();

            Assert.Equal(expected.Id, actual.Id);
            Assert.Equal(expected.User, actual.User);
            Assert.Equal(expected.AnswerSelected.FirstOrDefault().IdOption, actual.AnswerSelected.FirstOrDefault().IdOption);
            Assert.Equal(expected.AnswerSelected.FirstOrDefault().OptionDescription, actual.AnswerSelected.FirstOrDefault().OptionDescription);
            Assert.Equal(expected.AnswerSelected.FirstOrDefault().IdQuestion, actual.AnswerSelected.FirstOrDefault().IdQuestion);
            Assert.Equal(expected.AnswerSelected.FirstOrDefault().QuestionDescription, actual.AnswerSelected.FirstOrDefault().QuestionDescription);

            _mockAnswerReposotory.Verify();
        }