private void InsertUserMessage(string mpc, MessageExchangePattern pattern, Operation operation) { var sendingPMode = new SendingProcessingMode() { Id = "SomePModeId", MessagePackaging = { Mpc = mpc } }; UserMessage userMessage = SendingPModeMap.CreateUserMessage(sendingPMode); AS4Message as4Message = AS4Message.Create(userMessage, sendingPMode); var om = new OutMessage(userMessage.MessageId) { MEP = pattern, Mpc = mpc, ContentType = as4Message.ContentType, EbmsMessageType = MessageType.UserMessage, Operation = operation, MessageLocation = InMemoryMessageBodyStore.Default.SaveAS4Message(location: "some-location", message: as4Message) }; om.SetPModeInformation(sendingPMode); GetDataStoreContext.InsertOutMessage(om); }
public async Task Updates_Status_Nack_Related_UserMessage_OutMessage() { // Arrange string ebmsMessageId = "error-" + Guid.NewGuid(); GetDataStoreContext.InsertOutMessage(CreateOutMessage(ebmsMessageId)); var error = Error.FromErrorResult( $"error-{Guid.NewGuid()}", ebmsMessageId, new ErrorResult("Some Error", ErrorAlias.ConnectionFailure)); // Act await ExerciseUpdateReceivedMessage( AS4Message.Create(error), CreateNotifyAllSendingPMode(), receivePMode : null); // Assert GetDataStoreContext.AssertOutMessage( ebmsMessageId, m => { Assert.NotNull(m); Assert.Equal(OutStatus.Nack, m.Status.ToEnum <OutStatus>()); }); }
public async Task Doesnt_Update_OutMessage_If_No_MessageLocation_Can_Be_Found() { // Arrange string knownId = "known-id-" + Guid.NewGuid(); GetDataStoreContext.InsertOutMessage( new OutMessage(knownId) { MessageLocation = null }); var ctx = new MessagingContext( AS4Message.Create(new FilledUserMessage(knownId)), MessagingContextMode.Unknown) { SendingPMode = CreateNotifyAllSendingPMode() }; var sut = new UpdateReceivedAS4MessageBodyStep(StubConfig.Default, GetDataStoreContext, _messageBodyStore); // Act await sut.ExecuteAsync(ctx); // Assert GetDataStoreContext.AssertOutMessage(knownId, m => Assert.Null(m.MessageLocation)); }
public async Task Updates_ToBeNotified_When_Specified_SendingPMode_And_Reference_InMessage() { // Arrange string ebmsMessageId = Guid.NewGuid().ToString(); GetDataStoreContext.InsertOutMessage(new OutMessage(ebmsMessageId)); AS4Message receivedAS4Message = AS4Message.Create(new Receipt($"receipt-{Guid.NewGuid()}", ebmsMessageId)); // Act await ExerciseUpdateReceivedMessage( receivedAS4Message, CreateNotifyAllSendingPMode(), receivePMode : null); // Assert GetDataStoreContext.AssertInMessageWithRefToMessageId( ebmsMessageId, m => { Assert.NotNull(m); Assert.Equal(Operation.ToBeNotified, m.Operation); }); GetDataStoreContext.AssertOutMessage( ebmsMessageId, m => { Assert.NotNull(m); Assert.Equal(OutStatus.Ack, m.Status.ToEnum <OutStatus>()); }); }
private void InsertOutMessage(string messageId, SendingProcessingMode pmode) { var outMessage = new OutMessage(ebmsMessageId: messageId); outMessage.SetPModeInformation(pmode); GetDataStoreContext.InsertOutMessage(outMessage); }
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}"); }); }); }
private OutMessage InsertOutMessage(string ebmsMessageId, Operation operation = Operation.NotApplicable) { var outMessage = new OutMessage(ebmsMessageId: ebmsMessageId); outMessage.Operation = operation; GetDataStoreContext.InsertOutMessage(outMessage, withReceptionAwareness: false); return(outMessage); }
private MessagingContext SetupMessagingContextForOutMessage(string ebmsMessageId) { // Arrange var message = new OutMessage(ebmsMessageId: ebmsMessageId); message.SetStatus(OutStatus.Sent); GetDataStoreContext.InsertOutMessage(message, withReceptionAwareness: false); var receivedMessage = new ReceivedEntityMessage(message, Stream.Null, string.Empty); var context = new MessagingContext(receivedMessage, MessagingContextMode.Unknown); return(context); }
private void InsertReceipt( Receipt receipt, Operation operation, string url, bool signed = false) { GetDataStoreContext.InsertOutMessage( new OutMessage(receipt.MessageId) { EbmsRefToMessageId = receipt.RefToMessageId, EbmsMessageType = MessageType.Receipt, ContentType = Constants.ContentTypes.Soap, MessageLocation = SaveAS4MessageUnit(receipt, signed), Operation = operation, Url = url }); }
public async Task Update_RetryReliability_To_Pending_When_Receiver_Is_Offline() { // Arrange string ebmsMessageId = $"user-{Guid.NewGuid()}"; AS4Message tobeSendMessage = AS4Message.Create(new UserMessage(ebmsMessageId)); var outMessage = new OutMessage(ebmsMessageId); GetDataStoreContext.InsertOutMessage(outMessage); GetDataStoreContext.InsertRetryReliability( RetryReliability.CreateForOutMessage( refToOutMessageId: outMessage.Id, maxRetryCount: 2, retryInterval: TimeSpan.FromSeconds(1), type: RetryType.Send)); var ctx = new MessagingContext( tobeSendMessage, new ReceivedEntityMessage( outMessage, tobeSendMessage.ToStream(), tobeSendMessage.ContentType), MessagingContextMode.Send) { SendingPMode = CreateSendPModeWithPushUrl() }; var sabotageException = new WebException("Remote host not available"); IStep sut = CreateSendStepWithResponse( StubHttpClient.ThatThrows(sabotageException)); // Act StepResult result = await sut.ExecuteAsync(ctx); // Assert Assert.False(result.Succeeded); GetDataStoreContext.AssertRetryRelatedOutMessage( outMessage.Id, r => { Assert.NotNull(r); Assert.Equal(RetryStatus.Pending, r.Status); }); }
public async Task Updates_Error_InMessage_With_Retry_Info_When_Specified(bool enabled, int count, string intervalString) { TimeSpan interval = intervalString.AsTimeSpan(); // Arrange string ebmsMessageId = "error-" + Guid.NewGuid(); OutMessage om = GetDataStoreContext.InsertOutMessage( CreateOutMessage(ebmsMessageId)); var error = Error.FromErrorResult( $"error-{Guid.NewGuid()}", ebmsMessageId, new ErrorResult("Some Error occured", ErrorAlias.ConnectionFailure)); SendingProcessingMode pmode = CreateNotifyAllSendingPMode(); pmode.ErrorHandling.Reliability = new RetryReliability { IsEnabled = enabled, RetryCount = 5, RetryInterval = "0:00:01:00" }; // Act await ExerciseUpdateReceivedMessage( AS4Message.Create(error), pmode, receivePMode : null); // Assert GetDataStoreContext.AssertRetryRelatedInMessage( om.Id, rr => { Assert.True(enabled == (rr != null), "RetryReliability inserted while not enabled"); Assert.True(enabled == (0 == rr?.CurrentRetryCount), "CurrentRetryCount != 0 when enabled"); Assert.True(enabled == (count == rr?.MaxRetryCount), $"MaxRetryCount {count} != {rr?.MaxRetryCount} when enabled"); Assert.True( enabled == (interval == rr?.RetryInterval), $"RetryInterval {interval} != {rr?.RetryInterval} when enabled"); }); }
private MessagingContext SetupMessagingContext(string ebmsMessageId, Operation operation, string messageLocation) { var outMessage = new OutMessage(ebmsMessageId: ebmsMessageId) { MessageLocation = messageLocation }; outMessage.Operation = operation; var insertedOutMessage = GetDataStoreContext.InsertOutMessage(outMessage, withReceptionAwareness: false); Assert.NotEqual(default(long), insertedOutMessage.Id); var receivedMessage = new ReceivedEntityMessage(insertedOutMessage); return(new MessagingContext( AS4Message.Create(new FilledUserMessage(ebmsMessageId)), receivedMessage, MessagingContextMode.Send)); }
public async Task After_Send_Updates_Request_Operation_And_Status_To_Sent_For_Exsiting_SendPMode() { // Arrange string ebmsMessageId = $"user-{Guid.NewGuid()}"; AS4Message tobeSentMsg = AS4Message.Create(new FilledUserMessage(ebmsMessageId)); var inserted = new OutMessage(ebmsMessageId: ebmsMessageId); GetDataStoreContext.InsertOutMessage(inserted); var receivedMessage = new ReceivedEntityMessage( inserted, tobeSentMsg.ToStream(), tobeSentMsg.ContentType); var ctx = new MessagingContext( tobeSentMsg, receivedMessage, MessagingContextMode.Send) { SendingPMode = CreateSendPModeWithPushUrl() }; AS4Message receiptMessage = AS4Message.Create(new Receipt($"receipt-{Guid.NewGuid()}", $"user-{Guid.NewGuid()}")); // Act IStep sut = CreateSendStepWithResponse( StubHttpClient.ThatReturns(receiptMessage)); await sut.ExecuteAsync(ctx); // Assert GetDataStoreContext.AssertOutMessage( ebmsMessageId, message => { Assert.Equal(OutStatus.Sent, message.Status.ToEnum <OutStatus>()); Assert.Equal(Operation.Sent, message.Operation); }); }
public async Task Updates_Receipt_InMessage_With_Info_When_Specified(bool enabled, int count, string intervalString) { TimeSpan interval = intervalString.AsTimeSpan(); // Arrange string ebmsMessageId = Guid.NewGuid().ToString(); GetDataStoreContext.InsertOutMessage( new OutMessage(ebmsMessageId)); AS4Message receipt = AS4Message.Create(new Receipt($"receipt-{Guid.NewGuid()}", ebmsMessageId)); SendingProcessingMode pmode = CreateNotifyAllSendingPMode(); pmode.ReceiptHandling.Reliability = new RetryReliability { IsEnabled = enabled, RetryCount = 3, RetryInterval = "0:00:00:10" }; // Act await ExerciseUpdateReceivedMessage(receipt, pmode, receivePMode : null); // Assert long id = GetDataStoreContext.GetInMessage(m => m.EbmsRefToMessageId == ebmsMessageId).Id; GetDataStoreContext.AssertRetryRelatedInMessage( id, rr => { Assert.True(enabled == (rr != null), "RetryReliability inserted while not enabled"); Assert.True(enabled == (0 == rr?.CurrentRetryCount), "CurrentRetryCount != 0 when enabled"); Assert.True(enabled == (count == rr?.MaxRetryCount), $"MaxRetryCount {count} != {rr?.MaxRetryCount} when enabled"); Assert.True( enabled == (interval == rr?.RetryInterval), $"RetryInterval {interval} != {rr?.RetryInterval} when enabled"); }); }