Exemplo n.º 1
0
        public async Task TestGetVideosInPlaylist_ReturnsVideos()
        {
            var context = new TestContext();

            context.Users.Add(new User
            {
                UserId   = 1,
                Username = "******"
            });
            var controller = new VideosController(context);

            context.Playlists.Add(new Playlist
            {
                PlaylistName = "testPlaylist",
                PlaylistId   = 1,
                username     = "******"
            });
            context.Playlists.Add(new Playlist
            {
                PlaylistName = "testPlaylistfun",
                PlaylistId   = 2,
                username     = "******"
            });
            var video = GetDemoVideoInstance(1);

            video.Playlists.Add(new Playlist
            {
                PlaylistId = 1,
            });
            context.Videos.Add(video);

            video = GetDemoVideoInstance(2);
            video.Playlists.Add(new Playlist
            {
                PlaylistId = 1,
            });
            context.Videos.Add(video);

            video = GetDemoVideoInstance(2);
            video.Playlists.Add(new Playlist
            {
                PlaylistId = 2
            });
            context.Videos.Add(video);
            var location = "http://location/";
            var mockUrl  = new Mock <UrlHelper>();

            mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location);
            controller.Url = mockUrl.Object;
            var result = await controller.GetVideosInPlayList("testPlaylist", "testuser") as OkNegotiatedContentResult <IList <VideoModel> >;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(result.Content.Count, 2);
        }
Exemplo n.º 2
0
        public async Task TestGetVideosInPlaylist_ReturnsBadResult()
        {
            var context   = new TestContext();
            var playlist1 = new Playlist
            {
                PlaylistName = "testPlaylist",
                PlaylistId   = 1,
                username     = "******"
            };
            var playlist2 = new Playlist
            {
                PlaylistName = "testPlaylistfun",
                PlaylistId   = 2,
                username     = "******"
            };

            context.Playlists.Add(playlist1);
            context.Playlists.Add(playlist2);


            context.Users.Add(new User
            {
                UserId   = 1,
                Username = "******"
            });
            var controller = new VideosController(context);

            var video = GetDemoVideoInstance(1);

            video.Playlists.Add(playlist1);
            context.Videos.Add(video);

            video = GetDemoVideoInstance(2);
            video.Playlists.Add(playlist2);
            context.Videos.Add(video);

            video = GetDemoVideoInstance(3);
            video.Playlists.Add(playlist2);
            context.Videos.Add(video);
            var location = "http://location/";
            var mockUrl  = new Mock <UrlHelper>();

            mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location);
            controller.Url = mockUrl.Object;
            var result = await controller.GetVideosInPlayList("nosuchplaylist", "testuser");

            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
        }