public ListDetailForm(string name, ListBox box) { InitializeComponent(); service = new VideoService(); lb = box; ListName = name; oldName = name; listNameText.DataBindings.Add("Text", this, "ListName"); listView1.View = View.LargeIcon; listView1.LargeImageList = this.imageList1; listBox1.DrawMode = DrawMode.OwnerDrawVariable; listBox1.DrawItem += ListBox1_DrawItem; listBox1.MeasureItem += ListBox1_MeasureItem; InitListBoxItem(); List <string> listID = service.GetVideoList(name); ListID = listID[0]; videos = service.GetFileFromList(ListID); documents = service.GetDocument(ListID); ListViewUpdate(videos); ListViewUpdate(ListID); }
// GET: Details public ActionResult Details(int?languageId, int?id) { if (languageId is null || id is null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var service = CreateWordService((int)languageId); var model = service.GetWordById((int)id); var sentenceService = new SentenceService(Guid.Parse(User.Identity.GetUserId()), (int)id); List <SentenceListItem> sentences = new List <SentenceListItem>(); foreach (var item in model.Sentences) { sentences.Add(sentenceService.GetSentenceById(item.Key)); } ViewBag.Sentences = sentences; var videoService = new VideoService(Guid.Parse(User.Identity.GetUserId()), (int)id); List <VideoDetail> videos = new List <VideoDetail>(); foreach (var item in model.Videos) { videos.Add(videoService.GetVideoById(item.Key)); } ViewBag.Videos = videos; return(View(model)); }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("BackgroundService entry point called", "Information"); // Connect to SignalR var connection = new HubConnection(CloudConfigurationManager.GetSetting("ApiBaseUrl")); var proxy = connection.CreateHubProxy("Notifier"); connection.Start().Wait(); while (true) { Thread.Sleep(5000); var service = new VideoService(); Trace.WriteLine("Getting Media Services active jobs", "Information"); var activeJobs = service.GetActiveJobs(); foreach (var video in activeJobs.ToList()) { proxy.Invoke( "VideoUpdated", (video.JobStatus == JobStatus.Completed) ? service.Publish(video.Id) : video); } } }
public void Setup() { _fileReader = new Mock <IFileReader>(); _videoRepository = new Mock <IVideoRepository>(); _service = new VideoService(_fileReader.Object, _videoRepository.Object); }
private async void BindListData() { try { searchActivityIndicator.IsRunning = true; searchActivityIndicator.IsVisible = true; VideoService videoService = new VideoService(); var listVideoViewModel = await videoService.GetAllVideosBySearchAsync(videoSearchBar.Text, slug); if (listVideoViewModel.Count > 0) { lblMsg.IsVisible = false; lstVideos.ItemsSource = listVideoViewModel; } else { lstVideos.ItemsSource = null; lblMsg.IsVisible = true; } } catch (Exception pException) { System.Diagnostics.Debug.WriteLine("Exception : " + pException.Message); lblMsg.IsVisible = true; } finally { GC.Collect(); searchActivityIndicator.IsRunning = false; searchActivityIndicator.IsVisible = false; } }
public void Get_Video_By_Id() { var videos = new List <Video> { new Video { Title = "Def", Id = 324 }, new Video { Title = "Abc", Id = -1 } }.AsQueryable(); var mockSet = new Mock <DbSet <Video> >(); mockSet.As <IQueryable <Video> >().Setup(b => b.Provider).Returns(videos.Provider); mockSet.As <IQueryable <Video> >().Setup(b => b.Expression).Returns(videos.Expression); mockSet.As <IQueryable <Video> >().Setup(b => b.ElementType).Returns(videos.ElementType); mockSet.As <IQueryable <Video> >().Setup(b => b.GetEnumerator()).Returns(videos.GetEnumerator); var mockCtx = new Mock <LibraryDbContext>(); mockCtx.Setup(c => c.Videos).Returns(mockSet.Object); var sut = new VideoService(mockCtx.Object); var video = sut.Get(-1); video.Title.Should().Be("Abc"); }
public void ReturnTrue_IfGalleryExist_AndVideoIsRemoved() { // Arrange var mockedGalleries = Utils.GetVideoGalleriesCollection(); var video = new Video(); var gallery = mockedGalleries.First(); gallery.Videos.Add(video); var mockedDbSet = MockDbSet.Mock(mockedGalleries.AsQueryable()); var mockedDbContext = new Mock <IDatabaseContext>(); mockedDbContext.Setup(c => c.VideoGalleries).Returns(mockedDbSet.Object); var videoService = new VideoService(mockedDbContext.Object); // Confirm that the gallery contains the video before remove it Assert.IsTrue(gallery.Videos.Count == 1); Assert.AreEqual(gallery.Videos.First(), video); // Act var isRemoved = videoService.RemoveVideoFromGallery(gallery.Name, video.Id); Assert.IsTrue(gallery.Videos.Count == 0); Assert.IsTrue(isRemoved); }
public ActionResult GetVideo(Video video, int idRound) { bool isValide = true; if (string.IsNullOrEmpty(video.authorVideo)) { ModelState.AddModelError("authorVideo", "Cần điền tên tác giả video"); } if (string.IsNullOrEmpty(video.codeAuthor)) { ModelState.AddModelError("codeAuthor", "Cần điền mã số sinh viên tác giả video"); } if (string.IsNullOrEmpty(video.titleVideo)) { ModelState.AddModelError("titleVideo", "Cần điền tên video"); } if (string.IsNullOrEmpty(video.urlVideo)) { ModelState.AddModelError("urlVideo", "Cần điền tên url video"); } if (ModelState.IsValid) { video.idRound = idRound; Video newVideo = VideoService.UpdateVideo(video); return(RedirectToAction("UpdateVideo", new { idRound = idRound })); } else { return(View(video)); } }
public async Task <ActionResult> Login(LoginModel model) { // await SetInitialDataAsync(); if (ModelState.IsValid) { UserDTO userDto = new UserDTO { Email = model.Email, Password = model.Password }; ClaimsIdentity claim = await VideoService.Authenticate(userDto); if (claim == null) { ModelState.AddModelError("", "Неверный логин или пароль."); } else { AuthenticationManager.SignOut(); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claim); int?par = 1; return(RedirectToAction("Index", "Video", par)); } } return(View(model)); }
public async Task <ActionResult> Register(RegisterModel model) { // await SetInitialDataAsync(); if (ModelState.IsValid) { UserDTO userDto = new UserDTO { Email = model.Email, Password = model.Password, Role = "user" }; OperationDetails operationDetails = await VideoService.Create(userDto); if (operationDetails.Succedeed) { int?par = 1; return(View("SuccessRegister")); } else { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); } } return(View(model)); }
public void SetUp() { //use moq only for external dependencies _fileReader = new Mock <IFileReader>(); _repository = new Mock <IVideoRepository>(); _videoService = new VideoService(_fileReader.Object, _repository.Object); }
// // GET: /Detail/ public ActionResult Round(int idRound, int?page, int?item, int?sort) // sort: 1 is new, 2 is most { int total; page = page.HasValue ? page : 0; item = item.HasValue ? item : 10; sort = sort.HasValue ? sort : 1; int skip = (int)page * (int)item; List <Video> listVideo = new List <Video>(); //if (sort == 1) //{ // listVideo = VideoService.GetVideosByRound_New(idRound, skip, (int) item, out total); //} else if (sort == 2) //{ // listVideo = VideoService.GetVideosByRound_Most(idRound, skip, (int) item, out total); //} listVideo = VideoService.GetAllVideosByMost(idRound); ViewBag.IdRound = idRound; return(View(listVideo)); }
public void SetUp() { _mockFileReader = new Mock <IFileReader>(); //estamos dizendo a biblioteco do Moq que queremos um objeto que implemente a interface IFileReader _mockIVideoRepository = new Mock <IVideoRepository>(); _videoService = new VideoService(_mockFileReader.Object, _mockIVideoRepository.Object); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request.Files.Count > 0) { string videoName = context.Request.Files["videoFile"].FileName; string videoPath = context.Server.MapPath(@"../Upload/Videos"); string title = context.Request["Title"].ToString(); DateTime uploadTime = DateTime.Now; string uploadUser = context.Session["CurrentUser"].ToString(); Video video = new Video() { Url = "Upload//Videos//" + videoName, Title = title, UploadUser = uploadUser, UploadTime = uploadTime, }; if (VideoService.Create(video)) { HttpPostedFile postedFile = context.Request.Files["videoFile"]; postedFile.SaveAs(context.Request.MapPath("..//" + video.Url)); context.Response.Write("上传成功"); } else { context.Response.Write("上传失败"); } } }
public async Task AddVideo_should_return_the_expected_video(string kindId, string genreId) { //Arrange string data = GenData.Create <string>(); AddVideoRequest expectedVideo = new AddVideoRequest() { AltTitle = data, Description = data, Duration = 123, Episode = 7, ReleaseYear = DateTime.Now, Season = 1, Title = data, KindId = new Guid(kindId), GenreId = new Guid(genreId) }; VideoService sut = new VideoService(Repository, Mapper); //Act VideoResponse result = await sut.AddVideoAsync(expectedVideo); //Assert result.Should().BeEquivalentTo(expectedVideo); }
public ActionResult VideoCategory(int categoryId) { var user = AuthService.CurrentUser; /*if (user == null) * return RedirectToAction<SimpleRegController>(c => c.Registration(Request.Url.AbsolutePath, "ВИДЕОСАЙТ"));*/ if (categoryId == 0) { return(null); } var category = VideoCategoryService.GetByPK(categoryId); if (category == null) { return(null); } var videos = VideoService.GetAll(x => x.CategoryId == categoryId && x.IsActive).OrderByDescending(x => x.VideoID).ToList(); var model = new VideoCategoryVM { Category = category, Videos = videos }; return(BaseViewWithModel(new VideoCategoryView(), model)); }
public async Task EditVideo_should_return_the_expected_video(string kindId, string genreId) { //Arrange string data = GenData.Create <string>(); EditVideoRequest expectedVideo = new EditVideoRequest() { Id = new Guid("eaa0B9d4-4A2d-496e-8a68-a36cd0758abb"), AltTitle = data, Description = data, IsInactive = false, Duration = 123, Episode = 7, ReleaseYear = DateTime.Now, Season = 1, Title = data, KindId = new Guid(kindId), GenreId = new Guid(genreId) }; VideoService sut = new VideoService(Repository, Mapper); //Act VideoResponse result = await sut.EditVideoAsync(expectedVideo); //Assert result.Should().BeEquivalentTo(expectedVideo, o => o.Excluding(x => x.IsInactive)); }
public void ReturnNull_IfIdNotMatch() { // Arrange var mockedGalleriesCollection = Utils.GetVideoGalleriesCollection(); // Add videos for every gallery, so there won't be empty gallery in the context. foreach (var gallery in mockedGalleriesCollection) { gallery.Videos.Add(new Video() { Title = "First video" }); gallery.Videos.Add(new Video() { Title = "Second video" }); } var searchedGalleryId = Guid.NewGuid().ToString(); var mockedDbSet = MockDbSet.Mock(mockedGalleriesCollection.AsQueryable()); var mockedDbContext = new Mock <IDatabaseContext>(); mockedDbContext.Setup(c => c.VideoGalleries).Returns(mockedDbSet.Object); var videoService = new VideoService(mockedDbContext.Object); // Act var videos = videoService.GetVideosFromGallery(searchedGalleryId); // Assert Assert.IsNull(videos); }
public static void Main() { //PRODUCTION IT TAKES REAL FILE READER IMPLEMENTATION var service = new VideoService(); var title = service.ReadVideoTitle(); }
public void Get_All_Videos() { var videos = new List <Video> { new Video { Id = 1234 }, new Video { Id = -6 } }.AsQueryable(); var mockSet = new Mock <DbSet <Video> >(); mockSet.As <IQueryable <Video> >().Setup(b => b.Provider).Returns(videos.Provider); mockSet.As <IQueryable <Video> >().Setup(b => b.Expression).Returns(videos.Expression); mockSet.As <IQueryable <Video> >().Setup(b => b.ElementType).Returns(videos.ElementType); mockSet.As <IQueryable <Video> >().Setup(b => b.GetEnumerator()).Returns(videos.GetEnumerator); var mockCtx = new Mock <LibraryDbContext>(); mockCtx.Setup(c => c.Videos).Returns(mockSet.Object); var sut = new VideoService(mockCtx.Object); var queryResult = sut.GetAll().ToList(); queryResult.Should().AllBeOfType(typeof(Video)); queryResult.Should().HaveCount(2); queryResult.Should().Contain(a => a.Id == -6); queryResult.Should().Contain(a => a.Id == 1234); }
public void SetUp() { _vs = new VideoService(new FileReaderForTest()); _fileReader = new Mock <IFileReader>(); _repository = new Mock <IVideoRepository>(); _videoService = new VideoService(_fileReader.Object, _repository.Object); }
public void EditVideoShoudEditOneOrMorePropertiesInVideo() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Videos").Options; var dbContext = new ApplicationDbContext(options); var service = new VideoService(dbContext); var model = new UpdateDeleteVideoViewModel { Title = "Edited", }; var video = new Video { Title = "New", }; dbContext.Videos.Add(video); dbContext.SaveChanges(); var videoToEdit = dbContext.Videos.First(); service.EditVideo(videoToEdit, model); Assert.Equal("Edited", videoToEdit.Title); }
private async Task CheckProcessingVideosAsync(VideoService videoService, FairplaytubeDatabaseContext fairplaytubeDatabaseContext, CancellationToken stoppingToken) { this.Logger?.LogInformation("Checking processing videos"); var processingInDB = await videoService.GetDatabaseProcessingVideosIdsAsync(stoppingToken); string message = $"{processingInDB.Length} videos marked as processing In DB"; this.Logger?.LogInformation(message); if (processingInDB.Length > 0) { this.Logger?.LogInformation("Retrieving videos status in Azure Video Indexer"); var videosIndex = await videoService.GetVideoIndexerStatusAsync(processingInDB, stoppingToken); if (videosIndex.results.Length > 0) { var indexCompleteVideos = videosIndex.results.Where(p => p.state == Common.Global.Enums.VideoIndexStatus.Processed.ToString()); if (indexCompleteVideos.Any()) { var indexCompleteVideosIds = indexCompleteVideos.Select(p => p.id).ToArray(); await videoService.AddVideoIndexTransactionsAsync(indexCompleteVideosIds, stoppingToken); var videosCompleted = fairplaytubeDatabaseContext.VideoInfo.Where(video => indexCompleteVideosIds.Contains(video.VideoId)); foreach (var video in videosCompleted) { await videoService.MarkVideoAsProcessedAsync(video, stoppingToken); } } } } }
public void ReadVideoTitle_EmptyFile_ReturnError() { var service = new VideoService(new FakeFileReader()); var result = service.ReadVideoTitle(); Assert.That(result, Does.Contain("error").IgnoreCase); }
public ProfileVM GetProfile() { var user = UserService .GetByPK(AuthService.CurrentUser.UserID); var manager = OrderService.GetUserManagerTC(user); var existgroup = OrderService.ExistGroup(user); var companyName = string.Empty; if (user.EmployeeCompanyID.HasValue) { companyName = CompanyService.GetValues(user.EmployeeCompanyID, x => x.CompanyName); } var result = new ProfileVM(Htmls.IsNewProfile) { User = user, IsBest = IsBest(user), IsExcelMaster = IsExcelMaster(user), EmployeeCompanyName = companyName, Manager = manager, HasUnlimit = HasUnlimit(user), Videos = VideoService.GetAll(x => x.IsActive).OrderByDescending(x => x.VideoID).Take(5).ToList(), ExistGroup = existgroup }; return(result); }
public void CreateNewGallery_IfNotExist_AndAddVideoToGallery() { // Arrange var video = new Video() { Title = "Test video" }; var mockedGallery = Utils.GetEmptyVideoGallery(); var mockedDbSet = MockDbSet.Mock(mockedGallery.AsQueryable()); mockedDbSet.Setup(d => d.Add(It.IsAny <VideoGallery>())).Callback <VideoGallery>((g) => mockedGallery.Add(g)); var mockedDbContext = new Mock <IDatabaseContext>(); mockedDbContext.Setup(c => c.VideoGalleries).Returns(mockedDbSet.Object); var videoService = new VideoService(mockedDbContext.Object); var newGalleryName = "Test"; // Act videoService.AddVideoToGallery(newGalleryName, video); // Assert Assert.IsTrue(mockedDbContext.Object.VideoGalleries.Count() == 1); Assert.IsTrue(mockedDbContext.Object.VideoGalleries.First().Name == newGalleryName); Assert.IsTrue(mockedDbContext.Object.VideoGalleries.First().Videos.Count == 1); Assert.AreEqual(mockedDbContext.Object.VideoGalleries.First().Videos.First(), video); }
public void GetUnprocessedVideosAsCsv_WhenCall_ReturnListUnprocessedVideos() { var videoRepository = new Mock <IVideoRepository>(); var fileReader = new Mock <IFileReader>(); videoRepository.Setup(v => v.GetUnprocessedVideos()).Returns(new List <Video>() { new Video() { Id = 1 }, new Video() { Id = 2 }, new Video() { Id = 3 } } ); var videoService = new VideoService(videoRepository.Object, fileReader.Object); var result = videoService.GetUnprocessedVideosAsCsv(); Assert.That(result, Is.EqualTo("1,2,3")); }
public void ReturnCorectResult_IfIdMatch() { // Arrange var mockedGalleriesCollection = Utils.GetVideoGalleriesCollection(); var searchedGallery = mockedGalleriesCollection[1]; var searchedGalleryId = searchedGallery.Id; searchedGallery.Videos.Add(new Video() { Title = "First video" }); searchedGallery.Videos.Add(new Video() { Title = "Second video" }); var mockedDbSet = MockDbSet.Mock(mockedGalleriesCollection.AsQueryable()); var mockedDbContext = new Mock <IDatabaseContext>(); mockedDbContext.Setup(c => c.VideoGalleries).Returns(mockedDbSet.Object); var videoService = new VideoService(mockedDbContext.Object); // Act var videos = videoService.GetVideosFromGallery(searchedGalleryId); // Assert Assert.IsTrue(videos.Count() == 2); Assert.IsTrue(videos.First().Title == "First video"); Assert.IsTrue(videos.Last().Title == "Second video"); }
protected void btnSubmit_Click(object sender, EventArgs e) { try { if (Label2.Text.Trim() == "") { Response.Write("<script>alert('照片不能为空!')</script>"); } else { Models.Video video = new Models.Video(); video.VideoID = Convert.ToInt32(Request.QueryString["VideoID"]); //news.AssID = 1; video.VideoName = txtTitle.Text.Trim(); video.VideoBrief = CKEditorControl1.Text.Trim(); video.Images = Label2.Text; video.VideoUrl = Label1.Text; video.CreatTime = DateTime.Now; int result = VideoService.Insert(video); if (result >= 1) { Response.Write("<script>alert('发布成功!')</script>"); } } } catch (Exception ex) { Response.Write("<script>alert('上传失败');</script> 原因是:" + ex); } }
public void GetUnprocessedVideoAsCsv_RepositoryHaseOneOrMoreItems_ReturnsJoinedList() { // Arrange var repo = new Mock <IVideoProcessedFilter>(); repo.Setup(r => r.GetProcessedVideos()).Returns(new List <Video> { new Video { Id = 1 }, new Video { Id = 2 }, new Video { Id = 3 } }); var videoService = new VideoService(null, repo.Object); // Act var result = videoService.GetUnprocessedVideosAsCsv(); // Assert Assert.Equal("1,2,3", result); }
public ActionResult Add(string t, string k, string d, string imageurl, string u, string um) { string result = "发布失败"; if (Session["UserId"] == null) { return Content("长时间未操作,请重新登录。"); } if (!string.IsNullOrEmpty(t) && !string.IsNullOrEmpty(k) && !string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(imageurl) && !string.IsNullOrEmpty(u) && !string.IsNullOrEmpty(um)) { Video video = new Video(); video.Title = t; video.Keywords = k; video.Description = d; video.Thumbnail = imageurl; video.Url = u; video.UrlM = um; video.InsertTime = DateTime.Now; video.ViewTime = 0; VideoService videoService = new VideoService(); if (videoService.AddVideo(video)) { result = "success"; } } else { result = "必填项不能为空"; } return Content(result); }
public ActionResult Delete(int id) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } VideoService videoService = new VideoService(); videoService.RemoveVideo(id); return Redirect(Request.UrlReferrer.AbsoluteUri); }
/// <summary> /// 新闻首页 /// </summary> public ActionResult Index(string page) { this.Internationalization(); NewsModel model = new NewsModel(); if (string.IsNullOrEmpty(page)) { page = "1"; } NewsService newsService = new NewsService(); model.Page = Int32.Parse(page); model.PageSize = 10;//每页显示10张 model.PageIndex = Int32.Parse(page); int count = 0; //视频列表 model.NewsList = newsService.GetNewsList(null, null, model.PageSize, model.PageIndex, out count); //分页 if (model.NewsList != null && model.NewsList.Count > 0) { model.PageStep = 10; //页码10个 model.AllCount = count; if (model.AllCount % model.PageSize == 0) { model.PageCount = model.AllCount / model.PageSize; } else { model.PageCount = model.AllCount / model.PageSize + 1; } } CategoryService categoryService = new CategoryService(); model.Category = categoryService.GetCategoryById("news"); VideoService videoService = new VideoService(); //猜你喜欢 //model.Like = videoService.GetLike(16); return View(model); }
public ActionResult Edit(int id, string t, string k, string d, string imageurl, string u, string um) { string result = "更新失败"; if (Session["UserId"] == null) { return Content("长时间未操作,请重新登录。"); } if (!string.IsNullOrEmpty(t) && !string.IsNullOrEmpty(k) && !string.IsNullOrEmpty(d) && !string.IsNullOrEmpty(imageurl) && !string.IsNullOrEmpty(u) && !string.IsNullOrEmpty(um)) { VideoService videoService = new VideoService(); Video video = videoService.GetVideoById(id); if (video != null) { video.Title = t; video.Keywords = k; video.Description = d; video.Thumbnail = imageurl; video.Url = u; video.UrlM = um; if (videoService.EditVideo(video)) { result = "success"; } } } else { result = "必填项不能为空"; } return Content(result); }
public ActionResult Edit(int id) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } VideoModel model = new VideoModel(); VideoService videoService = new VideoService(); model.Video = videoService.GetVideoById(id); return View(model); }
public ActionResult Index(string keywords, string page) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } VideoModel model = new VideoModel(); VideoService videoService = new VideoService(); int tempPage = 1; if (!string.IsNullOrEmpty(page)) { Int32.TryParse(page, out tempPage); } //视频列表 int tempCount = 0; model.Videos = videoService.GetVideos(keywords, 15, tempPage, out tempCount); //分页 if (model.Videos != null && model.Videos.Count > 0) { model.PageIndex = tempPage; model.PageSize = 15; model.PageStep = 10; model.AllCount = tempCount; if (model.AllCount % model.PageSize == 0) { model.PageCount = model.AllCount / model.PageSize; } else { model.PageCount = model.AllCount / model.PageSize + 1; } } model.Keywords = keywords; return View(model); }