public async Task <Track> InsertAsync(TrackUpdateModel track)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <DataAccess.Entities.Track>(track));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Track>(result.Entity));
        }
        public async Task <Track> UpdateAsync(TrackUpdateModel track)
        {
            var existing = await this.Get(track);

            var result = this.Mapper.Map(track, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Track>(result));
        }
            public async Task CreateAsync_TrackValidationSucceed_CreatesScreening()
            {
                // Arrange
                var track           = new TrackUpdateModel();
                var expected        = new Track();
                var albumGetService = new Mock <IAlbumGetService>();

                albumGetService.Setup(x => x.ValidateAsync(track));
                var trackDataAccess = new Mock <ITrackDataAccess>();

                trackDataAccess.Setup(x => x.InsertAsync(track)).ReturnsAsync(expected);
                var trackGetService = new TrackCreateService(trackDataAccess.Object, albumGetService.Object);
                // Act
                var result = await trackGetService.CreateAsync(track);

                // Assert
                result.Should().Be(expected);
            }
            public async Task CreateAsync_TrackValidationFailed_ThrowsError()
            {
                // Arrange
                var fixture         = new Fixture();
                var track           = new TrackUpdateModel();
                var expected        = fixture.Create <string>();
                var albumGetService = new Mock <IAlbumGetService>();

                albumGetService
                .Setup(x => x.ValidateAsync(track))
                .Throws(new InvalidOperationException(expected));
                var trackDataAccess = new Mock <ITrackDataAccess>();
                var trackGetService = new TrackCreateService(trackDataAccess.Object, albumGetService.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);
            }
Example #5
0
        public async Task <Track> UpdateAsync(TrackUpdateModel track)
        {
            await AlbumGetService.ValidateAsync(track);

            return(await TrackDataAccess.UpdateAsync(track));
        }