public void the_assertion_fails_if_notification_is_not_raised() { Assert.Throws <Exception>(() => { var sut = new NoNotification(); sut.AssertThatChangeNotificationIsRaisedBy(x => x.PropertyWithoutNotification) .When(() => sut.PropertyWithoutNotification = "something"); }); }
public IActionResult Notifications(EnumList.Notifications type, EnumList.NotifyMethod method, bool receive = false) { //ToDo :: Implement Method here var userId = _access.GetUserId(User); if (string.IsNullOrEmpty(userId)) { return(BadRequest()); } var user = _context.Users.Find(userId); if (user == null) { return(BadRequest()); } var userNotifications = _context.NoNotifications.Where(x => x.UserId == userId).Where(x => x.Method == method).ToList(); if (receive) { if (!userNotifications.Any()) { return(BadRequest()); } var notification = userNotifications.SingleOrDefault(x => x.NotificationType == type); if (notification == null) { return(BadRequest()); } _context.Remove(notification); _context.SaveChanges(); return(Ok()); } if (userNotifications.Any(x => x.NotificationType == type)) { return(BadRequest()); } var newNotNotify = new NoNotification { User = user, NotificationType = type, Method = method }; _context.Add(newNotNotify); _context.SaveChanges(); return(Ok()); }
public async Task PublishAsync_throws_when_notification_handler_collection_is_empty() { Mock.Get(_instanceFactory) .Setup(f => f.Invoke(It.IsAny <Type>())) .Returns((Func <Type, object>)_containerFixture.Container.GetInstance); using var scope = AsyncScopedLifestyle.BeginScope(_containerFixture.Container); var noNotification = new NoNotification(); Func <Task> publishFunc = () => _sut.PublishAsync(noNotification); await publishFunc.Should().ThrowExactlyAsync <ArgumentNullException>().WithMessage("Handler collection is empty*"); Mock.Get(_instanceFactory) .Verify(f => f.Invoke(It.Is <Type>(t => t == typeof(IEnumerable <INotificationHandler <NoNotification> >))), Times.Once()); }