public async Task NotificationController_Get_Test_LongerThan1Day()
        {
            var notificationController = new NotificationController(new FakeINotificationQuery());
            var result = await notificationController.GetNotifications("2020-04-11T17:55:35.922319Z") as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
        }
        public async Task NotificationController_Get_Test_Null()
        {
            var notificationController = new NotificationController(new FakeINotificationQuery());
            var result = await notificationController.GetNotifications(null) as BadRequestObjectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(400, result.StatusCode);
        }
        public async Task GetNotificationsOnlyUnreadedByDefoultTest()
        {
            // Arrange

            // Act
            var response = await _controller.GetNotifications();

            // Assert
            IEnumerable <NotificationDTO> notificationsResponse;

            Assert.IsTrue(response.TryGetContentValue(out notificationsResponse));

            Assert.AreNotEqual(notificationsResponse, null);
            Assert.AreNotEqual(notificationsResponse.Count(), 0);
            Assert.AreEqual(notificationsResponse.Count(i => i.IsReaded == true), 0);

            Assert.AreEqual(notificationsResponse.Count(i => i.Receiver != FormatUserName(testUserName)), 0);
        }
Beispiel #4
0
        /// <summary>
        /// Obtains a list of all notification messages.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickGetNotifications(object sender, System.EventArgs e)
        {
            string Tag = "Notifications";

            try
            {
                List <Dictionary <string, string> > notifications = NotificationController.GetNotifications(this);

                log.Info(Tag, $"There are {notifications.Count} active notifications.");
            }
            catch (ApiException exception)
            {
                log.Error(Tag, "Error/Exception: " + exception);
            }
        }
Beispiel #5
0
        public void TestGetNotifications()
        {
            var contextMock = new Mock <HttpContext>();

            contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal(claims));
            IEnumerable <Notification> _ienumerable = notifications;

            mockNotificationService.Setup(x => x.GetNotifications(It.IsAny <string>())).Returns(_ienumerable);
            var _notificationController = new NotificationController(mockNotificationService.Object);

            _notificationController.ControllerContext.HttpContext = contextMock.Object;
            var accountReturn = _notificationController.GetNotifications();
            var type          = accountReturn.GetType();

            Assert.AreEqual(type.Name, "OkObjectResult");
        }
        public async Task NotificationController_Get_Test_Now_HappyFlow()
        {
            var notificationController = new NotificationController(new FakeINotificationQuery(new List <NotificationItem> {
                new NotificationItem()
                {
                    DateTime = DateTime.UtcNow
                }
            }));

            var dateTime = DateTime.UtcNow.AddMinutes(-1)
                           .ToString(CultureInfo.InvariantCulture);
            var result = await notificationController.GetNotifications(dateTime) as JsonResult;

            Assert.IsNotNull(result);
            var parsedResult = result.Value as List <NotificationItem>;

            Assert.IsNotNull(parsedResult);
            Assert.AreEqual(1, parsedResult.Count);
        }
 public List <Dictionary <string, string> > GetNotifications()
 {
     return(NotificationController.GetNotifications(Application.Context));
 }
        public void Get_All_Notifications()
        {
            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>();
            IEnumerable <NotificationViewModel> result = controller.GetNotifications(5, 5) as IEnumerable <NotificationViewModel>;

            Assert.IsNotNull(result);
        }
Beispiel #9
0
        public void GetNotifications_Flow_ViewResult()
        {
            // Arrange
            var data = new List <Notification>
            {
                new Notification {
                    Id = 1
                }
            }.AsQueryable();

            var user = new User
            {
                Id            = 1,
                Notifications = new List <Notification>()
                {
                    new Notification
                    {
                        Date    = DateTime.Now.AddDays(-3),
                        IsRead  = false,
                        Content = "",
                        Title   = ""
                    },
                    new Notification
                    {
                        Date    = DateTime.Now.AddDays(-1),
                        IsRead  = true,
                        Content = "",
                        Title   = ""
                    },
                    new Notification
                    {
                        Date    = DateTime.Now.AddDays(-1),
                        IsRead  = false,
                        Content = "",
                        Title   = ""
                    },
                    new Notification
                    {
                        Date    = DateTime.Now.AddDays(-3),
                        IsRead  = true,
                        Content = "",
                        Title   = ""
                    },
                }
            };

            var mockSet = MockHelper.MockDbSet(data);

            var mockContext = new Mock <Context>();

            mockContext.SetupGet(c => c.Notifications).Returns(mockSet.Object);

            var mockUserHelper = new Mock <IUserHelper>();

            mockUserHelper.Setup(u => u.GetCurrentDbUser(mockContext.Object)).Returns(user);

            var controller = new NotificationController(mockContext.Object, mockUserHelper.Object);

            // Act

            var result = controller.GetNotifications() as ViewResult;

            // Assert

            Assert.IsNotNull(result);
        }