public void OnlyDequeuesMessageOnce() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); using (var trans = new TransactionScope()) { var record = _sut.Dequeue().GetPayload <SampleCommand>(); Assert.NotNull(record); Assert.Equal(message1.SomeContents, record.SomeContents); trans.Complete(); } SampleCommand lastMessage; using (var trans = new TransactionScope()) { lastMessage = _sut.Dequeue().GetPayload <SampleCommand>(); trans.Complete(); } Assert.NotNull(lastMessage); Assert.Equal(message2.SomeContents, lastMessage.SomeContents); }
public void MessageMarkedAsFailedWillNotBeDequeuedAgain() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); using (var trans = new TransactionScope()) { var record = _sut.Dequeue(); record.MarkAsFailed("The reason for failure"); trans.Complete(); } SampleCommand lastMessage; using (var trans = new TransactionScope()) { lastMessage = _sut.Dequeue().GetPayload <SampleCommand>(); trans.Complete(); } Assert.NotNull(lastMessage); Assert.Equal(message2.SomeContents, lastMessage.SomeContents); }
public void CanEnqueueAndDequeueMessage() { var message = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message); var record = _sut.Dequeue().GetPayload<SampleCommand>(); Assert.NotNull(record); Assert.Equal(message.SomeContents, record.SomeContents); }
public void DequeuesFirstMessage() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); var record = _sut.Dequeue(); Assert.NotNull(record); Assert.Equal(message1.SomeContents, record.GetPayload<SampleCommand>().SomeContents); }
public void CanEnqueueAndDequeueMessage() { var message = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message); var record = _sut.Dequeue().GetPayload <SampleCommand>(); Assert.NotNull(record); Assert.Equal(message.SomeContents, record.SomeContents); }
public void DequeuesFirstMessage() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); var record = _sut.Dequeue(); Assert.NotNull(record); Assert.Equal(message1.SomeContents, record.GetPayload <SampleCommand>().SomeContents); }
public void MessageMarkedAsFailedWillBeInTheFailedMessageRepository() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); const string theReasonForFailure = "The reason for failure"; using (var trans = new TransactionScope()) { var record = _sut.Dequeue(); _sut.MarkAsFailed(record, theReasonForFailure); trans.Complete(); } var failedMessage = _sut.GetFailedMessages().First(); Assert.NotNull(failedMessage); Assert.Equal(message1, failedMessage.GetPayload()); Assert.Equal(theReasonForFailure, failedMessage.FailureMessage); }
public void MessageNotMarkedAsFailedWillNotBeInTheFailedMessageRepository() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message3 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); _sut.Enqueue(message3); using (var trans = new TransactionScope()) { _sut.Dequeue(); trans.Complete(); } using (var trans = new TransactionScope()) { _sut.MarkAsFailed(_sut.Dequeue(), "Oh, my failures..."); trans.Complete(); } using (var trans = new TransactionScope()) { _sut.Dequeue(); trans.Complete(); } var failedMessages = _sut.GetFailedMessages().Select(m => m.GetPayload()).ToArray(); Assert.DoesNotContain(message1, failedMessages); Assert.Contains(message2, failedMessages); Assert.DoesNotContain(message3, failedMessages); }
public void MessageMarkedAsFailedWillNotBeDequeuedAgain() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); using (var trans = new TransactionScope()) { var record = _sut.Dequeue(); record.MarkAsFailed("The reason for failure"); trans.Complete(); } SampleCommand lastMessage; using (var trans = new TransactionScope()) { lastMessage = _sut.Dequeue().GetPayload<SampleCommand>(); trans.Complete(); } Assert.NotNull(lastMessage); Assert.Equal(message2.SomeContents, lastMessage.SomeContents); }
public void OnlyDequeuesMessageOnce() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); using (var trans = new TransactionScope()) { var record = _sut.Dequeue().GetPayload<SampleCommand>(); Assert.NotNull(record); Assert.Equal(message1.SomeContents, record.SomeContents); trans.Complete(); } SampleCommand lastMessage; using (var trans = new TransactionScope()) { lastMessage = _sut.Dequeue().GetPayload<SampleCommand>(); trans.Complete(); } Assert.NotNull(lastMessage); Assert.Equal(message2.SomeContents, lastMessage.SomeContents); }
public void MessageNotMarkedAsFailedWillNotBeInTheFailedMessageRepository() { var message1 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message2 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; var message3 = new SampleCommand { SomeContents = Guid.NewGuid().ToString() }; _sut.Enqueue(message1); _sut.Enqueue(message2); _sut.Enqueue(message3); using (var trans = new TransactionScope()) { _sut.Dequeue(); trans.Complete(); } using (var trans = new TransactionScope()) { _sut.MarkAsFailed( _sut.Dequeue(), "Oh, my failures..."); trans.Complete(); } using (var trans = new TransactionScope()) { _sut.Dequeue(); trans.Complete(); } var failedMessages = _sut.GetFailedMessages().Select(m=>m.GetPayload()).ToArray(); Assert.DoesNotContain(message1, failedMessages); Assert.Contains(message2, failedMessages); Assert.DoesNotContain(message3, failedMessages); }