Пример #1
0
        public async void ReturnRoundWhichExistsInDbByGivenId()
        {
            // Assert
            var round = new Round()
            {
                Id   = 1,
                Name = "Round 1"
            };

            RoundDTO testRound = null;

            _repositoryMock.Reset();
            _repositoryMock.Setup(r => r.GetByIdAsync(It.IsAny <uint>())).ThrowsAsync(new ArgumentException());
            _repositoryMock.Setup(r => r.GetByIdAsync(1)).ReturnsAsync(round);

            var expectedRound = _mapper.Map <RoundDTO>(round);

            // Act
            var err = await Record.ExceptionAsync(async
                                                      () => testRound = await _service.GetByIdAsync(1));

            // Arrange
            err.Should().BeNull();

            testRound.Should().NotBeNull();

            testRound.Should().BeEquivalentTo(expectedRound);
        }
Пример #2
0
        public async Task <IActionResult> GetByIdAsync(Guid id)
        {
            var round = await _roundService.GetByIdAsync(id);

            if (round != null)
            {
                return(Ok(RoundAdapter.ToRoundDTO(round)));
            }

            return(NoContent());
        }
Пример #3
0
        public async Task GetByIdAsyncTest()
        {
            var round = new Round
            {
                Name   = "First",
                Topics = new List <Topic>
                {
                    new Topic
                    {
                        Name      = "C#",
                        Questions = new List <Question>
                        {
                            new Question
                            {
                                Text  = "g",
                                Price = 100
                            }
                        }
                    },
                    new Topic
                    {
                        Name      = "Java",
                        Questions = new List <Question>
                        {
                            new Question
                            {
                                Text  = "g",
                                Price = 200
                            }
                        }
                    }
                }
            };

            _db.Rounds.Add(round);
            _db.SaveChanges();

            var actual = await _roundService.GetByIdAsync(round.Id);

            await _roundService.RemoveAsync(round.Id);

            Assert.AreEqual(round, actual);
        }
 public async Task <RoundDTO> Handle(GetRoundByIdQuery query, CancellationToken cancellationToken)
 => await _service.GetByIdAsync(query.Id);