Exemplo n.º 1
0
        public void Edit_ChangesProperties()
        {
            // Arrange
            var context = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var album   = new Album
            {
                Id             = 1,
                AlbumCoverLink = "first",
                Genre          = "first",
                Name           = "first",
                ReleaseDate    = DateTime.Now.AddDays(-1),
                ReleaseStage   = ReleaseStage.Secret,
                SpotifyLink    = "first",
                AlbumsSongs    = new List <AlbumSong>()
                {
                    new AlbumSong {
                        SongId = 1
                    }
                }
            };

            context.Albums.Add(album);
            context.SaveChanges();
            var albumsService = new AlbumsService(context);
            var editInfo      = new EditAlbumDto()
            {
                Id              = 1,
                AlbumCoverLink  = "newlink",
                Genre           = "newgenre",
                Name            = "newname",
                ReleaseDate     = DateTime.Now.AddDays(1),
                ReleaseStage    = ReleaseStage.Announced,
                SpotifyLink     = "newSLink",
                SelectedSongIds = new int[] { 1, 2, 3, 4, 5, 6, 7 }
            };

            // Act
            albumsService.Edit(editInfo);

            //Assert
            Assert.Equal(editInfo.Name, context.Albums.First().Name);
            Assert.Equal(editInfo.AlbumCoverLink, context.Albums.First().AlbumCoverLink);
            Assert.Equal(editInfo.Genre, context.Albums.First().Genre);
            Assert.Equal(editInfo.ReleaseDate, context.Albums.First().ReleaseDate);
            Assert.Equal(editInfo.ReleaseStage, context.Albums.First().ReleaseStage);
            Assert.Equal(editInfo.SpotifyLink, context.Albums.First().SpotifyLink);
            Assert.Equal(editInfo.SelectedSongIds, context.Albums.First().AlbumsSongs.Select(s => s.SongId));
        }