Ejemplo n.º 1
0
        public async Task ReturnFalse_WhenPlaylistIsAlreadyUndeleted()
        {
            var options = Utils.GetOptions(nameof(ReturnFalse_WhenPlaylistIsAlreadyUndeleted));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 11,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.UndoDeletePlaylistAsync(11);

                //Assert
                Assert.IsFalse(result);
            }
        }
Ejemplo n.º 2
0
        public async Task Throw_If_NoTracksExist()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(Throw_If_NoTracksExist));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 27,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.SaveChanges();
            }

            //Act & Assert
            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetPlaylistTracksAsync(27));
            }
        }
        public async Task ReturnTrue_WhenPlaylistFavoriteWasCreatedButDisliked()
        {
            var options = Utils.GetOptions(nameof(ReturnTrue_WhenPlaylistFavoriteWasCreatedButDisliked));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 32,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 33,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 4
            };

            PlaylistFavorite favorite = new PlaylistFavorite()
            {
                Id         = 2,
                UserId     = 4,
                PlaylistId = 32,
                IsFavorite = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.Favorites.Add(favorite);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.AddPlaylistToFavoritesAsync(32, 4);

                //Assert
                Assert.IsTrue(result);
            }
        }
        public async Task ReturnCorrectPlaylist_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylist_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 1,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 2,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var playlistDTO = new PlaylistDTO
            {
                Id               = 2,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.GetPlaylistByIdAsync(2);

                //Assert
                Assert.AreEqual(playlistDTO.Id, result.Id);
                Assert.AreEqual(playlistDTO.Title, result.Title);
                Assert.AreEqual(playlistDTO.Rank, result.Rank);
                Assert.AreEqual(playlistDTO.UserId, result.UserId);
                Assert.AreEqual(playlistDTO.PlaylistPlaytime, result.PlaylistPlaytime);
            }
        }
        public void ReturnCorrectPlaylists_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylists_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 60,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 61,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 62,
                Title            = "Jazz",
                PlaylistPlaytime = 5074,
                UserId           = 2,
                Rank             = 580258,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPageCount();

                //Assert
                Assert.AreEqual(result, 1);
            }
        }
Ejemplo n.º 6
0
        public async Task ReturnCorrectGenreCount_WhenParamsAreValid()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectGenreCount_WhenParamsAreValid));

            Genre rock = new Genre
            {
                Id   = 21,
                Name = "rock"
            };

            Genre metal = new Genre
            {
                Id   = 22,
                Name = "metal"
            };

            Genre pop = new Genre
            {
                Id   = 23,
                Name = "pop"
            };

            Genre jazz = new Genre
            {
                Id   = 24,
                Name = "jazz"
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Genres.Add(metal);
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Genres.Add(jazz);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                // Act
                var result = await sut.GetAllGenresAsync();

                //Assert
                Assert.AreEqual(result.Count(), 4);
            }
        }
Ejemplo n.º 7
0
        public async Task ReturnFalse_WhenPlaylistFavoriteWasAlreadyRemoved()
        {
            var options = Utils.GetOptions(nameof(ReturnFalse_WhenPlaylistFavoriteWasAlreadyRemoved));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 39,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 9
            };

            PlaylistFavorite favorite = new PlaylistFavorite()
            {
                Id         = 6,
                UserId     = 9,
                PlaylistId = 39,
                IsFavorite = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.Favorites.Add(favorite);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.RemovePlaylistFromFavoritesAsync(39, 9);

                //Assert
                Assert.IsFalse(result);
            }
        }
Ejemplo n.º 8
0
        public async Task ReturnPlaylistWithFilePath_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnPlaylistWithFilePath_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 87,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            PlaylistDTO firstPlaylistDTO = new PlaylistDTO
            {
                Id               = 87,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            mockImageService
            .Setup(x => x.AssignImage(It.IsAny <PlaylistDTO>()))
            .Returns(GetString());

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.AttachImage(firstPlaylistDTO);

                //Assert
                Assert.IsNotNull(result.FilePath);
            }
        }
Ejemplo n.º 9
0
        public void ReturnZeroPlaylistsOnSecondPage()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnZeroPlaylistsOnSecondPage));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 72,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 73,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPlaylistsPerPage(2).ToList();

                //Assert
                Assert.AreEqual(result.Count, 0);
            }
        }
Ejemplo n.º 10
0
        public async Task ReturnTrue_WhenParamsAreValid()
        {
            var options = Utils.GetOptions(nameof(ReturnTrue_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 12,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = true
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 13,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = await sut.UndoDeletePlaylistAsync(12);

                //Assert
                Assert.IsTrue(result);
            }
        }
Ejemplo n.º 11
0
        public void ReturnCorrectPlaylists_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylists_WhenParamsAreValid));

            var firstUser = new User();

            firstUser.Id = 1;
            var secondUser = new User();

            secondUser.Id = 2;

            Playlist firstPlaylist = new Playlist
            {
                Id               = 14,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 1,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 15,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var firstPlaylistDTO = new PlaylistDTO
            {
                Id               = 14,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 1,
                Rank             = 552348
            };

            var secondPlaylistDTO = new PlaylistDTO
            {
                Id               = 15,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Users.Add(firstUser);
                arrangeContext.Users.Add(secondUser);
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPlaylistsOfUserAsync(1).Result.ToList();

                //Assert
                Assert.AreEqual(result[0].Id, firstPlaylistDTO.Id);
                Assert.AreEqual(result[0].Title, firstPlaylistDTO.Title);
                Assert.AreEqual(result.Count, 1);
            }
        }
Ejemplo n.º 12
0
        public void ReturnOnePlaylist_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnOnePlaylist_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 45,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 46,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 47,
                Title            = "Seaside",
                PlaylistPlaytime = 5324,
                UserId           = 2,
                Rank             = 552308,
                IsDeleted        = false
            };

            var firstPlaylistDTO = new PlaylistDTO
            {
                Id               = 45,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut       = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var playlists = sut.GetAllPlaylistsAsync().Result;
                var result    = sut.FilterPlaylistsByName("Home", playlists).ToList();

                //Assert
                Assert.AreEqual(result.Count, 1);
                Assert.AreEqual(result[0].Id, firstPlaylistDTO.Id);
                Assert.AreEqual(result[0].Title, firstPlaylistDTO.Title);
            }
        }
Ejemplo n.º 13
0
        public void ReturnTheCorrectPageCountOfUserPlaylists()
        {
            var options = Utils.GetOptions(nameof(ReturnTheCorrectPageCountOfUserPlaylists));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 66,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 31,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 67,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 31,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 68,
                Title            = "Jazz",
                PlaylistPlaytime = 5074,
                UserId           = 31,
                Rank             = 580258,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 31
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPageCountOfCollection(31, "myPlaylists");

                //Assert
                Assert.AreEqual(result, 1);
            }
        }
        public void ReturnTwoPlaylists_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnTwoPlaylists_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 51,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 52,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 53,
                Title            = "Seaside",
                PlaylistPlaytime = 5324,
                UserId           = 2,
                Rank             = 552308,
                IsDeleted        = false
            };

            Genre rock = new Genre
            {
                Id   = 31,
                Name = "rock"
            };

            Genre metal = new Genre
            {
                Id   = 32,
                Name = "metal"
            };

            Genre pop = new Genre
            {
                Id   = 33,
                Name = "pop"
            };

            Genre jazz = new Genre
            {
                Id   = 34,
                Name = "jazz"
            };

            var firstPlaylistGenre  = new PlaylistGenre(31, 51);
            var secondPlaylistGenre = new PlaylistGenre(32, 51);
            var thirdPlaylistGenre  = new PlaylistGenre(32, 52);
            var fourthPlaylistGenre = new PlaylistGenre(34, 52);
            var fifthPlaylistGenre  = new PlaylistGenre(34, 53);

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            var genres = new List <string>()
            {
                "metal"
            };

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.Genres.Add(metal);
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Genres.Add(jazz);
                arrangeContext.PlaylistGenres.Add(firstPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(secondPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(thirdPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(fourthPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(fifthPlaylistGenre);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut       = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var playlists = sut.GetAllPlaylistsAsync().Result;
                var result    = sut.FilterPlaylistsByGenreAsync(genres, playlists).Result.ToList();

                //Assert
                Assert.AreEqual(result.Count, 2);
                Assert.AreEqual(result[0].Id, firstPlaylist.Id);
                Assert.AreEqual(result[0].Title, firstPlaylist.Title);
                Assert.AreEqual(result[1].Id, secondPlaylist.Id);
                Assert.AreEqual(result[1].Title, secondPlaylist.Title);
            }
        }
Ejemplo n.º 15
0
        public void ReturnCorrectPlaylistTracks_WhenParamsAreValid()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectPlaylistTracks_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 25,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false,
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 26,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            Artist artist = new Artist()
            {
                Id         = 1,
                ArtistName = "Sade"
            };

            Track firstTrack = new Track()
            {
                Id       = 1,
                ArtistId = 1
            };

            Track secondTrack = new Track()
            {
                Id       = 2,
                ArtistId = 1
            };

            var firstPlaylistTrack  = new PlaylistTrack(1, 25);
            var secondPlaylistTrack = new PlaylistTrack(2, 25);

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Tracks.Add(firstTrack);
                arrangeContext.Tracks.Add(secondTrack);
                arrangeContext.PlaylistTracks.Add(firstPlaylistTrack);
                arrangeContext.PlaylistTracks.Add(secondPlaylistTrack);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                // Act
                var result = sut.GetPlaylistTracksAsync(25).Result.ToList();

                //Assert
                Assert.AreEqual(result.Count, 2);
                Assert.AreEqual(result[0].ArtistId, artist.Id);
                Assert.AreEqual(result[1].ArtistId, artist.Id);
                Assert.AreEqual(result[0].Id, firstTrack.Id);
                Assert.AreEqual(result[1].Id, secondTrack.Id);
            }
        }
Ejemplo n.º 16
0
        public void ReturnTheCorrectPlaylistsPerPageForFavoritePlaylists()
        {
            var options = Utils.GetOptions(nameof(ReturnTheCorrectPlaylistsPerPageForFavoritePlaylists));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 75,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 35,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 76,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 35,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 77,
                Title            = "Jazz",
                PlaylistPlaytime = 5074,
                UserId           = 35,
                Rank             = 580258,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 35
            };

            PlaylistFavorite firstFavorite = new PlaylistFavorite()
            {
                Id         = 40,
                UserId     = 35,
                PlaylistId = 75,
                IsFavorite = true
            };

            PlaylistFavorite secondFavorite = new PlaylistFavorite()
            {
                Id         = 41,
                UserId     = 35,
                PlaylistId = 76,
                IsFavorite = true
            };

            PlaylistFavorite thirdFavorite = new PlaylistFavorite()
            {
                Id         = 42,
                UserId     = 35,
                PlaylistId = 77,
                IsFavorite = true
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.Favorites.Add(firstFavorite);
                arrangeContext.Favorites.Add(secondFavorite);
                arrangeContext.Favorites.Add(thirdFavorite);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetPlaylistsPerPageOfCollection(1, 35, "favorites").ToList();

                //Assert
                Assert.AreEqual(result.Count, 3);
            }
        }
Ejemplo n.º 17
0
        public void ReturnPlaylistWithCorrectPlaytime()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnPlaylistWithCorrectPlaytime));

            Genre rock = new Genre()
            {
                Id   = 30,
                Name = "rock"
            };

            Genre pop = new Genre()
            {
                Id   = 31,
                Name = "pop"
            };

            Track firstTrack = new Track()
            {
                Id            = 17,
                ArtistId      = 1,
                TrackDuration = 249,
                GenreId       = 30,
                Genre         = rock
            };

            Track secondTrack = new Track()
            {
                Id            = 18,
                ArtistId      = 1,
                TrackDuration = 272,
                GenreId       = 30,
                Genre         = rock
            };

            Track thirdTrack = new Track()
            {
                Id            = 19,
                ArtistId      = 1,
                TrackDuration = 262,
                GenreId       = 30,
                Genre         = rock
            };

            Track fourthTrack = new Track()
            {
                Id            = 20,
                ArtistId      = 1,
                TrackDuration = 246,
                GenreId       = 30,
                Genre         = rock
            };

            Track fifthTrack = new Track()
            {
                Id            = 21,
                ArtistId      = 1,
                TrackDuration = 218,
                GenreId       = 31,
                Genre         = pop
            };

            Track sixthTrack = new Track()
            {
                Id            = 22,
                ArtistId      = 1,
                TrackDuration = 252,
                GenreId       = 31,
                Genre         = pop
            };

            Track seventhTrack = new Track()
            {
                Id            = 23,
                ArtistId      = 1,
                TrackDuration = 218,
                GenreId       = 31,
                Genre         = pop
            };

            Track eightTrack = new Track()
            {
                Id            = 24,
                ArtistId      = 1,
                TrackDuration = 252,
                GenreId       = 31,
                Genre         = pop
            };

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Tracks.Add(firstTrack);
                arrangeContext.Tracks.Add(secondTrack);
                arrangeContext.Tracks.Add(thirdTrack);
                arrangeContext.Tracks.Add(fourthTrack);
                arrangeContext.Tracks.Add(fifthTrack);
                arrangeContext.Tracks.Add(sixthTrack);
                arrangeContext.Tracks.Add(seventhTrack);
                arrangeContext.Tracks.Add(eightTrack);
                arrangeContext.SaveChanges();
            }

            double travelDuration = 660.0;

            var genrePercentage = new Dictionary <string, int>()
            {
                { "rock", 50 },
                { "metal", 0 },
                { "pop", 50 },
                { "jazz", 0 },
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            string genre = "pop";

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new GeneratePlaylistService(assertContext, dateTimeProviderMock.Object);
                var result = sut.GetTracks(genre, travelDuration, genrePercentage, true).Result.ToList();

                var finalPlaytime = sut.CalculatePlaytime(result);

                //Assert
                Assert.IsTrue(finalPlaytime >= travelDuration / 2);
                Assert.IsTrue(result.Count > 1);
            }
        }
Ejemplo n.º 18
0
        public async Task ReturnCorrectString_WhenParamsAreValid()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectString_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 17,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false,
            };

            Genre rock = new Genre
            {
                Id   = 9,
                Name = "rock"
            };

            Genre metal = new Genre
            {
                Id   = 10,
                Name = "metal"
            };

            Genre pop = new Genre
            {
                Id   = 11,
                Name = "pop"
            };

            Genre jazz = new Genre
            {
                Id   = 12,
                Name = "jazz"
            };

            var firstPlaylistGenre  = new PlaylistGenre(9, 17);
            var secondPlaylistGenre = new PlaylistGenre(10, 17);

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Genres.Add(metal);
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Genres.Add(jazz);
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.PlaylistGenres.Add(firstPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(secondPlaylistGenre);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                // Act
                var result = await sut.GetPlaylistGenresAsStringAsync(17);

                string expectedString = "metal, rock";

                //Assert
                Assert.AreEqual(result, expectedString);
            }
        }
Ejemplo n.º 19
0
        public void ReturnTheCorrectPlaylists_WhenParamsAreValid()
        {
            var options = Utils.GetOptions(nameof(ReturnTheCorrectPlaylists_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 41,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 42,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            User user = new User()
            {
                Id = 11
            };

            PlaylistFavorite firstFavorite = new PlaylistFavorite()
            {
                Id         = 10,
                UserId     = 11,
                PlaylistId = 41,
                IsFavorite = true
            };

            PlaylistFavorite secondFavorite = new PlaylistFavorite()
            {
                Id         = 11,
                UserId     = 11,
                PlaylistId = 42,
                IsFavorite = true
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Users.Add(user);
                arrangeContext.Favorites.Add(firstFavorite);
                arrangeContext.Favorites.Add(secondFavorite);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut    = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var result = sut.GetFavoritePlaylistsOfUser(11).Result.ToList();

                //Assert
                Assert.AreEqual(result.Count, 2);
                Assert.AreEqual(result[0].Id, firstPlaylist.Id);
                Assert.AreEqual(result[0].Title, firstPlaylist.Title);
                Assert.AreEqual(result[1].Id, secondPlaylist.Id);
                Assert.AreEqual(result[1].Title, secondPlaylist.Title);
            }
        }
        public void ReturnOneFilteredPlaylist_WhenParamsAreValid()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnOneFilteredPlaylist_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 55,
                Title            = "Home",
                PlaylistPlaytime = 4824,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 56,
                Title            = "Metal",
                PlaylistPlaytime = 5124,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            Playlist thirdPlaylist = new Playlist
            {
                Id               = 57,
                Title            = "Seaside",
                PlaylistPlaytime = 5324,
                UserId           = 2,
                Rank             = 552308,
                IsDeleted        = false
            };

            Genre rock = new Genre
            {
                Id   = 35,
                Name = "rock"
            };

            Genre metal = new Genre
            {
                Id   = 36,
                Name = "metal"
            };

            Genre pop = new Genre
            {
                Id   = 37,
                Name = "pop"
            };

            Genre jazz = new Genre
            {
                Id   = 38,
                Name = "jazz"
            };

            var firstPlaylistGenre  = new PlaylistGenre(35, 55);
            var secondPlaylistGenre = new PlaylistGenre(36, 55);
            var thirdPlaylistGenre  = new PlaylistGenre(36, 56);
            var fourthPlaylistGenre = new PlaylistGenre(37, 56);
            var fifthPlaylistGenre  = new PlaylistGenre(38, 57);

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            var genres = new List <string>()
            {
                "metal"
            };
            List <int> durationLimits = new List <int>()
            {
                0, 84
            };
            string name = null;

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.Playlists.Add(thirdPlaylist);
                arrangeContext.Genres.Add(metal);
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Genres.Add(jazz);
                arrangeContext.PlaylistGenres.Add(firstPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(secondPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(thirdPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(fourthPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(fifthPlaylistGenre);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                //Act
                var sut       = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);
                var count     = sut.ReturnFilteredPlaylistsAndCountAsync(name, genres, durationLimits, 1).Result.Item1;
                var playlists = sut.ReturnFilteredPlaylistsAndCountAsync(name, genres, durationLimits, 1).Result.Item2.ToList();

                //Assert
                Assert.AreEqual(playlists.Count, count);
                Assert.AreEqual(playlists[0].Id, firstPlaylist.Id);
                Assert.AreEqual(playlists[0].Title, firstPlaylist.Title);
            }
        }
Ejemplo n.º 21
0
        public async Task ReturnTrue_WhenParamsAreValid()
        {
            // Arrange
            var options = Utils.GetOptions(nameof(ReturnTrue_WhenParamsAreValid));

            Playlist firstPlaylist = new Playlist
            {
                Id               = 5,
                Title            = "Home",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                IsDeleted        = false,
            };

            Playlist secondPlaylist = new Playlist
            {
                Id               = 6,
                Title            = "Metal",
                PlaylistPlaytime = 5024,
                UserId           = 2,
                Rank             = 490258,
                IsDeleted        = false
            };

            var editPlaylistDTO = new EditPlaylistDTO
            {
                Id              = 5,
                Title           = "Home and back",
                GenrePercentage = new Dictionary <string, int>()
                {
                    {
                        "rock", 0
                    },
                    {
                        "metal", 0
                    },
                    {
                        "pop", 100
                    },
                    {
                        "jazz", 0
                    }
                },
                UserId = 2
            };

            Genre rock = new Genre
            {
                Id   = 1,
                Name = "rock"
            };

            Genre metal = new Genre
            {
                Id   = 2,
                Name = "metal"
            };

            Genre pop = new Genre
            {
                Id   = 3,
                Name = "pop"
            };

            Genre jazz = new Genre
            {
                Id   = 4,
                Name = "jazz"
            };

            var firstPlaylistGenre  = new PlaylistGenre(1, 5);
            var secondPlaylistGenre = new PlaylistGenre(2, 5);

            var updatedPlaylistDTO = new PlaylistDTO
            {
                Id               = 5,
                Title            = "Home and back",
                PlaylistPlaytime = 5524,
                UserId           = 2,
                Rank             = 552348,
                GenresCount      = 1
            };

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();
            var mockImageService     = new Mock <IPixaBayImageService>();

            using (var arrangeContext = new RidePalDbContext(options))
            {
                arrangeContext.Genres.Add(metal);
                arrangeContext.Genres.Add(rock);
                arrangeContext.Genres.Add(pop);
                arrangeContext.Genres.Add(jazz);
                arrangeContext.Playlists.Add(firstPlaylist);
                arrangeContext.Playlists.Add(secondPlaylist);
                arrangeContext.PlaylistGenres.Add(firstPlaylistGenre);
                arrangeContext.PlaylistGenres.Add(secondPlaylistGenre);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new RidePalDbContext(options))
            {
                var sut = new PlaylistService(assertContext, dateTimeProviderMock.Object, mockImageService.Object);

                // Act
                var result = await sut.EditPlaylistAsync(editPlaylistDTO);

                var updatedPlaylistFromDb = await sut.GetPlaylistByIdAsync(5);

                //Assert
                Assert.IsTrue(result);
                Assert.AreEqual(updatedPlaylistDTO.Id, updatedPlaylistFromDb.Id);
                Assert.AreEqual(updatedPlaylistDTO.Title, updatedPlaylistFromDb.Title);
                Assert.AreEqual(updatedPlaylistDTO.GenresCount, updatedPlaylistFromDb.GenresCount);
            }
        }