public async Task <Notification> ChangeImportant(string username, int nId, bool important) { var notification = await notificationRepo.GetById(nId); if (notification == null) { throw new NotFoundException(); } if (username != notification.Username) { throw new ForbiddenException(); } notification.Important = important; return(await notificationRepo.Update(notification)); }
public void NotificationRepository_GetById_ThrowsExceptionWhenIdNotFound() { //arrange INotificationRepo nr = GetInMemoryNotificationRepository(); //act nr.Add(notification); //assert Assert.ThrowsAny <ArgumentNullException>(() => nr.GetById(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)); }
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)); }
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); }
public Notification GetCity(int id) { return(Repository.GetById(id)); }