示例#1
0
        public async Task <IActionResult> AddNews(NotificationContext news)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            NotificationContext data = new NotificationContext(news.Title, news.Message, user.UserName);

            notifyRepo.Add(data);
            return(RedirectToAction("Index", "Home"));
        }
示例#2
0
        public void NotificationRepository_GetById_ThrowsExceptionWhenIdNotFound()
        {
            //arrange
            INotificationRepo nr = GetInMemoryNotificationRepository();

            //act
            nr.Add(notification);

            //assert
            Assert.ThrowsAny <ArgumentNullException>(() => nr.GetById(0));
        }
示例#3
0
        public void NotificationRepository_GetByUserId_ReturnsIEnumerable()
        {
            //arrange
            INotificationRepo nr            = GetInMemoryNotificationRepository();
            Notification      notification2 = new Notification
            {
                Type       = "like",
                ReceiverId = 1,
                SenderId   = 3,
                Status     = true,
                ReviewId   = 2
            };

            //act
            nr.Add(notification);
            nr.Add(notification2);

            //assert
            Assert.IsAssignableFrom <IEnumerable <Notification> >(nr.GetByReceiverId(1));
        }
示例#4
0
        public void NotificationRepository_DeleteById_DeletesNotification()
        {
            //arrange
            INotificationRepo nr = GetInMemoryNotificationRepository();

            //act
            nr.Add(notification);
            nr.DeleteById(1); //NotificationId should be 1

            //assert
            Assert.ThrowsAny <ArgumentNullException>(() => nr.GetById(1));
        }
示例#5
0
        public Notification Add(string Description, DateTime date, string userid)
        {
            Notification p = new Notification()
            {
                Description   = Description,
                Date          = date,
                AspNetUsersId = userid
            };

            Repository.Add(p);

            return(p);
        }
示例#6
0
        public void NotificationRepository_DeleteByUserId_DeletesNotifications()
        {
            //arrange
            INotificationRepo nr            = GetInMemoryNotificationRepository();
            Notification      notification2 = new Notification
            {
                Type       = "like",
                ReceiverId = 1,
                SenderId   = 3,
                Status     = true,
                ReviewId   = 2
            };

            //act
            nr.Add(notification);
            nr.Add(notification2);

            nr.DeleteByUserId(1); //both notifications have same receiver id

            //assert
            Assert.ThrowsAny <ArgumentNullException>(() => nr.GetById(1));
            Assert.ThrowsAny <ArgumentNullException>(() => nr.GetById(2));
        }
示例#7
0
        public void NotificationRepository_Add_AddsNotification()
        {
            //arrange
            INotificationRepo nr = GetInMemoryNotificationRepository();

            //act
            nr.Add(notification);
            var savedNotification = nr.GetById(1);

            //assert
            Assert.Equal(1, savedNotification.ReceiverId);
            Assert.Equal(2, savedNotification.SenderId);
            Assert.Equal("like", savedNotification.Type);
            Assert.Equal(1, savedNotification.ReviewId);
            Assert.True(savedNotification.Status);
        }
示例#8
0
 public IActionResult AddFakeNews()
 {
     notifyRepo.Add(new NotificationContext("Demo title", "Demo tekst demo tekst demo tekst demo tekst demo tekst", "Admin"));
     return(View("Index"));
 }