public async Task ReturnExtendedSurveyUserByIdWhenHasData() { // Arrange int expectedId = 1; var answers = new Faker <AnswersBaseModel>() .RuleFor(s => s.Id, v => ++ v.IndexVariable) .RuleFor(s => s.UserId, v => v.IndexVariable) .RuleFor(s => s.OptionId, v => v.IndexVariable); var options = new Faker <OptionBaseModel>() .RuleFor(s => s.Id, v => ++ v.IndexVariable); var question = new Faker <QuestionModelBase>() .RuleFor(s => s.Id, v => ++ v.IndexVariable); var surveyUser = new Faker <SurveyUserExtended>() .Generate(6); // Act var result = await _controller.GetById(expectedId); // Assert result.Should().BeOfType <OkObjectResult>(); var model = result as OkObjectResult; model?.Value.Should().BeOfType <SurveyUserExtended>().Subject.Id.Should().Be(expectedId); }
public async Task ReturnExtendedSurveyUserByIdWhenHasData() { // Arrange int expectedId = 1; var answer = new Faker <AnswersBaseModel>() .RuleFor(r => r.Id, v => ++ v.IndexVariable) .RuleFor(r => r.UserId, v => ++ v.IndexVariable) .RuleFor(r => r.OptionId, v => ++ v.IndexVariable); var surveyUser = new Faker <SurveyUserExtended>() .RuleFor(r => r.Id, v => ++ v.IndexVariable) .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") .RuleFor(r => r.Answers, v => answer.Generate(4)) .Generate(4); _mockService.Setup(x => x.GetById(It.IsAny <int>())) .ReturnsAsync(surveyUser.Find(x => x.Id == expectedId)) .Verifiable(); // Act var result = await _controller.GetById(expectedId); // Assert result.Should().BeOfType <OkObjectResult>(); var model = result as OkObjectResult; model?.Value.Should().BeOfType <SurveyUserExtended>().Subject.Id.Should().Be(expectedId); }