public async Task GetAllPlaylistsByUserCorrectly()
        {
            var options = Utils.GetOptions(nameof(GetAllPlaylistsByUserCorrectly));

            var nirvanaPlaylist = new PlaylistDTO
            {
                Title    = "In Utero",
                Duration = 1600,
                //PixabayImage = "https://en.wikipedia.org/wiki/In_Utero_(album)#/media/File:In_Utero_(Nirvana)_album_cover.jpg",
                UserId = "153a257-526504u",
            };

            var acdcPlaylist = new PlaylistDTO
            {
                Title    = "Back in Black",
                Duration = 2531,
                //PixabayImage = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/ACDC_Back_in_Black.png/220px-ACDC_Back_in_Black.png",
                UserId = "153a257-526504u",
            };

            var scorpionsPLaylist = new PlaylistDTO
            {
                Title    = "Lovedrive",
                Duration = 2190,
                //PixabayImage = "https://en.wikipedia.org/wiki/Lovedrive#/media/File:Scorpions-album-lovedrive.jpg",
                UserId = "68910y78a-89as1568",
            };

            using (var arrangeContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(arrangeContext);

                await sut.Create(nirvanaPlaylist);

                await sut.Create(acdcPlaylist);

                await sut.Create(scorpionsPLaylist);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(assertContext);

                var firstUserPalylists = await sut.GetPlaylistsByUser("153a257-526504u");

                int firstUserPalylistsCount = firstUserPalylists.Count();

                var secondUserPalylists = await sut.GetPlaylistsByUser("68910y78a-89as1568");

                int secondUserPalylistsCount = secondUserPalylists.Count();

                Assert.AreEqual(2, firstUserPalylistsCount);
                Assert.AreEqual(1, secondUserPalylistsCount);
            }
        }
Exemplo n.º 2
0
        public async Task DeleteThrowsWhenIdAlreadyDeleted()
        {
            var options = Utils.GetOptions(nameof(DeleteThrowsWhenIdAlreadyDeleted));

            var playlist = new PlaylistDTO
            {
                Title    = "In Utero",
                Duration = 1600,
                //PixabayImage = "https://en.wikipedia.org/wiki/In_Utero_(album)#/media/File:In_Utero_(Nirvana)_album_cover.jpg",
            };

            using (var arrangeContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(arrangeContext);
                await sut.Create(playlist);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(assertContext);

                await sut.Delete(1);

                await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.Delete(1));
            }
        }
Exemplo n.º 3
0
        public async Task DeleteCorrectly()
        {
            var options = Utils.GetOptions(nameof(DeleteCorrectly));

            var playlist = new PlaylistDTO
            {
                Title    = "In Utero",
                Duration = 1600,
                //PixabayImage = "https://en.wikipedia.org/wiki/In_Utero_(album)#/media/File:In_Utero_(Nirvana)_album_cover.jpg",
            };

            using (var arrangeContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(arrangeContext);
                await sut.Create(playlist);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(assertContext);
                await sut.Delete(1);

                var playlists = await sut.GetAllPlaylists();

                int playlistsCount = playlists.Count();

                Assert.AreEqual(0, playlistsCount);
            }
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Create(PlaylistChangeModel pmodel)
        {
            if (ModelState.IsValid)
            {
                OperationDetails operationDetails = await PlaylistService.Create(new PlaylistDTO()
                {
                    Name   = pmodel.Name,
                    UserId = User.Identity.GetUserId(),
                    Musics = pmodel.MusicsId.Select(x => new MusicDTO()
                    {
                        Id = x
                    }).ToList()
                });

                if (operationDetails.Succedeed)
                {
                    return(RedirectToAction("PlaylistView"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }

            return(View(pmodel));
        }
        public async System.Threading.Tasks.Task <RedirectResult> PlaylistCreate()
        {
            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
            {
                string body = await reader.ReadToEndAsync();

                body = body.Replace("+", " ").Replace("=on", "");
                Stack <string> brokenOutPlayStack = new Stack <string>();
                string[]       brokenOutPlaylist  = body.Split('&');
                foreach (var item in brokenOutPlaylist)
                {
                    brokenOutPlayStack.Push(item);
                }
                string playlistId   = brokenOutPlayStack.Pop().Replace("playlistid=", "");
                string playlistName = brokenOutPlayStack.Pop().Replace("playlistname=", "");
                if (playlistId != "")
                {
                    _playlistService.Update(playlistId, new PlaylistModel {
                        playlistname = playlistName, videos = brokenOutPlayStack, __v = 0
                    });
                }
                else
                {
                    PlaylistModel newDoc = _playlistService.Create(new PlaylistModel {
                        playlistname = playlistName, videos = brokenOutPlayStack, __v = 0
                    });
                    playlistId = newDoc.Id;
                }
                string referrer = Request.Headers["Referer"].ToString() + "playlistorder?id=" + playlistId;
                return(Redirect(referrer));
            }
        }
Exemplo n.º 6
0
        public async Task CreateCorrectly()
        {
            var options = Utils.GetOptions(nameof(CreateCorrectly));

            var playlist = new PlaylistDTO
            {
                Title    = "In Utero",
                Duration = 1600,
                //PixabayImage = "https://en.wikipedia.org/wiki/In_Utero_(album)#/media/File:In_Utero_(Nirvana)_album_cover.jpg",
            };

            using (var arrangeContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(arrangeContext);
                await sut.Create(playlist);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new PGDbContext(options))
            {
                var result = await assertContext.Playlists.FirstOrDefaultAsync(x => x.Title == playlist.Title);

                Assert.AreEqual(playlist.Title, result.Title);
                Assert.AreEqual(playlist.Duration, result.Duration);
                //Assert.AreEqual(playlist.PixabayImage, result.Picture);
            }
        }
Exemplo n.º 7
0
        public async Task CreateThrowsWhenNull()
        {
            var options = Utils.GetOptions(nameof(CreateThrowsWhenNull));

            var context = new PGDbContext(options);
            var sut     = new PlaylistService(context);

            await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.Create(null));
        }
Exemplo n.º 8
0
        public async Task GetPlaylistByIdCorrectly()
        {
            var options = Utils.GetOptions(nameof(GetPlaylistByIdCorrectly));

            var nirvanaPlaylist = new PlaylistDTO
            {
                Title    = "In Utero",
                Duration = 1600,
                //PixabayImage = "https://en.wikipedia.org/wiki/In_Utero_(album)#/media/File:In_Utero_(Nirvana)_album_cover.jpg",
            };

            var acdcPlaylist = new PlaylistDTO
            {
                Title    = "Back in Black",
                Duration = 2531,
                //PixabayImage = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/92/ACDC_Back_in_Black.png/220px-ACDC_Back_in_Black.png",
            };

            using (var arrangeContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(arrangeContext);

                await sut.Create(nirvanaPlaylist);

                await sut.Create(acdcPlaylist);

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new PGDbContext(options))
            {
                var sut = new PlaylistService(assertContext);

                var userPalylists = await sut.GetPlaylistById(1);

                Assert.AreEqual(nirvanaPlaylist.Title, userPalylists.Title);
                Assert.AreEqual(nirvanaPlaylist.Duration, userPalylists.Duration);
                Assert.AreEqual(nirvanaPlaylist.PixabayImage, userPalylists.PixabayImage);
            }
        }
Exemplo n.º 9
0
        public async Task CreateThrowsWhenNameAbove50Chars()
        {
            var options = Utils.GetOptions(nameof(CreateThrowsWhenNameAbove50Chars));


            var context = new PGDbContext(options);
            var sut     = new PlaylistService(context);

            var playlist = new PlaylistDTO
            {
                Title    = "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
                Duration = 1600,
                //PixabayImage = "https://en.wikipedia.org/wiki/In_Utero_(album)#/media/File:In_Utero_(Nirvana)_album_cover.jpg",
            };

            await Assert.ThrowsExceptionAsync <ArgumentOutOfRangeException>(() => sut.Create(playlist));
        }