private void MethodAddReturnsCorrectResponse() { //Setup repo mock _repository.Setup(repo => repo.Add(_video1)); //check correct response _service.Add(_videoDto1); _repository.Verify(repo => repo.Add(_video1), Times.Once); }
public ActionResult Add(VideoVM _VideoVM, HttpPostedFileBase videoFile) { string fileName = Path.GetFileName(videoFile.FileName); videoFile.SaveAs(Server.MapPath("~/Content/VideoFiles/" + fileName)); _VideoVM.Video.UserID = _UserService.GetByDefault(x => x.UserName == User.Identity.Name).ID; _VideoVM.Video.Url = "~/Content/VideoFiles/" + fileName; _VideoVM.Video.Name = videoFile.FileName; _VideoVM.Video.VideoCategoryID = _VideoCategoryService.GetByDefault(x => x.Name == _VideoVM.CategoryName).ID; _VideoService.Add(_VideoVM.Video); return(Redirect("/SysAdmin/Video/List")); }
public void Add_New_Video_To_Context() { var mockSet = new Mock <DbSet <Video> >(); var mockCtx = new Mock <LibraryDbContext>(); mockCtx.Setup(c => c.Videos).Returns(mockSet.Object); var sut = new VideoService(mockCtx.Object); sut.Add(new Video()); mockCtx.Verify(s => s.Add(It.IsAny <Video>()), Times.Once()); mockCtx.Verify(c => c.SaveChanges(), Times.Once()); }
public IActionResult SaveEntity(Video video) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (video.Id == 0) { _videoService.Add(video); } else { _videoService.Update(video); } _videoService.Save(); return(new OkObjectResult(video)); } }
public ActionResult HomePage(Tweet tweet, Hashtag hashtag, HttpPostedFileBase[] PhotoVideo, Photo photo, Video video)//Tweet ve Hashtag Ekleme { AppUser gelen = (AppUser)Session["oturum"]; if (Session["oturum"] != null) { gelen = (AppUser)Session["oturum"]; tweet.AppUserID = gelen.ID; } if (ModelState.IsValid) { tweet.Like = 0; tweet.Dislike = 0; tweet.Retweet = 0; #region Add Hashtag if (tweet.TweetText != null) { if (tweet.TweetText.Contains('#')) { string[] text = tweet.TweetText.Split(' '); foreach (var item in text) { if (hs.Any(x => x.HashTag.Contains(item))) { var hashtagItem = hs.GetByDefault(x => x.HashTag == item); hashtagItem.Quantity += 1; hashtagItem.Tweets.Add(tweet); hs.Update(hashtagItem); } else { if (item.Contains('#')) { hashtag.HashTag = item; hashtag.Quantity = 1; tweet.Hashtags.Add(hashtag); ts.Add(tweet); } } } } else { ts.Add(tweet); } } else { ViewBag.Message = "Tweet Giriniz."; return(View()); } #endregion #region Add Photo and Video bool isUploadedVideo; bool isUploadedPhoto; foreach (var itemPhoto in PhotoVideo) { if (itemPhoto != null) { if (itemPhoto.ContentType.Contains("image")) { string photoFileResult = FxFunction.Upload(PhotoVideo, FolderPath.TweetPhoto, out isUploadedPhoto); if (isUploadedPhoto) { photo.TweetID = tweet.ID; photo.Description = tweet.TweetText; photo.ImagePath = photoFileResult; ps.Add(photo); } } else if (itemPhoto.ContentType.Contains("video")) { string videoFileResult = FxFunction.Upload(PhotoVideo, FolderPath.TweetMovie, out isUploadedVideo); if (isUploadedVideo) { video.ID = Guid.NewGuid(); video.Description = tweet.TweetText; video.VideoPath = videoFileResult; vs.Add(video); tweet.TweetVideoID = video.ID; ts.Update(tweet); } } } } return(RedirectToAction("HomePage")); #endregion } else { ViewBag.Message = "Ekleme sırasında hata oluştu."; } ViewBag.AppUserID = new SelectList(aus.GetActive(), "ID", "Name", tweet.AppUserID); return(View()); }
public StatusResponse Post([FromBody] VideoRequest videoRequest) => _videos.Add(videoRequest);