public async Task <Viewer> InsertAsync(ViewerUpdateModel viewer) { var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Viewer>(viewer)); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Viewer>(result.Entity)); }
public async Task <Viewer> UpdateAsync(ViewerUpdateModel viewer) { var existing = await this.Get(viewer); var result = this.Mapper.Map(viewer, existing); this.Context.Update(result); await this.Context.SaveChangesAsync(); return(this.Mapper.Map <Viewer>(result)); }
public async Task CreateAsync_ViewerValidationSucceed_CreatesScreening() { // Arrange var track = new ViewerUpdateModel(); var expected = new Viewer(); var ratingGetService = new Mock <IRatingGetService>(); ratingGetService.Setup(x => x.ValidateAsync(track)); var trackDataAccess = new Mock <IViewerDataAccess>(); trackDataAccess.Setup(x => x.InsertAsync(track)).ReturnsAsync(expected); var trackGetService = new ViewerCreateService(trackDataAccess.Object, ratingGetService.Object); // Act var result = await trackGetService.CreateAsync(track); // Assert result.Should().Be(expected); }
public async Task CreateAsync_ViewerValidationFailed_ThrowsError() { // Arrange var fixture = new Fixture(); var track = new ViewerUpdateModel(); var expected = fixture.Create <string>(); var ratingGetService = new Mock <IRatingGetService>(); ratingGetService .Setup(x => x.ValidateAsync(track)) .Throws(new InvalidOperationException(expected)); var trackDataAccess = new Mock <IViewerDataAccess>(); var trackGetService = new ViewerCreateService(trackDataAccess.Object, ratingGetService.Object); // Act var action = new Func <Task>(() => trackGetService.CreateAsync(track)); // Assert await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected); trackDataAccess.Verify(x => x.InsertAsync(track), Times.Never); }
public async Task <Viewer> UpdateAsync(ViewerUpdateModel track) { await RatingGetService.ValidateAsync(track); return(await ViewerDataAccess.UpdateAsync(track)); }