Exemplo n.º 1
0
        public async Task CreateAsync_Should_ReturnCorrectQuiz()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            using (var context = new DataContext(options))
            {
                const string userId  = "test";
                var          service = new QuizService(context);

                context.Questions.Add(new Question()
                {
                    Id = 1
                });
                context.Questions.Add(new Question()
                {
                    Id = 2
                });
                context.Questions.Add(new Question()
                {
                    Id = 3
                });
                context.Questions.Add(new Question()
                {
                    Id = 4
                });
                context.Questions.Add(new Question()
                {
                    Id = 5
                });
                context.SaveChanges();

                var quizId = await service.CreateAsync(userId);

                quizId.Should().Be(1);

                var questionQuizzes = context.QuestionQuizzes.Where(x => x.QuizId == quizId).ToList();
                questionQuizzes.Count.Should().Be(5);
            }
        }