Exemplo n.º 1
0
        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
                    DataModels.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0);

                    DataModels.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);
                }
            });
        }
Exemplo n.º 2
0
        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);

                    DataModels.Playlist playlist  = context.CreatePlaylist(true, userId, null, 0);
                    DataModels.Playlist playlist2 = context.CreatePlaylist(false, userId, "Rock", 0);
                    DataModels.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());
                }
            });
        }
Exemplo n.º 3
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);

                    DataModels.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());
                }
            });
        }
Exemplo n.º 4
0
        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);

                    DataModels.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());
                }
            });
        }
Exemplo n.º 5
0
        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);

                    DataModels.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);
                    }
                }
            });
        }
Exemplo n.º 6
0
        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
                    DataModels.Playlist playlist = context.CreatePlaylist(true, userId, null, 0);

                    DataModels.Playlist playlist1 = context.CreatePlaylist(false, userId, "playlist1", 0);
                    DataModels.Playlist playlist2 = context.CreatePlaylist(false, userId, "playlist2", 0);
                    DataModels.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()));
                }
            });
        }
Exemplo n.º 7
0
        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
                    DataModels.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));
                }
            });
        }
Exemplo n.º 8
0
        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
                    DataModels.Playlist playlist = context.CreatePlaylist(true, userId, null, 0);
                    context.SaveChanges();

                    var result = playListService.CreatePlaylist(userId, new CreatePlaylistRequest
                    {
                        Title = "13"
                    });

                    CheckIfFail(result);
                }
            });
        }
Exemplo n.º 9
0
        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
                    DataModels.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);
                }
            });
        }
Exemplo n.º 10
0
 public static Playlist FromData(DataModels.Playlist playlist)
 {
     return(playlist == null ? null : new Playlist
     {
         Id = playlist.Id,
         IsGeneral = playlist.IsGeneral,
         Title = playlist.Title,
         Owner = UserMapper.ToApi.FromData(playlist.Owner)
     });
 }
        public async Task <Playlist> AddAsync(Playlist newPlaylist, CancellationToken ct = default(CancellationToken))
        {
            var playlist = new DataModels.Playlist {
                Name = newPlaylist.Name
            };

            _context.Playlist.Add(playlist);
            await _context.SaveChangesAsync(ct);

            newPlaylist.PlaylistId = playlist.PlaylistId;
            return(newPlaylist);
        }
Exemplo n.º 12
0
        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
                    DataModels.Playlist generalPlaylist = context.CreatePlaylist(true, userId, null, 0);
                    context.SaveChanges();

                    var result = playListService.DeletePlaylist(userId, generalPlaylist.Id);

                    CheckIfFail(result);
                    Assert.True(result.Info.Any());
                }
            });
        }