Beispiel #1
0
        public JsonResult SubmitAnswer(SubmitAnswerParameter parameter)
        {
            UserAnswerService service = new UserAnswerService();
            var model = service.SubmitAnswer(parameter);

            return(Json(model));
        }
Beispiel #2
0
        public void Invoke_AddMethod_UserAnswerRepo_OnlyForAnsweredQuestions()
        {
            // Arrange
            var fakeUserId = "userId";

            var fakeAnsweredQuestionDto = new QuestionResponseDto()
            {
                Answers = new Guid().ToString()
            };
            var fakeNotAnsweredQuestionDto = new QuestionResponseDto();

            var fakeQuestionResponseDtos = new List <QuestionResponseDto>()
            {
                fakeAnsweredQuestionDto, fakeNotAnsweredQuestionDto
            };

            var mockUserAnswerRepo  = new Mock <IDataRepository <UserAnswer> >();
            var dataSaverStub       = new Mock <IDataSaver>();
            var mappingProviderStub = new Mock <IMappingProvider>();
            var answerRepoStub      = new Mock <IDataRepository <Answer> >();

            var userAnswerService = new UserAnswerService(mockUserAnswerRepo.Object, dataSaverStub.Object, mappingProviderStub.Object, answerRepoStub.Object);

            // Act
            userAnswerService.AddAnswersToUser(fakeUserId, fakeQuestionResponseDtos);

            // Assert
            mockUserAnswerRepo.Verify(uar => uar.Add(It.IsAny <UserAnswer>()), Times.Once);
        }
        public void Throw_ArgumentNullException_WhenUserId_IsNullOrEmpty()
        {
            // Arrange
            var fakeUserId = "";
            var fakeTestId = new Guid();

            var userAnswerRepoStub  = new Mock <IDataRepository <UserAnswer> >();
            var dataSaverStub       = new Mock <IDataSaver>();
            var mappingProviderStub = new Mock <IMappingProvider>();
            var answerRepoStub      = new Mock <IDataRepository <Answer> >();

            var userAnswerService = new UserAnswerService(userAnswerRepoStub.Object, dataSaverStub.Object, mappingProviderStub.Object, answerRepoStub.Object);

            Action executingGetAnswersForTestDoneByUser = () => userAnswerService.GetAnswersForTestDoneByUser(fakeUserId, fakeTestId.ToString());

            // Act & Assert
            Assert.ThrowsException <ArgumentNullException>(executingGetAnswersForTestDoneByUser);
        }
Beispiel #4
0
        public void Invoke_SaveChangesMethod_DataSaver()
        {
            // Arrange
            string fakeUserId = "userId";

            var fakeQuestionResponseDtos = new List <QuestionResponseDto>();

            var userAnswerRepoStub  = new Mock <IDataRepository <UserAnswer> >();
            var mockDataSaver       = new Mock <IDataSaver>();
            var mappingProviderStub = new Mock <IMappingProvider>();
            var answerRepoStub      = new Mock <IDataRepository <Answer> >();

            var userAnswerService = new UserAnswerService(userAnswerRepoStub.Object, mockDataSaver.Object, mappingProviderStub.Object, answerRepoStub.Object);

            // Act
            userAnswerService.AddAnswersToUser(fakeUserId, fakeQuestionResponseDtos);

            // Assert
            mockDataSaver.Verify(ds => ds.SaveChanges(), Times.Once);
        }
        public void Invoke_MappingProvider_ProjectTo_With_ResultsFrom_UserAnswerRepo()
        {
            // Arrange
            var fakeUserId = "userId";
            var fakeTestId = new Guid();

            var fakeUserAnswer = new UserAnswer()
            {
                UserId = fakeUserId,
                Answer = new Answer()
                {
                    Question = new Question()
                    {
                        Test = new Test()
                        {
                            Id = fakeTestId
                        }
                    }
                }
            };
            var fakeUserAnswers = new List <UserAnswer>()
            {
                fakeUserAnswer
            }.AsQueryable();

            var userAnswerRepoStub  = new Mock <IDataRepository <UserAnswer> >();
            var dataSaverStub       = new Mock <IDataSaver>();
            var mockMappingProvider = new Mock <IMappingProvider>();
            var answerRepoStub      = new Mock <IDataRepository <Answer> >();

            var userAnswerService = new UserAnswerService(userAnswerRepoStub.Object, dataSaverStub.Object, mockMappingProvider.Object, answerRepoStub.Object);

            userAnswerRepoStub.SetupGet(uar => uar.All).Returns(fakeUserAnswers);

            // Act
            userAnswerService.GetAnswersForTestDoneByUser(fakeUserId, fakeTestId.ToString());

            // Assert
            mockMappingProvider.Verify(mp => mp.ProjectTo <UserAnswerDto>(It.IsAny <IQueryable <UserAnswer> >()), Times.Once);
        }
        public void Throw_ArgumentException_When_NoAnswers_AreFound()
        {
            // Arrange
            var fakeUserId = "userId";
            var fakeTestId = new Guid();

            var fakeUserAnswers = new List <UserAnswer>()
            {
            }.AsQueryable();

            var userAnswerRepoStub  = new Mock <IDataRepository <UserAnswer> >();
            var dataSaverStub       = new Mock <IDataSaver>();
            var mappingProviderStub = new Mock <IMappingProvider>();
            var answerRepoStub      = new Mock <IDataRepository <Answer> >();

            var userAnswerService = new UserAnswerService(userAnswerRepoStub.Object, dataSaverStub.Object, mappingProviderStub.Object, answerRepoStub.Object);

            userAnswerRepoStub.SetupGet(uar => uar.All).Returns(fakeUserAnswers);

            Action executingGetAnswersForTestDoneByUser = () => userAnswerService.GetAnswersForTestDoneByUser(fakeUserId, fakeTestId.ToString());

            // Act & Assert
            Assert.ThrowsException <ArgumentException>(executingGetAnswersForTestDoneByUser);
        }