public void TestFollowUser() { //Arrange var controller = new CommunicationControllerTest(); User cur1 = new User { UserName = "******", Password = "******" }; User cur2 = new User { UserName = "******", Password = "******" }; UserDal usrd = new UserDal(); User cur1_Obj = usrd.Users.SingleOrDefault(b => b.UserName == cur1.UserName); User cur2_Obj = usrd.Users.SingleOrDefault(b => b.UserName == cur2.UserName); CommentDal cmtd = new CommentDal(); Comment testComment = new Comment() { commentContent = "Testing Comment 1122334455", userId = cur2_Obj.id, threadId = 1 }; cmtd.Comments.Add(testComment); cmtd.SaveChanges(); Comment testId = cmtd.Comments.SingleOrDefault(b => b.commentContent == testComment.commentContent); //Act controller.follow(testId.commentId, cur1_Obj); //Assert FollowDal fdal = new FollowDal(); List <Follow> f = (from x in fdal.Follows where x.follower == cur1_Obj.id && x.followOn == cur2_Obj.id select x).ToList(); Assert.IsTrue(f.Any()); //Clean Up cmtd.Comments.Remove(testId); cmtd.SaveChanges(); fdal.Follows.Remove(f[0]); fdal.SaveChanges(); }
public ActionResult unFollow(Int32 i) { ThreadDal tdal = new ThreadDal(); CommentDal cdal = new CommentDal(); FollowDal fdal = new FollowDal(); List <Follow> follows = new List <Follow>(); List <Comment> comments = new List <Comment>(); List <Thread> threads = new List <Thread>(); User ur = new User((User)TempData["urid"]); try { comments = (from x in cdal.Comments where x.commentId == i select x).ToList <Comment>(); int on = comments[0].userId; int tid = comments[0].threadId; int fwr = ur.id; threads = (from x in tdal.Threads where x.ThreadId == tid select x).ToList <Thread>(); follows = (from y in fdal.Follows where y.followOn == @on && y.follower == fwr select y).ToList <Follow>(); fdal.Follows.Remove(follows[0]); fdal.SaveChanges(); } catch { } Thread t = new Thread(threads[0]); return(RedirectToAction("ContentPage", "MainPage", t)); }
public ActionResult UnFollow(int ID) { var IdBilgisi = Convert.ToInt32(Session["ID"]); var insan = db.Followers.FirstOrDefault(x => x.UserId == IdBilgisi && x.FollowId == ID); Follower follower = new Follower() { Id = insan.Id, UserId = insan.UserId, FollowId = insan.FollowId, IsDeleted = false }; //db.Followers.Remove(follower); FollowDal followDal = new FollowDal(); followDal.Delete(follower); return(RedirectToAction("Index")); }