Example #1
0
        public async Task ReturnCreatedSurveyUserOnCreateWhenCorrectModel()
        {
            // Arrange
            var surveyUser = new Faker <SurveyUserCreate>()
                             .RuleFor(s => s.FirstName, v => v.Name.FullName())
                             .RuleFor(s => s.LastName, v => v.Name.FullName())
                             .RuleFor(s => s.DoB, v => v.Date.Between(DateTime.Today.AddYears(-18), DateTime.Today.AddYears(-23)))
                             .Generate();
            var expected = new Faker <AnswerBaseModel>()
                           .RuleFor(s => s.Id, v => ++ v.IndexVariable)
                           .RuleFor(s => s.FirstName, v => v.Name.FullName())
                           .RuleFor(s => s.DoB, v => v.Date.Between(DateTime.Today.AddYears(-18), DateTime.Today.AddYears(-23)))
                           .Generate();

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

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

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

            var model = result as CreatedResult;

            model?.Value.Should().Be(1);
            model?.Location.Should().Be("/api/Players/1");
        }
        public async Task ReturnCreatedSurveyUserOnCreateWhenCorrectModel()
        {
            var surveyUser = new Faker <SurveyUserCreate>()
                             .RuleFor(r => r.FirstName, v => v.Name.FirstName())
                             .RuleFor(r => r.LastName, v => v.Name.LastName())
                             .RuleFor(r => r.DoB, v => v.Date.Between(DateTime.Today.AddYears(-19), DateTime.Today.AddYears(-22)))
                             .RuleFor(r => r.Gender, v => v.PickRandom <Gender>())
                             .RuleFor(r => r.Country, "Makedonija").Generate();

            var expected = new Faker <SurveyUserBaseModel>()
                           .RuleFor(r => r.Id, 1)
                           .RuleFor(r => r.FirstName, v => v.Name.FirstName())
                           .RuleFor(r => r.LastName, v => v.Name.LastName())
                           .RuleFor(r => r.DoB, v => v.Date.Between(DateTime.Today.AddYears(-19), DateTime.Today.AddYears(-22)))
                           .RuleFor(r => r.Gender, v => v.PickRandom <Gender>())
                           .RuleFor(r => r.Country, "Makedonija").Generate();

            _mockService.Setup(x => x.Insert(It.IsAny <SurveyUserCreate>()))
            .ReturnsAsync(expected)
            .Verifiable();
            // Act
            var result = await _controller.Post(surveyUser);

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

            var model = result as CreatedAtRouteResult;

            model?.Value.Should().Be(1);
            //model?.Location.Should().Be("/api/SurveyUsers/1");
        }