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 ItShouldStoreTheExpectedMessagesWhenNoExceptionIsThrown( [Frozen] IStorageProvider <long> storageProvider, [Frozen] IStorageMessageSerializer serializer, CancellationToken cancellation, NotificationTransaction expectedTransaction, INotification <long>[] expectedNotifications, INotificationChannel <long> channel, AbstractMessageProcessor <long> sut) { // Arrange // Act await sut.GetMessages(cancellation); // Assert A.CallTo(() => storageProvider.Store(serializer, expectedNotifications)).MustHaveHappened(Repeated.Exactly.Once) .Then(A.CallTo(() => channel.Commit(expectedNotifications, expectedTransaction)).MustHaveHappened(Repeated.Exactly.Once)); }
public async Task ItShouldRollbackTheExpectedMessagesWhenAnExceptionIsThrown( [Frozen] IStorageProvider <long> storageProvider, NotificationTransaction expectedTransaction, INotification <long>[] expectedNotifications, INotificationChannel <long> channel, AbstractMessageProcessor <long> sut) { // Arrange A.CallTo(() => storageProvider.Store( A <IStorageMessageSerializer> ._, A <INotification <long>[]> ._)) .Throws <Exception>(); // Act await sut.GetMessages(CancellationToken.None); // Assert A.CallTo(() => channel.Commit(A <INotification <long>[]> ._, A <NotificationTransaction> ._)).MustNotHaveHappened(); A.CallTo(() => channel.Rollback(expectedNotifications, expectedTransaction)).MustHaveHappened(Repeated.Exactly.Once); }
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)); } }