コード例 #1
0
        public async Task <ActionResult <AlbumDTO> > PostAlbum([FromBody] AlbumAddDTO albumAddDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (albumAddDTO.UserId != UserId)
            {
                return(BadRequest());
            }

            AlbumDTO albumDTO;

            try
            {
                albumDTO = await _albumService.AddAlbumAsync(albumAddDTO);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok(albumDTO));
        }
コード例 #2
0
        public async Task <AlbumDTO> AddAlbumAsync(AlbumAddDTO albumDTO)
        {
            var album = mapper.Map <Album>(albumDTO, opt => opt.Items["creationTime"] = DateTime.Now);

            await unitOfWork.Albums.AddAsync(album);

            await unitOfWork.SaveAsync();

            return(mapper.Map <AlbumDTO>(album));
        }
コード例 #3
0
        public async Task AddAlbumAsync_Should_ReturnAlbumDTO()
        {
            var dto = new AlbumAddDTO {
                Name = "name", Description = "desc"
            };

            mockUow.Setup(uow => uow.Albums.AddAsync(It.IsAny <Album>()));

            var result = await service.AddAlbumAsync(dto);

            result.Should().BeEquivalentTo(dto);
            result.Created.Should().NotBe(default);
コード例 #4
0
        public async Task AddAlbumAsync_Should_AddAlbumToUow()
        {
            var dto = new AlbumAddDTO {
                Name = "name", Description = "desc"
            };

            mockUow.Setup(uow => uow.Albums.AddAsync(It.Is <Album>(a => a.Name == dto.Name))).Verifiable();

            await service.AddAlbumAsync(dto);

            mockUow.Verify();
        }
コード例 #5
0
        public async Task AddAlbumAsync_Should_SaveUow()
        {
            var dto = new AlbumAddDTO {
                Name = "name", Description = "desc"
            };

            mockUow.Setup(uow => uow.Albums.AddAsync(It.IsAny <Album>()));
            mockUow.Setup(uow => uow.SaveAsync()).Verifiable();

            await service.AddAlbumAsync(dto);

            mockUow.Verify();
        }
コード例 #6
0
ファイル: AlbumService.cs プロジェクト: DenKu1/PhotoGallery
        //Do not forget to update userId in controller!
        public async Task <AlbumDTO> AddAlbumAsync(AlbumAddDTO albumDTO)
        {
            if (albumDTO == null)
            {
                throw null;
            }

            Album album = _mp.Map <Album>(albumDTO);

            var curDateTime = DateTime.Now;

            album.Created = curDateTime;
            album.Updated = curDateTime;

            await _unit.Albums.AddAsync(album);

            await _unit.SaveAsync();

            return(_mp.Map <AlbumDTO>(album));
        }