public async Task ItShouldNotCommitNotificationsIfReceivedAnEmptyCollectionOfNotifications( INotificationChannel <long> channel, AbstractMessageProcessor <long> sut) { // Arrange A.CallTo(() => channel.Receive(A <CancellationToken> ._)) .Returns(Enumerable.Empty <INotification <long> >().ToArray()); // Act await sut.GetMessages(CancellationToken.None); // Assert A.CallTo(() => channel.Commit(A <INotification <long>[]> ._, A <NotificationTransaction> ._)) .MustNotHaveHappened(); }
public async Task ItShouldReturnTheExpectedResultsIfReceivedAnEmptyCollectionOfNotifications( INotificationChannel <long> channel, AbstractMessageProcessor <long> sut) { // Arrange A.CallTo(() => channel.Receive(A <CancellationToken> ._)) .Returns(Enumerable.Empty <INotification <long> >().ToArray()); var likeness = new MessageEnvelope(null, null) .AsSource() .OfLikeness <MessageEnvelope>(); // Act var actual = await sut.GetMessages(CancellationToken.None); // Assert likeness.ShouldEqual(actual); }
public async Task <MessageEnvelope> GetMessages(CancellationToken cancellation) { // very lame representation of what this method could look like var notifications = await _notificationChannel.Receive(cancellation); if (!notifications.Any()) { return(new MessageEnvelope()); } var transaction = _transactionTracker.CreateTransaction(); try { _storageProvider.Store(_messageSerializer, notifications); _notificationChannel.Commit(notifications, transaction); return(new MessageEnvelope("Notifications Commited", transaction)); } catch (Exception ex) { _notificationChannel.Rollback(notifications, transaction); return(new MessageEnvelope(ex.Message, transaction)); } }