public async Task <Podcast> InsertAsync(PodcastUpdateModel podcast) { var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Podcast>(podcast)); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Podcast>(result.Entity)); }
public async Task <Podcast> UpdateAsync(PodcastUpdateModel podcast) { var existing = await this.Get(podcast); var result = this.Mapper.Map(podcast, existing); this.Context.Update(result); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Podcast>(result)); }
public async Task CreateAsync_PodcastValidationSucceed_CreatesScreening() { // Arrange var podcast = new PodcastUpdateModel(); var expected = new Podcast(); var albumGetService = new Mock <IAlbumGetService>(); albumGetService.Setup(x => x.ValidateAsync(podcast)); var podcastDataAccess = new Mock <IPodcastDataAccess>(); podcastDataAccess.Setup(x => x.InsertAsync(podcast)).ReturnsAsync(expected); var podcastGetService = new PodcastCreateService(podcastDataAccess.Object, albumGetService.Object); // Act var result = await podcastGetService.CreateAsync(podcast); // Assert result.Should().Be(expected); }
public async Task CreateAsync_PodcastValidationFailed_ThrowsError() { // Arrange var fixture = new Fixture(); var podcast = new PodcastUpdateModel(); var expected = fixture.Create <string>(); var albumGetService = new Mock <IAlbumGetService>(); albumGetService .Setup(x => x.ValidateAsync(podcast)) .Throws(new InvalidOperationException(expected)); var podcastDataAccess = new Mock <IPodcastDataAccess>(); var podcastGetService = new PodcastCreateService(podcastDataAccess.Object, albumGetService.Object); // Act var action = new Func <Task>(() => podcastGetService.CreateAsync(podcast)); // Assert await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected); podcastDataAccess.Verify(x => x.InsertAsync(podcast), Times.Never); }
public async Task <Podcast> CreateAsync(PodcastUpdateModel podcast) { await AlbumGetService.ValidateAsync(podcast); return(await PodcastDataAccess.InsertAsync(podcast)); }