public async Task ReturnCreatedSurveyUserOnCreateWhenCorrectModel()
        {
            // Arrange
            var answers = new Faker <AnswerCreateModel>()
                          .RuleFor(s => s.UserId, v => ++ v.IndexVariable)
                          .RuleFor(s => s.OptionId, v => v.IndexVariable)
                          .Generate();

            var expected = new Faker <AnswersBaseModel>()
                           .RuleFor(s => s.Id, v => ++ v.IndexVariable)
                           .RuleFor(s => s.UserId, v => v.IndexVariable)
                           .RuleFor(s => s.OptionId, v => v.IndexVariable)
                           .Generate();

            _mockService.Setup(x => x.Insert(It.IsAny <AnswerCreateModel>()))
            .ReturnsAsync(expected)
            .Verifiable();

            // Act
            var result = await _controller.Post(answers);

            // Assert
            result.Should().BeOfType <CreatedResult>();

            var model = result as CreatedResult;

            model?.Value.Should().Be(1);
            model?.Location.Should().Be("/api/Players/1");
        }
Ejemplo n.º 2
0
        private async Task <JsonResult> ExecutePost(Models.TransferObjects.UpdateQuizAttemptStatusResult status)
        {
            const int attemptId = 5;
            const int userId    = 2;

            var quizAttemptsManager = new Mock <IQuizAttemptManager>();

            quizAttemptsManager.Setup(c => c.InsertAnswerAsync(userId, attemptId, It.IsAny <Models.TransferObjects.Answer>()))
            .Returns <int, int, Models.TransferObjects.Answer>((u, a, answer) =>
                                                               Task.FromResult(status));
            var controller = new AnswersController(quizAttemptsManager.Object);

            controller.Token = new Models.TransferObjects.AuthToken
            {
                Token      = "token",
                UserId     = userId,
                ValidUntil = DateTime.Now.AddDays(1),
                IsVerified = true
            };
            var result = await controller.Post(5,
                                               new Models.TransferObjects.Answer
            {
                TimeSpent  = 10,
                QuestionId = 3,
                Options    = new List <int> {
                    8, 9
                }
            });

            return(result);
        }
Ejemplo n.º 3
0
        public async Task PostThrowsError()
        {
            var quizAttemptsManager = new Mock <IQuizAttemptManager>();
            var controller          = new AnswersController(quizAttemptsManager.Object);

            var result = await controller.Post(5,
                                               new Models.TransferObjects.Answer
            {
                TimeSpent  = 10,
                QuestionId = 3,
                Options    = new List <int> {
                    8, 9
                }
            });

            Assert.IsNotNull(result);
        }