Exemple #1
0
        public async System.Threading.Tasks.Task GetAnswersForQuestion()
        {
            using var dbContext = this.GetDbContext();
            using var unity     = new UnitofWork(dbContext);
            var guid = Guid.NewGuid();

            dbContext.Questions.Add(new Models.Questions {
                Id = guid, Question = "question1", Tags = "c#"
            });
            dbContext.Questions.Add(new Models.Questions {
                Id = Guid.NewGuid(), Question = "question2", Tags = "asp"
            });
            dbContext.Questions.Add(new Models.Questions {
                Id = Guid.NewGuid(), Question = "question3", Tags = "azure"
            });
            await dbContext.SaveChangesAsync();

            dbContext.Answers.Add(new Models.Answers {
                Id = Guid.NewGuid(), Answer = "answer1", QuestionID = guid
            });
            dbContext.Answers.Add(new Models.Answers {
                Id = Guid.NewGuid(), Answer = "answer2", QuestionID = guid
            });
            dbContext.Answers.Add(new Models.Answers {
                Id = Guid.NewGuid(), Answer = "answer3", QuestionID = guid
            });

            await dbContext.SaveChangesAsync();

            var service = new AnswersController(unity);
            var result  = (IList <Models.Answers>) await service.GetAnswersByquestionAsync("question1");

            Xunit.Assert.NotNull(result);
            Xunit.Assert.Equal(3, result.Count);
        }