/// <summary> /// Acknowledges notifications by a sender and given filter /// </summary> private void AcknowledgeByFilter(INotificationSender sender, Predicate <NotificationMap> filter) { _listLock.EnterWriteLock(); var publishes = _published.Where(m => filter(m)).ToArray(); _published.RemoveAll(filter); _pendingPubs.RemoveAll(filter); foreach (var published in publishes) { var managed = (IManagedNotification)published.Notification; managed.Acknowledged = DateTime.Now; managed.Acknowledger = sender.Identifier; _pendingAcks.Add(published); } _listLock.ExitWriteLock(); foreach (var published in publishes) { Acknowledged?.Invoke(this, published.Notification); } }
public void Delete_Success() { // Arrange CashDeskItem item = new CashDeskItem() { Id = "5c012842f8e2708cf041e247", Name = "Caisse_01" }; Acknowledged deleteResult = new Acknowledged(1); _cashDeskServicesMock.Setup(x => x.GetCashDesk(item.Id)).Returns(Task.FromResult(item)); _cashDeskServicesMock.Setup(x => x.DeleteCashDesk(item.Id)) .ReturnsAsync(deleteResult) .Verifiable(); _cashDeskFlowValidMock .Setup(x => x.IsValidOperation(BaseValidatorType.Delete, It.IsAny <CashDeskItem>(), null)) .Returns(true) .Verifiable(); // Act CashDeskController controller = new CashDeskController(_cashDeskServicesMock.Object, _cashDeskFlowValidMock.Object); ActionResult actionResult = controller.Delete(item.Id); // Assert. Assert.IsType <NoContentResult>(actionResult); NoContentResult actionResultType = actionResult as NoContentResult; Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.NoContent); _cashDeskServicesMock.Verify(); _cashDeskFlowValidMock.Verify(); }
public void Delete_FlowValidError() { // Arrange CustomerItem item = new CustomerItem() { Id = "5c012842f8e2708cf041e247", Name = "Caisse_01" }; Acknowledged deleteResult = new Acknowledged(1); _customerServicesMock.Setup(x => x.GetCustomer(item.Id)).Returns(Task.FromResult(item)); _customerFlowValidMock .Setup(x => x.IsValidOperation(BaseValidatorType.Delete, It.IsAny <CustomerItem>(), null)) .Returns(false) .Verifiable(); // Act CustomerController controller = new CustomerController(_customerServicesMock.Object, _customerFlowValidMock.Object); ActionResult actionResult = controller.Delete(item.Id); // Assert. Assert.IsType <BadRequestResult>(actionResult); BadRequestResult actionResultType = actionResult as BadRequestResult; Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.BadRequest); _customerServicesMock.Verify(); _customerFlowValidMock.Verify(); }
public void Delete_CountFail() { // Arrange CheckOutItem item = new CheckOutItem() { Id = "5c012842f8e2708cf041e247" }; Acknowledged deleteResult = new Acknowledged(0); _checkOutServicesMock.Setup(x => x.GetCheckOut(item.Id)).Returns(Task.FromResult(item)); _checkOutServicesMock.Setup(x => x.DeleteCheckOut(item.Id)) .ReturnsAsync(deleteResult) .Verifiable(); _checkOutFlowValidMock .Setup(x => x.IsValidOperation(BaseValidatorType.Delete, It.IsAny <CheckOutItem>(), null)) .Returns(true) .Verifiable(); // Act CheckOutController controller = new CheckOutController(_checkOutServicesMock.Object, _eventBusMock.Object, _checkOutFlowValidMock.Object); ActionResult actionResult = controller.Delete(item.Id); // Assert. Assert.IsType <NotFoundResult>(actionResult); NotFoundResult actionResultType = actionResult as NotFoundResult; Assert.Equal(actionResultType.StatusCode, (int)System.Net.HttpStatusCode.NotFound); _checkOutServicesMock.Verify(); _checkOutFlowValidMock.Verify(); }
/// <inheritdoc /> public void Acknowledge(INotificationSender sender, INotification notification) { if (string.IsNullOrEmpty(sender.Identifier)) { throw new InvalidOperationException("The identifier of the sender must be set"); } if (notification == null) { throw new ArgumentNullException(nameof(notification), "Notification must be set"); } var managed = (IManagedNotification)notification; managed.Acknowledged = DateTime.Now; managed.Acknowledger = sender.Identifier; _listLock.EnterWriteLock(); var published = _published.SingleOrDefault(n => n.Notification.Identifier == notification.Identifier); if (published != null) { _published.Remove(published); } if (published == null) { published = _pendingPubs.SingleOrDefault(n => n.Notification.Identifier == notification.Identifier); if (published == null) { _listLock.ExitWriteLock(); throw new InvalidOperationException("Notification was not managed by the adapter. " + "The sender was not registered on the adapter"); } _pendingPubs.Remove(published); } _pendingAcks.Add(published); _listLock.ExitWriteLock(); Acknowledged?.Invoke(this, published.Notification); }
/// <inheritdoc /> void INotificationSourceAdapter.PublishProcessed(INotification notification) { _listLock.EnterWriteLock(); var map = _pendingPubs.SingleOrDefault(n => n.Notification.Identifier.Equals(notification.Identifier)); if (map != null) { _pendingPubs.Remove(map); _published.Add(map); _listLock.ExitWriteLock(); } else { // Notification is maybe not pending anymore - we only can acknowledge it _listLock.ExitWriteLock(); var managed = (IManagedNotification)notification; managed.Acknowledged = DateTime.Now; managed.Acknowledger = nameof(NotificationAdapter); Acknowledged?.Invoke(this, notification); } }
/// <inheritdoc /> void INotificationSourceAdapter.Sync() { // Publish pending notifications _listLock.EnterReadLock(); var pendingPublishs = _pendingPubs.ToArray(); _listLock.ExitReadLock(); foreach (var pendingPublish in pendingPublishs) { Published?.Invoke(this, pendingPublish.Notification); } // Acknowledge pending acknowledges _listLock.EnterReadLock(); var pendingAcks = _pendingAcks.ToArray(); _listLock.ExitReadLock(); foreach (var pendingAck in pendingAcks) { Acknowledged?.Invoke(this, pendingAck.Notification); } }
internal void ConsumeAck(ViscaAckStatus ack) { _ackStatus = ack; _ackWaiter.Set(); Acknowledged?.Invoke(this, ack); }
private void OnNotificationAcknowledged(object sender, INotification notification) { Acknowledged?.Invoke(this, notification); }