public void ShouldFailAddToPlaylistNotOwner() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0); DataModel.Playlist playlist = context.CreatePlaylist(false, userId, "Rock", 0); CreateAndAddAudio(context, playlist.Id, 1); context.SaveChanges(); var audio = context.Audios.FirstOrDefault(); var result = audioService.AddToPlaylist(Guid.Empty, new AddRemovePlaylistRequest() { AudioId = audio.Id, PlaylistId = playlist.Id, }); CheckIfFail(result); Assert.True(result.Info.Any()); } }); }
public void ShouldFailCreatePlaylist() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); context.SaveChanges(); var result = playListService.CreatePlaylist(userId, new CreatePlaylistRequest() { Title = "13", }); CheckIfFail(result); } }); }
public void ShouldDeletePlaylist() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModel.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0); DataModel.Playlist playlist = context.CreatePlaylist(false, userId, "My playlist", 0); CreateAndAddAudio(context, playlist.Id, 10); context.SaveChanges(); Assert.Equal(context.AudioPlaylists.Count(), 10); var result = playListService.DeletePlaylist(userId, playlist.Id); CheckIfSuccess(result); Assert.Equal(context.AudioPlaylists.Count(), 0); } }); }
public void IsGetAllAudios(int count, int skip, int take, int actualCount) { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); CreateAndAddAudio(context, playlist.Id, count); context.SaveChanges(); UserPlaylistsResult result = playListService.GetUserPlaylists(userId, playlist.Id, skip, take); CheckIfSuccess(result); Assert.Equal(playlist.Id, result.Playlists.FirstOrDefault().Id); Assert.Equal(playlist.Title, result.Playlists.FirstOrDefault().Title); Assert.Equal(actualCount, result.Playlists.FirstOrDefault().Audios.Count()); } }); }
public void ShouldRemoveIfAudioNotExists() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0); DataModel.Playlist playlist = context.CreatePlaylist(false, userId, "Rock", 0); context.SaveChanges(); var result = audioService.RemoveFromPlaylist(userId, new AddRemovePlaylistRequest() { AudioId = Guid.Empty, PlaylistId = playlist.Id, }); CheckIfSuccess(result); } }); }
public void ShouldReturnGeneralPlaylist() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); DataModel.Playlist playlist2 = context.CreatePlaylist(false, userId, "Rock", 0); DataModel.Playlist playlist3 = context.CreatePlaylist(false, userId, "RnB", 0); CreateAndAddAudio(context, playlist3.Id, 10); context.SaveChanges(); UserPlaylistsResult result = playListService.GetUserPlaylists(userId, playlist3.Id, 0, 10); CheckIfSuccess(result); Assert.True(result.Playlists.Where(x => x.Id != playlist3.Id).All(x => !x.Audios.Any())); Assert.Equal(10, result.Playlists.FirstOrDefault(x => x.Id == playlist3.Id).Audios.Count()); } }); }
public void IsDescendingOrder() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); CreateAndAddAudio(context, playlist.Id, 5); context.SaveChanges(); UserPlaylistsResult result = playListService.GetUserPlaylists(userId, playlist.Id, 0, 5); CheckIfSuccess(result); Assert.Equal(playlist.Id, result.Playlists.FirstOrDefault().Id); Assert.Equal(playlist.Title, result.Playlists.FirstOrDefault().Title); Assert.Equal(1, result.Playlists.Count()); Assert.Equal(5, result.Playlists.FirstOrDefault().Audios.Count()); for (int i = 0; i < 4; i++) { Assert.True(result.Playlists.FirstOrDefault().Audios.ElementAt(i).DateAdded > result.Playlists.FirstOrDefault().Audios.ElementAt(i + 1).DateAdded); } } }); }
public void ShouldReturnNotGeneralPlaylist() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist playlist = context.CreatePlaylist(false, userId, "My playlist", 0); CreateAndAddAudio(context, playlist.Id, 10); context.SaveChanges(); UserPlaylistsResult result = playListService.GetUserPlaylists(userId, playlist.Id, 0, 10); CheckIfSuccess(result); Assert.Equal(playlist.Id, result.Playlists.FirstOrDefault().Id); Assert.Equal(playlist.Title, result.Playlists.FirstOrDefault().Title); Assert.Equal(10, result.Playlists.FirstOrDefault().Audios.Count()); } }); }
public void ShouldCreatePlaylist() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); context.SaveChanges(); string playlistTitle = "Test"; var result = playListService.CreatePlaylist(userId, new CreatePlaylistRequest() { Title = playlistTitle, }); CheckIfSuccess(result); var playlists = context.Playlists.ToList(); Assert.True(playlists.Any(x => x.Title == playlistTitle && !x.IsGeneral)); } }); }
public void ShouldReturnPlaylists() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); DataModel.Playlist playlist1 = context.CreatePlaylist(false, userId, "playlist1", 0); DataModel.Playlist playlist2 = context.CreatePlaylist(false, userId, "playlist2", 0); DataModel.Playlist playlist3 = context.CreatePlaylist(false, userId, "playlist3", 0); context.SaveChanges(); UserPlaylistsResult result = playListService.GetUserPlaylists(userId, null, 0, 10); CheckIfSuccess(result); Assert.Equal(4, result.Playlists.Count()); Assert.True(result.Playlists.All(x => !x.Audios.Any())); } }); }
public void ShouldFailUpdateOnWrongPlaylistId() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); string newTitle = "New title"; var updatePlaylist = context.CreatePlaylist(false, userId, "Top", 0); context.SaveChanges(); var result = playListService.UpdatePlaylist(userId, new UpdatePlaylistRequest() { PlaylistId = Guid.Empty, Title = newTitle, }); CheckIfFail(result); Assert.Equal("Playlist not found", result.Info); } }); }
public void ShouldTrueRemoveFromGeneral() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0); CreateAndAddAudio(context, generalPlaylist.Id, 1); context.SaveChanges(); var audio = context.Audios.FirstOrDefault(); var result = audioService.RemoveFromPlaylist(userId, new AddRemovePlaylistRequest() { AudioId = audio.Id, PlaylistId = generalPlaylist.Id, }); CheckIfSuccess(result); Assert.Equal(context.AudioPlaylists.Count(), 0); } }); }
public void ShouldUpdateProfile() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IProfileService)) as IProfileService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); var user = context.CreateUser("*****@*****.**", "v", "last", "m", "123", "123"); context.SaveChanges(); string newFirstName = "newFirstName"; string newLastName = "newLastName"; string newNickname = "newNickName"; var result = playListService.UpdateProfile(new DataService.Request.UpdateProfileRequest() { Id = user.Id, FirstName = newFirstName, LastName = newLastName, NickName = newNickname, }); CheckIfSuccess(result); Assert.NotNull(result.User); Assert.Equal(newFirstName, result.User.FirstName); Assert.Equal(newLastName, result.User.LastName); Assert.Equal(newNickname, result.User.NickName); } }); }
public void ShouldSuccessReturnProfile() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IProfileService)) as IProfileService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); string email = "*****@*****.**"; string firstName = "v"; string lastName = "last"; string nickName = "mef"; string password = "******"; string inviteCode = "123"; var user = context.CreateUser(email, firstName, lastName, nickName, password, inviteCode); context.SaveChanges(); var result = playListService.GetProfile(user.Id); CheckIfSuccess(result); Assert.NotNull(result.User); Assert.Equal(email, result.User.Email); Assert.Equal(firstName, result.User.FirstName); Assert.Equal(lastName, result.User.LastName); Assert.Equal(nickName, result.User.NickName); } }); }
public void ShouldAddToPlaylist() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0); CreateAndAddAudio(context, generalPlaylist.Id, 10); DataModel.Playlist playlist = context.CreatePlaylist(false, userId, "Rock", 0); context.SaveChanges(); var audio = context.Audios.FirstOrDefault(); var result = audioService.AddToPlaylist(userId, new AddRemovePlaylistRequest() { AudioId = audio.Id, PlaylistId = playlist.Id, }); var audioPlaylists = context.AudioPlaylists.ToList(); var addedAP = audioPlaylists.FirstOrDefault(x => x.PlaylistId == playlist.Id); CheckIfSuccess(result); Assert.Equal(audioPlaylists.Count, 11); Assert.NotNull(addedAP); Assert.Equal(addedAP.AudioId, audio.Id); } }); }
public void SearchByStartsWithAndOrder() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); context.CreateAudio(DateTime.Now, "0", artist: "B", song: "B", extension: "", filename: "", videoId: "A", uploaderId: null); context.CreateAudio(DateTime.Now, "1", artist: "B", song: "A", extension: "", filename: "", videoId: "B", uploaderId: null); context.CreateAudio(DateTime.Now, "2", artist: "A", song: "B", extension: "", filename: "", videoId: "C", uploaderId: null); context.SaveChanges(); var result = audioService.SearchAudios("A", 0, 10); CheckIfSuccess(result); Assert.Equal(result.Audios.Count(), 3); Assert.Equal(result.Audios.ElementAt(0).AccessUrl, "0"); Assert.Equal(result.Audios.ElementAt(1).AccessUrl, "1"); Assert.Equal(result.Audios.ElementAt(2).AccessUrl, "2"); } }); }
protected Guid GetUserId(PlayCatDbContext context) { string password = "******"; string email = "*****@*****.**"; User user = context.CreateUser(email, "test", "test", "m", password); AuthToken authToken = context.CreateToken(DateTime.Now.AddDays(-1), false, user.Id); context.SaveChanges(); return(user.Id); }
public void IsUpdateTokenSignIn() { SqlLiteDatabaseTest(options => { var authService = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService; var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService; using (var context = new PlayCatDbContext(options)) { authService.SetDbContext(context); string password = "******"; string email = "*****@*****.**"; string salt = Crypto.GenerateSalt(); string passwordHah = Crypto.HashPassword(password + salt); var user = context.Users.Add(new DataModel.User() { Id = Guid.NewGuid(), Email = email, FirstName = "test", LastName = "test", PasswordHash = passwordHah, PasswordSalt = salt, RegisterDate = DateTime.Now, VerificationCode = inviteService.GenerateInvite(), }); var authToken = context.AuthTokens.Add(new DataModel.AuthToken() { Id = Guid.NewGuid(), DateExpired = DateTime.Now.AddDays(-1), IsActive = false, UserId = user.Entity.Id, }); context.SaveChanges(); SignUpInResult result = authService.SignIn(new SignInRequest() { Email = email, Password = password, }); var updatedAuthToken = context.AuthTokens.FirstOrDefault(); Assert.NotNull(updatedAuthToken); Assert.True(updatedAuthToken.DateExpired > DateTime.Now); Assert.True(updatedAuthToken.IsActive); } }); }
private new Guid GetUserId(PlayCatDbContext context) { string password = "******"; string email = "*****@*****.**"; User user = context.CreateUser(email, "test", "test", "m", password); Playlist playlist = context.CreatePlaylist(true, user.Id, "General", 0); AuthToken authToken = context.CreateToken(DateTime.Now.AddDays(-1), false, user.Id); context.SaveChanges(); return(user.Id); }
protected Guid GetUserId(PlayCatDbContext context) { var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService; string password = "******"; string email = "*****@*****.**"; DataModel.User user = context.CreateUser(email, "test", "test", "m", password, inviteService.GenerateInvite()); DataModel.AuthToken authToken = context.CreateToken(DateTime.Now.AddDays(-1), false, user.Id); context.SaveChanges(); return(user.Id); }
public void ShouldFailOnAlreadyUpload() { SqlLiteDatabaseTest(options => { var uploadService = _server.Host.Services.GetService(typeof(IUploadService)) as IUploadService; var fileResolver = _server.Host.Services.GetService(typeof(IFileResolver)) as IFileResolver; using (var context = new PlayCatDbContext(options)) { uploadService.SetDbContext(context); string youtubeUrl = "https://www.youtube.com/watch?v=yPYZpwSpKmA"; var request = new UrlRequest() { Url = youtubeUrl, }; GetInfoResult result = uploadService.GetInfo(request); CheckIfSuccess(result); Guid userId = GetUserId(context); context.CreatePlaylist(true, userId, null, 0); context.SaveChanges(); Assert.NotNull(result.UrlInfo); Assert.Equal("Rick Astley", result.UrlInfo.Artist); Assert.Equal("Together Forever", result.UrlInfo.Song); var uploadResult = uploadService.UploadAudioAsync(userId, new UploadAudioRequest() { Artist = "Rick Astley", Song = "Together Forever", Url = youtubeUrl, }).Result; CheckIfSuccess(uploadResult); string audioFilePath = fileResolver.GetAudioFolderPath(StorageType.FileSystem); File.Delete(Path.Combine(audioFilePath, "yPYZpwSpKmA.mp3")); GetInfoResult checkAgainResult = uploadService.GetInfo(request); CheckIfFail(checkAgainResult); Assert.Equal("Video already uploaded", checkAgainResult.Info); } }); }
public void IsExpiredToken() { SqlLiteDatabaseTest(options => { var authService = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService; var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService; using (var context = new PlayCatDbContext(options)) { authService.SetDbContext(context); var user = context.Users.Add(new DataModel.User() { Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "test", LastName = "test", PasswordHash = "123123", PasswordSalt = "123", RegisterDate = DateTime.Now, VerificationCode = "123", }); var authToken = context.AuthTokens.Add(new DataModel.AuthToken() { Id = Guid.NewGuid(), DateExpired = DateTime.Now.AddDays(-1), IsActive = true, UserId = user.Entity.Id, }); context.SaveChanges(); var baseResult = authService.CheckToken(authToken.Entity.Id.ToString()); Assert.NotNull(baseResult); Assert.Equal("Token is expired", baseResult.Info); Assert.False(baseResult.ShowInfo); Assert.False(baseResult.Ok); Assert.Null(baseResult.Errors); Assert.Equal(ResponseCode.InvalidToken, baseResult.Code); } }); }
public void IsTokenIsInactive() { SqlLiteDatabaseTest(options => { var authService = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService; using (var context = new PlayCatDbContext(options)) { authService.SetDbContext(context); var user = context.Users.Add(new User { Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "test", LastName = "test", PasswordHash = new byte[] { 1 }, PasswordSalt = new byte[] { 1 }, RegisterDate = DateTime.Now, }); var authToken = context.AuthTokens.Add(new AuthToken { Id = Guid.NewGuid(), DateExpired = DateTime.Now.AddDays(10), IsActive = false, UserId = user.Entity.Id }); context.SaveChanges(); var baseResult = authService.CheckToken(authToken.Entity.Id.ToString()); Assert.NotNull(baseResult); Assert.Equal("Token is not active", baseResult.Info); Assert.False(baseResult.ShowInfo); Assert.False(baseResult.Ok); Assert.Null(baseResult.Errors); Assert.Equal(ResponseCode.InvalidToken, baseResult.Code); } }); }
public void SearchByComposeArtistAndSong() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); context.CreateAudio(DateTime.Now, "0", artist: "A", song: "B", extension: "", filename: "", videoId: "", uploaderId: null); context.SaveChanges(); var result = audioService.SearchAudios("A B", 0, 10); CheckIfSuccess(result); Assert.Equal(result.Audios.Count(), 1); } }); }
public void ShouldFailGetProfileOnWrongId() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IProfileService)) as IProfileService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); var user = context.CreateUser("*****@*****.**", "v", "last", "m", "123", "123"); context.SaveChanges(); var result = playListService.GetProfile(Guid.Empty); CheckIfFail(result); Assert.True(result.Info.Any()); } }); }
public void ShouldDeleteFailOnRemoveGeneral() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModel.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0); context.SaveChanges(); var result = playListService.DeletePlaylist(userId, generalPlaylist.Id); CheckIfFail(result); Assert.True(result.Info.Any()); } }); }
public void ShouldEmptyOnWrongId() { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); CreateAndAddAudio(context, playlist.Id, 10); context.SaveChanges(); AudioResult result = audioService.GetAudios(Guid.Empty, 0, 10); CheckIfSuccess(result); Assert.Equal(0, result.Audios.Count()); } }); }
public void ShouldFailDeleteOnWrongPlaylistId() { SqlLiteDatabaseTest(options => { var playListService = _server.Host.Services.GetService(typeof(IPlaylistService)) as IPlaylistService; using (var context = new PlayCatDbContext(options)) { playListService.SetDbContext(context); Guid userId = GetUserId(context); //create general DataModels.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); context.SaveChanges(); var result = playListService.DeletePlaylist(userId, Guid.Empty); CheckIfFail(result); Assert.Equal("Playlist not found", result.Info); } }); }
public void ShouldReturnAudios(int count, int skip, int take, int actual) { SqlLiteDatabaseTest(options => { var audioService = _server.Host.Services.GetService(typeof(IAudioService)) as IAudioService; using (var context = new PlayCatDbContext(options)) { audioService.SetDbContext(context); Guid userId = GetUserId(context); DataModel.Playlist playlist = context.CreatePlaylist(true, userId, null, 0); CreateAndAddAudio(context, playlist.Id, count); context.SaveChanges(); AudioResult result = audioService.GetAudios(playlist.Id, skip, take); CheckIfSuccess(result); Assert.Equal(actual, result.Audios.Count()); } }); }