public void Set_Retry_Info_When_SendingPMode_Is_Configured_For_Retry( bool enabled, PositiveInt count, TimeSpan interval) { // Arrange ClearOutExceptions(); var sut = new OutboundExceptionHandler(GetDataStoreContext, StubConfig.Default, new InMemoryMessageBodyStore()); var pmode = new SendingProcessingMode(); pmode.ExceptionHandling.Reliability = new RetryReliability { IsEnabled = enabled, RetryCount = count.Get, RetryInterval = interval.ToString("G") }; var entity = new OutMessage($"entity-{Guid.NewGuid()}"); GetDataStoreContext.InsertOutMessage(entity); // Act sut.HandleExecutionException( new Exception(), new MessagingContext( new ReceivedEntityMessage(entity), MessagingContextMode.Notify) { SendingPMode = pmode }) .GetAwaiter() .GetResult(); // Assert GetDataStoreContext.AssertOutException(ex => { Assert.Null(ex.MessageLocation); GetDataStoreContext.AssertRetryRelatedOutException( ex.Id, rr => { Assert.True( enabled == (0 == rr?.CurrentRetryCount), "CurrentRetryCount != 0 when RetryReliability is enabled"); Assert.True( enabled == (count.Get == rr?.MaxRetryCount), enabled ? $"Max retry count failed on enabled: {count.Get} != {rr?.MaxRetryCount}" : $"Max retry count should be 0 on disabled but is {rr?.MaxRetryCount}"); Assert.True( enabled == (interval == rr?.RetryInterval), enabled ? $"Retry interval failed on enabled: {interval:G} != {rr?.RetryInterval}" : $"Retry interval should be 0:00:00 on disabled but is {rr?.RetryInterval}"); }); }); }
public async Task ThenInsertOutExceptionSucceeds() { // Arrange var outException = OutException.ForEbmsMessageId($"outex-{Guid.NewGuid()}", "error"); // Act using (DatastoreContext context = GetDataStoreContext()) { new DatastoreRepository(context).InsertOutException(outException); await context.SaveChangesAsync(); } // Assert GetDataStoreContext.AssertOutException(outException.EbmsRefToMessageId, Assert.NotNull); }
private async Task TestExecutionException( Func <IAgentExceptionHandler, Task <MessagingContext> > act, Action <string> assertLocation) { // Arrange var sut = new PullSendAgentExceptionHandler(GetDataStoreContext, StubConfig.Default, new InMemoryMessageBodyStore()); // Act await act(sut); // Assert GetDataStoreContext.AssertOutException( ex => { Assert.True(ex.Exception.IndexOf(_expectedMessage, StringComparison.CurrentCultureIgnoreCase) > -1); assertLocation(ex.MessageLocation); }); }
public async Task InsertOutException_IfTransformException() { // Arrange var sut = new OutboundExceptionHandler(GetDataStoreContext, StubConfig.Default, new InMemoryMessageBodyStore()); // Act MessagingContext context = await sut.ExerciseTransformException(GetDataStoreContext, _expectedBody, _expectedException); // Assert Assert.Same(_expectedException, context.Exception); GetDataStoreContext.AssertOutException( ex => { Assert.NotNull(ex); Assert.True(ex.Exception.IndexOf(_expectedException.Message, StringComparison.CurrentCultureIgnoreCase) > -1, "Not equal message insterted"); }); }
private async Task TestHandleExecutionException( Operation expected, MessagingContext context, Func <IAgentExceptionHandler, Func <Exception, MessagingContext, Task <MessagingContext> > > getExercise) { var sut = new OutboundExceptionHandler(GetDataStoreContext, StubConfig.Default, new InMemoryMessageBodyStore()); Func <Exception, MessagingContext, Task <MessagingContext> > exercise = getExercise(sut); // Act await exercise(_expectedException, context); // Assert GetDataStoreContext.AssertOutMessage(_expectedId, m => Assert.Equal(OutStatus.Exception, m.Status.ToEnum <OutStatus>())); GetDataStoreContext.AssertOutException( _expectedId, exception => { Assert.True(exception.Exception.IndexOf(_expectedException.Message, StringComparison.CurrentCultureIgnoreCase) > -1, "Message does not contain expected message"); Assert.True(expected == exception.Operation, "Not equal 'Operation' inserted"); Assert.True(exception.MessageLocation == null, "Inserted exception body is not empty"); }); }
public async Task InsertInException_IfHandlingTransformException() { // Arrange byte[] expectedBody = Encoding.UTF8.GetBytes("serialize me!"); using (var bodyStore = new InMemoryMessageBodyStore()) using (var stream = new MemoryStream(expectedBody)) { var sut = new PullSendAgentExceptionHandler(GetDataStoreContext, StubConfig.Default, bodyStore); // Act await sut.HandleTransformationException( new Exception(_expectedMessage), new ReceivedMessage(stream)); } // Assert GetDataStoreContext.AssertOutException( ex => { Assert.NotNull(ex); Assert.Equal(_expectedMessage, ex.Exception); }); }