public void IsAuthorisedByCookie_SessionDoNoExistInDatabase() { var dbMock = new Mock <ApplicationDbContext>(); var list = new List <SessionUserPrivatePollEntity>() { new SessionUserPrivatePollEntity() { SessionID = Guid.NewGuid(), DateTime = DateTime.Now } }; dbMock.Setup(x => x.SessionPrivatePoll).Returns(CreateDbSetMock <SessionUserPrivatePollEntity>(list).Object); dbMock.Setup(x => x.SaveChanges()); Assert.AreEqual(false, manager.IsAuthorisedByCookie("idDonotExists", dbMock.Object)); }
public bool IsRequestAuthorised(PollEntity poll) { var user = appUserManager.FindById(User.Identity.GetUserId()); if (user != null && poll.UserCreator.Id == user.Id) { return(true); //creator of poll always has access } var privatePollManager = new PrivatePollManager(); if (Request.Cookies["privPoll"] != null && privatePollManager.IsAuthorisedByCookie(Request.Cookies["privPoll"].Value, db)) { Request.Cookies["privPoll"].Expires = DateTime.Now.AddMinutes(10);//updating cookie return(true); } else { return(false); } }