public async Task ReturnOptionWhenHasData()
        {
            // Arrange
            int expectedCount = 10;
            var option        = new Faker <OptionModelBase>()
                                .RuleFor(s => s.Id, v => ++ v.IndexVariable)
                                .RuleFor(s => s.Text, v => "Option 1")
                                .RuleFor(s => s.Order, v => 1)
                                .RuleFor(s => s.QuestionId, v => 1)
                                .Generate(expectedCount);

            _mockService.Setup(x => x.Get())
            .ReturnsAsync(option)
            .Verifiable();

            // Act
            var result = await _controller.Get();

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

            var model = result as OkObjectResult;

            model?.Value.Should().BeOfType <List <OptionModelBase> >().Subject.Count().Should().Be(expectedCount);
        }
        public async Task ReturnOptionWhenHasData()
        {
            // Arrange
            int expectedId = 10;
            var option     = new Faker <OptionBaseModel>()
                             .RuleFor(p => p.Id, v => ++ v.IndexVariable)
                             .RuleFor(p => p.Text, v => v.Name.FirstName())
                             .RuleFor(p => p.Order, v => ++ v.IndexVariable)
                             .RuleFor(p => p.QuestionId, v => ++ v.IndexVariable)
                             .Generate(10);

            _mockService.Setup(x => x.Get())
            .ReturnsAsync(option);
            // Act
            var result = await _controller.Get();

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

            var model = result as OkObjectResult;

            model?.Value.Should().BeOfType <List <OptionBaseModel> >().Subject.Count().Should().Be(expectedId);
        }
예제 #3
0
        public async Task Get()
        {
            const int optionId = 56;
            var       options  = new List <Option>
            {
                new Option(),
                new Option()
            };

            var optionsManager = new Mock <IOptionManager>();

            optionsManager.Setup(c => c.GetQuizOptions(optionId))
            .Returns(Task.FromResult(options));

            var sut = new OptionsController(optionsManager.Object);

            var result = await sut.Get(optionId);

            Assert.AreEqual(options.Count, result.ToList().Count);
        }