public async Task CreateArtist(ArtistToCreateDto artistToCreate) { using (var mock = AutoMock.GetLoose()) { var artist = new Artist { ArtistName = artistToCreate.Name }; var returnDto = new ArtistDetailDto { Name = artistToCreate.Name }; mock.Mock <IMap>().Setup(x => x.MapToArtist(artistToCreate)).Returns(artist); mock.Mock <IArtistData>().Setup(x => x.Add(artist)); mock.Mock <IArtistData>().Setup(x => x.SaveAllAsync()).Returns(Task.FromResult(true)); mock.Mock <IMap>().Setup(x => x.MapToArtistDetailDto(artist)).Returns(returnDto); var cls = mock.Create <ArtistRepo>(); var expected = new ArtistDetailDto { Name = artistToCreate.Name }; var actual = await cls.CreateArtistAsync(artistToCreate); Assert.True(actual != null); Assert.Equal(expected.Name, actual.Name); // More Tests needed } }
public async Task <ArtistDetailDto> CreateArtistAsync(ArtistToCreateDto artistToCreate) { var created = _map.MapToArtist(artistToCreate); _artist.Add(created); var result = await _artist.SaveAllAsync(); var artistToReturn = _map.MapToArtistDetailDto(created); return(artistToReturn); }
public async Task <IActionResult> Update(int id, [FromBody] ArtistToCreateDto artistDto) { var mappedArtist = _mapper.Map <Artist>(artistDto); _artistRepo.Update(id, mappedArtist); await _artistRepo.SaveChangesAsync(); var updatedArtist = await _artistRepo.GetByIdAsync(id); var mappedUpdatedArtist = _mapper.Map <ArtistDto>(updatedArtist); return(Ok(_linkService.CreateLinks(mappedUpdatedArtist))); }
public Artist MapToArtist(ArtistToCreateDto a) { var artist = new Artist() { ArtistName = a.Name, CareerBeginDate = a.CareerBeginDate, ArtistGroup = a.ArtistGroup, Verified = a.Verified, HomeCountryId = a.HomeCountryId, CurrentCountryId = a.CurrentCountryId, CreatedBy = a.CreatedBy, CreatedDate = a.CreatedDate }; return(artist); }
public async Task <IActionResult> AddArtistToTrack(int id, [FromBody] ArtistToCreateDto artistDto) { if (!ModelState.IsValid) { return(BadRequest()); } var artist = _mapper.Map <Artist>(artistDto); var track = await _trackRepo.AddArtistToTrack(id, artist); await _trackRepo.SaveChangesAsync(); var mappedTrack = _mapper.Map <TrackDto>(track); return(Ok(_linkService.CreateLinks(mappedTrack))); }
public async Task <IActionResult> Post([FromBody] ArtistToCreateDto artistDto) { if (!ModelState.IsValid) { return(BadRequest()); } var artist = _mapper.Map <Artist>(artistDto); _artistRepo.Add(artist); await _artistRepo.SaveChangesAsync(); var mappedArtist = _mapper.Map <ArtistDto>(artist); return(Ok(_linkService.CreateLinks(mappedArtist))); }
public async Task <IActionResult> Create(ArtistToCreateDto artistToCreate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var artist = await _artist.CreateArtistAsync(artistToCreate); if (artist.Id != 0) { return(CreatedAtRoute( artist.Id, artist)); } return(BadRequest("Could not add artist")); }