Пример #1
0
        /// <inheritdoc />
        public async Task <AnnouncementGetDto> AddAsync(AnnouncementPostDto announcementDto)
        {
            var announcement = _mapper.Map <Announcement>(announcementDto);

            _announcementRepository.Add(announcement);
            await _announcementRepository.SaveChangesAsync();

            return(_mapper.Map <AnnouncementGetDto>(announcement));
        }
        public async Task AddAsync_AnnouncementIsValid_Returns_AnnouncementGetDto()
        {
            var announcementDto = new AnnouncementPostDto();

            _announcementRepositoryMock.Setup(s => s.Add(It.IsAny <Announcement>()));
            _announcementRepositoryMock.Setup(x => x.SaveChangesAsync()).ReturnsAsync(1);

            var announcementResult = await _announcementService.AddAsync(announcementDto);

            announcementResult.Should().BeOfType <AnnouncementGetDto>();
            _announcementRepositoryMock.Verify(x => x.Add(It.IsAny <Announcement>()), Times.Once);
            _announcementRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
Пример #3
0
        public async Task <ActionResult <AnnouncementPostDto> > PostAsync([FromBody] AnnouncementPostDto announcementDto)
        {
            var insertedAnnouncement = await _announcementService.AddAsync(announcementDto);

            return(CreatedAtAction("GetByIdAsync", new { id = insertedAnnouncement.Id }, insertedAnnouncement));
        }