public void FailsToBuild_IfInvalidMessageUnit() { // Arrange InMessageBuilder sut = InMessageBuilder.ForSignalMessage(Mock.Of <SignalMessage>(), AS4Message.Empty, MessageExchangePattern.Push); // Act / Assert Assert.ThrowsAny <Exception>(() => sut.BuildAsToBeProcessed()); }
public void ThenBuildInMessageFailsWithMissingMessageUnit() { // Arrange AS4Message as4Message = AS4Message.Empty; // Act / Assert Assert.ThrowsAny <Exception>( () => InMessageBuilder.ForUserMessage(null, as4Message, MessageExchangePattern.Push).BuildAsToBeProcessed()); }
public void ThenBuildInMessageFailsWitMissingAS4Message() { // Arrange Receipt messageUnit = CreateReceiptMessageUnit(); // Act / Assert Assert.ThrowsAny <Exception>( () => InMessageBuilder.ForSignalMessage(messageUnit, belongsToAS4Message: null, mep: MessageExchangePattern.Push).BuildAsToBeProcessed()); }
private void InsertUserMessages( AS4Message as4Message, MessageExchangePattern mep, string location, SendingProcessingMode pmode) { if (!as4Message.HasUserMessage) { Logger.Trace("No UserMessages present to be inserted"); return; } IDictionary <string, bool> duplicateUserMessages = DetermineDuplicateUserMessageIds(as4Message.UserMessages.Select(m => m.MessageId)); foreach (UserMessage userMessage in as4Message.UserMessages) { if (userMessage.IsTest) { Logger.Trace($"Incoming UserMessage {userMessage.MessageId} is a 'Test Message'"); } userMessage.IsDuplicate = IsUserMessageDuplicate(userMessage, duplicateUserMessages); try { InMessage inMessage = InMessageBuilder .ForUserMessage(userMessage, as4Message, mep) .WithPMode(pmode) .OnLocation(location) .BuildAsToBeProcessed(); Logger.Debug( $"Insert InMessage UserMessage {userMessage.MessageId} with {{" + $"Operation={inMessage.Operation}, " + $"Status={inMessage.Status}, " + $"PModeId={pmode?.Id ?? "null"}, " + $"IsTest={userMessage.IsTest}, " + $"IsDuplicate={userMessage.IsDuplicate}}}"); _repository.InsertInMessage(inMessage); } catch (Exception ex) { string description = $"Unable to insert UserMessage {userMessage.MessageId}"; Logger.Error(description); throw new DataException(description, ex); } } }
private void InsertSignalMessages( AS4Message as4Message, MessageExchangePattern mep, string location, SendingProcessingMode pmode) { if (!as4Message.HasSignalMessage) { Logger.Trace("No SignalMessages present to be inserted"); return; } IEnumerable <string> relatedUserMessageIds = as4Message.SignalMessages .Select(m => m.RefToMessageId) .Where(refToMessageId => !String.IsNullOrWhiteSpace(refToMessageId)); IDictionary <string, bool> duplicateSignalMessages = DetermineDuplicateSignalMessageIds(relatedUserMessageIds); foreach (SignalMessage signalMessage in as4Message.SignalMessages.Where(s => !(s is PullRequest))) { signalMessage.IsDuplicate = IsSignalMessageDuplicate(signalMessage, duplicateSignalMessages); try { InMessage inMessage = InMessageBuilder .ForSignalMessage(signalMessage, as4Message, mep) .WithPMode(pmode) .OnLocation(location) .BuildAsToBeProcessed(); Logger.Debug( $"Insert InMessage {signalMessage.GetType().Name} {signalMessage.MessageId} with {{" + $"Operation={inMessage.Operation}, " + $"Status={inMessage.Status}, " + $"PModeId={pmode?.Id}}}"); _repository.InsertInMessage(inMessage); } catch (Exception exception) { string description = $"Unable to insert SignalMessage {signalMessage.MessageId}"; Logger.Error(description); throw new DataException(description, exception); } } }
public async Task ThenBuildInMessageSucceedsWithAS4MessageAndMessageUnit() { // Arrange AS4Message as4Message = AS4Message.Empty; Receipt receipt = CreateReceiptMessageUnit(); // Act InMessage inMessage = InMessageBuilder.ForSignalMessage(receipt, as4Message, MessageExchangePattern.Push) .WithPMode(new SendingProcessingMode()) .BuildAsToBeProcessed(); // Assert Assert.NotNull(inMessage); Assert.Equal(as4Message.ContentType, inMessage.ContentType); Assert.Equal(await AS4XmlSerializer.ToStringAsync(new SendingProcessingMode()), inMessage.PMode); Assert.Equal(MessageType.Receipt, inMessage.EbmsMessageType); }
/// <summary> /// Insert a DeadLettered AS4 Error refering a specified <paramref name="ebmsMessageId"/> /// for a specified <paramref name="mep"/> notifying only if the specified <paramref name="sendingPMode"/> is configured this way. /// </summary> /// <param name="ebmsMessageId"></param> /// <param name="mep"></param> /// <param name="sendingPMode"></param> /// <exception cref="ArgumentNullException"></exception> internal void InsertDeadLetteredErrorForAsync( string ebmsMessageId, MessageExchangePattern mep, SendingProcessingMode sendingPMode) { if (ebmsMessageId == null) { throw new ArgumentNullException(nameof(ebmsMessageId)); } Error errorMessage = Error.FromErrorResult( IdentifierFactory.Instance.Create(), ebmsMessageId, new ErrorResult("Missing Receipt", ErrorAlias.MissingReceipt)); AS4Message as4Message = AS4Message.Create(errorMessage, sendingPMode); // We do not use the InMessageService to persist the incoming message here, since this is not really // an incoming message. We create this InMessage in order to be able to notify the Message Producer // if he should be notified when a message cannot be sent. // (Maybe we should only create the InMessage when notification is enabled ?) string location = Registry.Instance .MessageBodyStore .SaveAS4Message( location: Config.Instance.InMessageStoreLocation, message: as4Message); InMessage inMessage = InMessageBuilder .ForSignalMessage(errorMessage, as4Message, mep) .WithPMode(sendingPMode) .OnLocation(location) .BuildAsDeadLetteredError(); Logger.Debug($"Create Error for missed Receipt with {{Operation={inMessage.Operation}}}"); _repository.InsertInMessage(inMessage); }