public ResultVm CheckAnswer(int idOfAnswer, string username)
        {
            var      answer   = _categoryAndQuestionRepo.ReturnAnswerById(idOfAnswer);
            ResultVm resultVm = new ResultVm();

            if (answer.IsCorrect == true)
            {
                resultVm.IsGood = true;
                var questionIdWithGoodRespondAndUsername = new QuestionsOnWhichUsersRespondCorrectly()
                {
                    UserName   = username,
                    QuestionId = answer.QuestionId
                };
                _categoryAndQuestionRepo.SaveIdOfQuestionWhichUserRespondedCorrectly(questionIdWithGoodRespondAndUsername);
            }
            else
            {
                resultVm.IsGood = false;
            }
            return(resultVm);
        }
        public void TestOfDrawingQuestionWhenUserDoesntAnswerOnEveryQuestion()
        {
            var returnedQuestions = new List <Question>()
            {
                new Question()
                {
                    Id           = 1,
                    QuestionText = "Ile to jest 25 + 25?",
                    CategoryId   = 2,
                    IsAccepted   = true,
                    Category     = new Category()
                    {
                        Id = 1, IsAccepted = true, Name = "Matematyka"
                    },
                    Answers = new List <Answer>()
                    {
                        new Answer()
                        {
                            Id = 1, AnswerText = "50", IsAccepted = true, IsCorrect = true, QuestionId = 1
                        },
                        new Answer()
                        {
                            Id = 2, AnswerText = "150", IsAccepted = true, IsCorrect = false, QuestionId = 1
                        }
                    }
                },
                new Question()
                {
                    Id           = 2,
                    QuestionText = "Ile wynosi pierwiastek kwadratowty z 64?",
                    CategoryId   = 2,
                    IsAccepted   = true,
                    Category     = new Category()
                    {
                        Id = 1, IsAccepted = true, Name = "Matematyka"
                    },
                    Answers = new List <Answer>()
                    {
                        new Answer()
                        {
                            Id = 1, AnswerText = "8", IsAccepted = true, IsCorrect = true, QuestionId = 2
                        },
                        new Answer()
                        {
                            Id = 2, AnswerText = "4", IsAccepted = true, IsCorrect = false, QuestionId = 2
                        }
                    }
                }
            };
            var questionWithGoodAnswer = new QuestionsOnWhichUsersRespondCorrectly()
            {
                Id = 1, UserName = "******", QuestionId = 2
            };
            var config = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new MappingProfile());
            });

            var mapper  = config.CreateMapper();
            var catRepo = new Mock <ICategoryAndQuestionRepository>();

            catRepo.Setup(c => c.GetQuestionIdsWhichUserRespondCorrectly(questionWithGoodAnswer.UserName))
            .Returns(new List <int>()
            {
                questionWithGoodAnswer.QuestionId
            });
            catRepo.Setup(c => c.GetQuestionsByCategoryId(returnedQuestions[0].CategoryId)).Returns(returnedQuestions.AsQueryable());
            var catServ = new CategoryAndQuestionService(catRepo.Object, mapper);

            //Act
            var question = catServ.ShowRandomlySelectedQuestion(returnedQuestions[0].CategoryId, questionWithGoodAnswer.UserName);

            //Assert
            Assert.NotNull(question);
            question.Should().BeOfType(typeof(QuestionVm));
        }
Beispiel #3
0
 public void SaveIdOfQuestionWhichUserRespondedCorrectly(QuestionsOnWhichUsersRespondCorrectly questionsOnWhichUsersRespondCorrectly)
 {
     _context.QuestionsWithCorrectlyResponds.Add(questionsOnWhichUsersRespondCorrectly);
     _context.SaveChanges();
 }