public void Index_ValidRequest_ReturnsNotifications() { // Arrange var @event = new Event(); @event.FillWithDefaultValues(); @event = _context.Events.Add(@event); var edition = new Edition(); edition.FillWithDefaultValues(@event); edition = _context.Editions.Add(edition); var notification = new Notification(); notification.FillWithDefaultValues(edition); _context.Notifications.Add(notification); _context.SaveChanges(); // Act var result = _controller.Index(); // Assert Assert.IsInstanceOf <NotificationListModel>(result.Model); Assert.AreEqual(1, ((NotificationListModel)result.Model).Notifications.Count); }
public void Should_Get_Notification_Index_Page() { NotificationController controller = new NotificationController(); ViewResult result = controller.Index("test") as ViewResult; Assert.IsNotNull(result); }
public void Index_ValidRequest_ReturnsView() { // Arrange // Act var result = _sut.Index(); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.IsNotNull(result); Assert.IsNotNull(result.Model); Assert.IsInstanceOfType(result.Model, typeof(NotificationListModel)); }
public void Index_If_AjaxRequest_IsNull() { MemoryUser user = new MemoryUser("adarsh"); ApplicationUser applicationUser = getApplicationUser(); var userContext = new UserInfo { UserId = user.Id, DisplayName = user.UserName, UserIdentifier = applicationUser.Email, RoleName = Enum.GetName(typeof(UserRoles), applicationUser.RoleId) }; var testTicket = new FormsAuthenticationTicket( 1, user.Id, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), false, userContext.ToString()); userRepository.Setup(x => x.Get(It.IsAny <Expression <Func <ApplicationUser, bool> > >())).Returns(applicationUser); NotificationController controller = new NotificationController(goalService, updateService, commentService, groupInvitationService, supportInvitationService, followRequestService, userService); principal.SetupGet(x => x.Identity.Name).Returns("adarsh"); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); controllerContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true); controller.ControllerContext = controllerContext.Object; contextBase.SetupGet(x => x.Request).Returns(httpRequest.Object); contextBase.SetupGet(x => x.Response).Returns(httpResponse.Object); genericPrincipal.Setup(x => x.Identity).Returns(identity.Object); contextBase.SetupGet(a => a.Response.Cookies).Returns(new HttpCookieCollection()); var formsAuthentication = new DefaultFormsAuthentication(); formsAuthentication.SetAuthCookie(contextBase.Object, testTicket); HttpCookie authCookie = contextBase.Object.Response.Cookies[FormsAuthentication.FormsCookieName]; var ticket = formsAuthentication.Decrypt(authCookie.Value); var goalsetterUser = new MuhendislerBuradaUser(ticket); string[] userRoles = { goalsetterUser.RoleName }; principal.Setup(x => x.Identity).Returns(goalsetterUser); IEnumerable <GroupInvitation> groupInvitation = new List <GroupInvitation> { new GroupInvitation { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec" }, new GroupInvitation { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", }, new GroupInvitation { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ee" }, }.AsEnumerable(); groupInvitationRepository.Setup(x => x.GetAll()).Returns(groupInvitation); IEnumerable <SupportInvitation> supportInvitation = new List <SupportInvitation> { new SupportInvitation { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec" }, new SupportInvitation { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed" }, new SupportInvitation { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ee" }, }.AsEnumerable(); supportInvitationRepository.Setup(x => x.GetAll()).Returns(supportInvitation); IEnumerable <FollowRequest> followInvitation = new List <FollowRequest> { new FollowRequest { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec" }, new FollowRequest { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed" }, new FollowRequest { Accepted = false, ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ee" }, }.AsEnumerable(); followRequestRepository.Setup(x => x.GetMany(It.IsAny <Expression <Func <FollowRequest, bool> > >())).Returns(followInvitation); Mapper.CreateMap <GroupInvitation, NotificationViewModel>(); Mapper.CreateMap <SupportInvitation, NotificationViewModel>(); Mapper.CreateMap <FollowRequest, NotificationViewModel>(); ViewResult result = controller.Index(1) as ViewResult; Assert.IsNotNull(result); }