public async Task Index_ReturnsAllVideos() { // Arrange var videoModel = new VideoConciseViewModel() { Id = 1, Title = "First" }; bool methodCalled = false; var mockRepository = new Mock <IAdminVideosService>(); mockRepository.Setup(s => s.GetAllVideosAsync()) .ReturnsAsync(new[] { videoModel }) .Callback(() => methodCalled = true); var userRepository = new Mock <IAdminUsersService>(); userRepository.Setup(repo => repo.GetAuthorsAsync()) .Callback(() => methodCalled = true); var controller = new VideosController(userRepository.Object, mockRepository.Object); // Act var result = await controller.Index(); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); var resultView = result as ViewResult; Assert.IsNotNull(resultView.Model); Assert.IsInstanceOfType(resultView.Model, typeof(IEnumerable <VideoConciseViewModel>)); Assert.IsTrue(methodCalled); }
public MergeVersionsManager(ILibraryManager libraryManager, ICollectionManager collectionManager, ILogger <VideosController> logger, IServerConfigurationManager serverConfigurationManager, IUserManager userManager, IDtoService dtoService, IAuthorizationContext authContext, IFileSystem fileSystem, IDlnaManager dlnaManager, IMediaSourceManager mediaSourceManager, IMediaEncoder mediaEncoder, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, TranscodingJobHelper transcodingJobHelper ) { _libraryManager = libraryManager; _userManager = userManager; _logger = logger; _timer = new Timer(_ => OnTimerElapsed(), null, Timeout.Infinite, Timeout.Infinite); _videosController = new VideosController(_libraryManager, _userManager, dtoService, dlnaManager, authContext, mediaSourceManager, serverConfigurationManager, mediaEncoder, fileSystem, subtitleEncoder, null, deviceManager, transcodingJobHelper, null); _fileSystem = fileSystem; }
public void GetVideosFromService() { // Arrange var mockedVideos = new VideoModel[] { new VideoModel { Title = "First", Url = "FirstUrl" }, new VideoModel { Title = "Second", Url = "SecondUrl" } }; var mockedService = new Mock <IVideoService>(); mockedService.Setup(s => s.GetVideosFromGallery(It.IsAny <string>())).Returns(mockedVideos).Verifiable(); var controller = new VideosController(mockedService.Object); // Act var result = controller.GetAll(null); // Assert StringAssert.Contains(mockedVideos[0].Title, result); StringAssert.Contains(mockedVideos[0].Url, result); StringAssert.Contains(mockedVideos[1].Title, result); StringAssert.Contains(mockedVideos[1].Url, result); mockedService.Verify(s => s.GetVideosFromGallery(It.IsAny <string>()), Times.Once); }
public async void DeleteVideo_CalledWithInvalidId_ReturnsNotFoundWithId() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); var context = Substitute.For <HttpContext>(); long notValidId = 1; Video nullVideo = null; unitOfWork.Videos.GetById(notValidId).Returns(nullVideo); cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString()); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); videosController.ControllerContext = new ControllerContext() { HttpContext = context }; var result = await videosController.DeleteVideo(notValidId); var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); var returnValue = Assert.IsType <long>(notFoundObjectResult.Value); Assert.Equal(notValidId, returnValue); }
public async Task TestVideosWithCategory_InvalidParameters_ReturnsBadResult() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); var video = GetDemoVideoInstance(1); context.Videos.Add(video); video = GetDemoVideoInstance(2); video.Category = 0; context.Videos.Add(video); video = GetDemoVideoInstance(3); video.Category = 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.GetVideosWithCategory(new List <CategoryModel> { CategoryModel.Movie, CategoryModel.Audio }, "testuser") as OkNegotiatedContentResult <IList <VideoModel> >; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(result.Content.Count, 2); }
public async void DeleteVideo_CalledAndRoleIsNotAdmin_ReturnsBadRequestWithError() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); var context = Substitute.For <HttpContext>(); long testId = 1; var testVideo = new Video(); string error = "Only Admins can delete videos."; unitOfWork.Videos.GetById(testId).Returns(testVideo); cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Student.ToString()); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); videosController.ControllerContext = new ControllerContext() { HttpContext = context }; var result = await videosController.DeleteVideo(testId); var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); var retrunValue = Assert.IsType <string>(badRequestObjectResult.Value); Assert.Equal(error, retrunValue); }
public async Task TestPutVideo_ReturnsSucess() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); controller.Request = new System.Net.Http.HttpRequestMessage { RequestUri = new Uri("http://localhost/api/Video") }; controller.Configuration = new System.Web.Http.HttpConfiguration(); controller.Configuration.Routes.MapHttpRoute( name: "GetVideoByLink", routeTemplate: "api/GetVideo" ); controller.RequestContext.RouteData = new HttpRouteData( route: new HttpRoute(), values: new HttpRouteValueDictionary { { "controller", "Video" } }); var video = GetDemoVideoModelInstance(1); var result = await controller.PostVideo(video) as CreatedAtRouteNegotiatedContentResult <VideoModel>; Assert.IsNotNull(result); Assert.AreEqual(result.RouteName, "GetVideoByLink"); Assert.AreEqual(result.RouteValues["link"], "test.com/check"); Assert.AreEqual(result.RouteValues["user"], "testuser"); }
public async Task TestGetVideoWithPeople_InvalidParameters_ReturnsBadResult() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var video = GetDemoVideoInstance(1); video.Participants.Add(new Participant { Name = "tester" }); context.Videos.Add(video); var controller = new VideosController(context); 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.GetVideosWithPeople(null, "nosuchuser"); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }
public async void AddVideo_CalledAndRoleIsNotAdmin_ReturnsBadRequestWithError() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); var context = Substitute.For <HttpContext>(); long testId = 1; var testVideo = new VideoViewModel(); ModuleContent nullModuleContent = null; string testUrl = "testurl"; string convertedUrl = "converted"; string testyoutubeId = "youtubeid"; string error = "Only Admins can add videos."; unitOfWork.ModuleContents.GetById(testId).Returns(nullModuleContent); videoManager.ConvertUrl(testUrl).Returns(convertedUrl); videoManager.GetYoutubeId(convertedUrl).Returns(testyoutubeId); cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Student.ToString()); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); videosController.ControllerContext = new ControllerContext() { HttpContext = context }; var result = await videosController.AddVideo(testVideo); var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); var returnValue = Assert.IsType <string>(badRequestObjectResult.Value); Assert.Equal(error, returnValue); }
public async void DeleteVideo_CalledWithValidId_ReturnsOk() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); var context = Substitute.For <HttpContext>(); long testId = 1; var testVideo = new Video(); unitOfWork.Videos.GetById(testId).Returns(testVideo); cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString()); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); videosController.ControllerContext = new ControllerContext() { HttpContext = context }; var result = await videosController.DeleteVideo(testId); var okResult = Assert.IsType <OkResult>(result); Assert.Equal(200, okResult.StatusCode); }
public async Task TestGetVideoWithPeople_ReturnsVideos() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var video = GetDemoVideoInstance(1); video.Participants.Add(new Participant { Name = "tester" }); context.Videos.Add(video); var controller = new VideosController(context); 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.GetVideosWithPeople(new List <string> { "tester" }, "testuser") as OkNegotiatedContentResult <IList <VideoModel> >; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(result.Content.Count, 1); }
public async Task TestGetVideos_NoSuchUser_ReturnsBadRequest() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); var controller = new VideosController(context); controller.Url = mockUrl.Object; context.Videos.Add(GetDemoVideoInstance(1)); context.Videos.Add(GetDemoVideoInstance(2)); context.Videos.Add(GetDemoVideoInstance(3)); var result = await controller.GetVideos("nosuchuser"); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }
protected override void SetupFixtureContext() { _mocks = new RhinoAutoMocker<VideosController>(); Controller = _mocks.ClassUnderTest; _video = new Video() {Id = Guid.NewGuid()}; }
public PutTests() { var sessionFactory = Substitute.For <ISessionFactory>(); _session = sessionFactory.CreateCommandSession(); _controller = new VideosController(sessionFactory); }
public async void AddVideo_CalledWithValidVideo_ReturnsOk() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); var context = Substitute.For <HttpContext>(); long testId = 1; var testVideo = new VideoViewModel() { ModuleContentId = testId }; var testModuleContent = new ModuleContent(); string testUrl = "testurl"; string convertedUrl = "converted"; string testyoutubeId = "youtubeid"; unitOfWork.ModuleContents.GetById(testId).Returns(testModuleContent); videoManager.ConvertUrl(testUrl).Returns(convertedUrl); videoManager.GetYoutubeId(convertedUrl).Returns(testyoutubeId); cookieManager.GetRoleFromToken(Arg.Any <string>()).Returns(Role.Admin.ToString()); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); videosController.ControllerContext = new ControllerContext() { HttpContext = context }; var result = await videosController.AddVideo(testVideo); var okResult = Assert.IsType <OkResult>(result); Assert.Equal(200, okResult.StatusCode); }
public VideosControllerTest() { _videoServiceMock = new Mock <IVideoService>(); _controller = new VideosController(_videoServiceMock.Object); _videos = new List <VideoDTO> { _video1, _video2, _video3 }; }
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); }
public void GetAll_ReturnResults() { // Arrange var logger = Substitute.For <ILogger>(); var controller = new VideosController(logger); // Act var result = controller.GetAll(); //Assert Assert.NotNull(result); Assert.NotEqual(0, result.Count()); }
public async Task TestGetRandomVideo() { using (var context = new GuessContext(Options)) { // Make a new video controller VideosController videosController = new VideosController(context, _mapper); // Get the result of GetRandomVideo method ActionResult <IEnumerable <Video> > result = await videosController.GetRandomVideo(); // Check whether the result is null Assert.IsNotNull(result); } }
public async Task TestPostVideo() { using (var context = new GuessContext(Options)) { // Make a new video controller VideosController videosController = new VideosController(context, _mapper); // Get the result of PostVideo method ActionResult <Video> result = await videosController.PostVideo(Url); // Check whether the result is null Assert.IsNotNull(result); } }
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)); }
public async Task TestGetVideoByTitle_InvalidParameters_ReturnVideo() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); context.Videos.Add(GetDemoVideoInstance(1)); var result = await controller.GetVideoByTitle(null, null); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }
public void ReturnDefaultView_WithGettedVideoFromService() { // Arrange var mockedVideo = new VideoModel { Title = "Test video" }; var mockedVideoService = new Mock <IVideoService>(); mockedVideoService.Setup(s => s.GetVideoById(It.IsAny <string>())).Returns(mockedVideo).Verifiable(); var controller = new VideosController(mockedVideoService.Object); // Act var result = controller.Watch("some id") as ViewResult; var model = result.ViewData.Model as VideoModel; // Assert Assert.AreEqual("", result.ViewName); Assert.AreEqual(mockedVideo, model); }
public async void GetVideo_CalledWithInvalidId_ReturnsNotFoundWithId() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); long notValidId = 1; Video video = null; unitOfWork.Videos.GetById(notValidId).Returns(video); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); var result = await videosController.GetVideo(notValidId); var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); var returnValue = Assert.IsType <long>(notFoundObjectResult.Value); Assert.Equal(notValidId, returnValue); }
public async void GetVideosByModuleContentId_CalledWithInvalidId_ReturnsNotFoundWithId() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); long testId = 1; List <Video> nullVideos = null; unitOfWork.Videos.GetVideosByModuleContentId(testId).Returns(nullVideos); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); var result = await videosController.GetVideosByModuleContentId(testId); var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); var returnValue = Assert.IsType <long>(notFoundObjectResult.Value); Assert.Equal(testId, returnValue); }
public async Task TestGetVideoWithAnyTag_ReturnVideos() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); var controller = new VideosController(context); controller.Url = mockUrl.Object; context.Videos.Add(GetDemoVideoInstance(2)); context.Videos.Add(GetDemoVideoInstance(1)); context.Tags.Add(new Tag { TagName = "test", VideoId = 1 }); context.Tags.Add(new Tag { TagName = "fun", VideoId = 1 }); context.Tags.Add(new Tag { TagName = "nontest", VideoId = 2 }); context.Tags.Add(new Tag { TagName = "nonfun", VideoId = 2 }); var result = await controller.GetVideosWithAnyTag(new List <string> { "test", "nonfun" }, "testuser") as OkNegotiatedContentResult <IList <VideoModel> >; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(result.Content.Count, 2); }
public async Task TestPostVideo_ReturnError() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); var mockurl = new Mock <UrlHelper>(); mockurl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns("https://testlocation"); controller.Url = mockurl.Object; var video = GetDemoVideoModelInstance(1); video.VideoLink = null; var result = await controller.PostVideo(video); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }
public async Task TestGetVideoByTitle_ReturnVideo() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var controller = new VideosController(context); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); context.Videos.Add(GetDemoVideoInstance(1)); var result = await controller.GetVideoByTitle("test", "testuser") as OkNegotiatedContentResult <VideoModel>; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.AreEqual(result.Content.Title, "test"); }
public async Task TestGetVideoWithAnyTag_InvalidParameters_ReturnsBadResult() { var context = new TestContext(); context.Users.Add(new User { UserId = 1, Username = "******" }); var location = "http://location/"; var mockUrl = new Mock <UrlHelper>(); mockUrl.Setup(x => x.Link(It.IsAny <string>(), It.IsAny <object>())).Returns(location); var controller = new VideosController(context); controller.Url = mockUrl.Object; context.Videos.Add(GetDemoVideoInstance(2)); context.Videos.Add(GetDemoVideoInstance(1)); context.Tags.Add(new Tag { TagName = "test", VideoId = 1 }); context.Tags.Add(new Tag { TagName = "fun", VideoId = 1 }); context.Tags.Add(new Tag { TagName = "nontest", VideoId = 2 }); context.Tags.Add(new Tag { TagName = "nonfun", VideoId = 2 }); var result = await controller.GetVideosWithAnyTag(new List <string> { "nosuchtag", "nosuchtag2" }, null); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }
public async void GetAllVideos_Called_ReturnsOkWithListOfVideos() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); var testList = new List <Video>() { new Video(), new Video(), new Video(), new Video() }; unitOfWork.Videos.GetAll().Returns(testList); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); var result = await videosController.GetAllVideos(); var okObjectResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <List <Video> >(okObjectResult.Value); Assert.Equal(testList.Count, returnValue.Count); }
public async void GetVideo_CalledWithValidId_ReturnsOkWithVideo() { IUnitOfWork unitOfWork = Substitute.For <IUnitOfWork>(); IVideoManager videoManager = Substitute.For <IVideoManager>(); ICookieManager cookieManager = Substitute.For <ICookieManager>(); long testId = 1; var video = new Video() { Id = testId }; unitOfWork.Videos.GetById(testId).Returns(video); var videosController = new VideosController(unitOfWork, videoManager, cookieManager); var result = await videosController.GetVideo(testId); var okObjectResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <Video>(okObjectResult.Value); Assert.Equal(testId, returnValue.Id); }
protected override void SetupFixtureContext() { _mocks = new RhinoAutoMocker<VideosController>(); Controller = _mocks.ClassUnderTest; _vidList = new List<Video>() { new Video(), new Video(), new Video(), new Video() }; }