private async void ReceiveMessageEntity( MessageEntity messageEntity, Function messageCallback, CancellationToken token) { Logger.Debug($"Received message FROM {Table} WHERE {Filter}"); using (Stream stream = await messageEntity.RetrieveMessageBody(Registry.Instance.MessageBodyStore)) { if (stream == null) { Logger.Error($"MessageBody cannot be retrieved for EbmsMessageId: {messageEntity.EbmsMessageId}"); } else if (messageEntity.ContentType == null) { Logger.Error($"ContentType cannot be found for EbmsMessageId: {messageEntity.EbmsMessageId}"); } else { ReceivedEntityMessage receivedMessage = null; try { receivedMessage = new ReceivedEntityMessage(messageEntity, stream, messageEntity.ContentType); await messageCallback(receivedMessage, token).ConfigureAwait(false); } finally { receivedMessage?.UnderlyingStream.Dispose(); } } } }
private static async void ReceiveEntity(Entity entity, Function messageCallback, CancellationToken token) { var message = new ReceivedEntityMessage(entity); MessagingContext result = await messageCallback(message, token).ConfigureAwait(false); result?.Dispose(); }
public async Task ThenSignalMessageIsTransformedToNotifyEnvelopeWithCorrectContents() { // Arrange ReceivedEntityMessage receivedSignal = await CreateReceivedReceiptMessage(); // Act MessagingContext result = await ExerciseTransform(receivedSignal); // Assert Assert.NotNull(result.NotifyMessage); var notifyMessage = AS4XmlSerializer.FromString <NotifyMessage>(Encoding.UTF8.GetString(result.NotifyMessage.NotifyMessage)); Assert.NotNull(notifyMessage); // Assert: check if the original Receipt is a part of the NotifyMessage. var document = new XmlDocument { PreserveWhitespace = true }; document.LoadXml(Encoding.UTF8.GetString(((MemoryStream)receivedSignal.UnderlyingStream).ToArray())); Assert.Equal( Canonicalize(document.SelectSingleNode("//*[local-name()='SignalMessage']")), Canonicalize(notifyMessage.StatusInfo.Any.First())); }
private static async Task <MessagingContext> ExerciseTransform(string expectedId, AS4Message as4Message) { ReceivedEntityMessage receivedMessage = CreateReceivedMessage(receivedInMessageId: expectedId, as4Message: as4Message); var sut = new DeliverMessageTransformer(); return(await sut.TransformAsync(receivedMessage)); }
public async Task FailsToTransform_IfMessageDoesntHaveAnyMatchingSignalMessages() { // Arrange ReceivedEntityMessage receival = await CreateInvalidReceivedReceiptMessage(); // Act / Assert await Assert.ThrowsAnyAsync <Exception>(() => ExerciseTransform(receival)); }
public async Task FailsToTransform_IfNoUserMessageCanBeFound() { // Arrange var sut = new DeliverMessageTransformer(); ReceivedEntityMessage receivedMessage = CreateReceivedMessage(receivedInMessageId: "ignored id", as4Message: AS4Message.Empty); // Act / Assert await Assert.ThrowsAnyAsync <Exception>( () => sut.TransformAsync(receivedMessage)); }
public async void ThenInExceptionIsTransformedToNotifyEnvelope() { // Arrange ReceivedEntityMessage receivedMessage = CreateReceivedExceptionMessage(InException.ForEbmsMessageId("id", "error"), Operation.ToBeNotified); var transformer = new NotifyMessageTransformer(); var result = await transformer.TransformAsync(receivedMessage); Assert.NotNull(result.NotifyMessage); Assert.Equal( ((ExceptionEntity)receivedMessage.Entity).EbmsRefToMessageId, result.NotifyMessage.MessageInfo.RefToMessageId); }
public async Task ThenNotifyMessageHasCorrectStatusCode() { // Arrange ReceivedEntityMessage receivedSignal = await CreateReceivedReceiptMessage(); // Act MessagingContext result = await ExerciseTransform(receivedSignal); // Assert NotifyMessageEnvelope notifyMessage = result.NotifyMessage; Assert.NotNull(notifyMessage); Assert.Equal(Status.Delivered, notifyMessage.StatusCode); }
private static async Task <ReceivedEntityMessage> CreateReceivedReceiptMessage() { var receiptContent = new MemoryStream(Encoding.UTF8.GetBytes(Properties.Resources.receipt)); ISerializer serializer = SerializerProvider.Default.Get(Constants.ContentTypes.Soap); AS4Message receiptMessage = await serializer.DeserializeAsync(receiptContent, Constants.ContentTypes.Soap); receiptContent.Position = 0; InMessage receiptInMessage = CreateInMessageFor(receiptMessage); var receivedMessage = new ReceivedEntityMessage(receiptInMessage, receiptContent, receiptInMessage.ContentType); return(receivedMessage); }
public async void ThenTransformSucceedsWithValidInExceptionForErrorProperties() { // Arrange ReceivedEntityMessage receivedMessage = CreateReceivedExceptionMessage(InException.ForEbmsMessageId("id", "error"), Operation.ToBeNotified); var transformer = new NotifyMessageTransformer(); // Act MessagingContext messagingContext = await transformer.TransformAsync(receivedMessage); // Assert Assert.Equal(Status.Exception, messagingContext.NotifyMessage.StatusCode); Assert.Equal(((InException)receivedMessage.Entity).EbmsRefToMessageId, messagingContext.NotifyMessage.MessageInfo.RefToMessageId); }
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); }
public async Task ThenSignalMessageIsTransformedToNotifyEnvelopeWithCorrectMessageInfo() { // Arrange ReceivedEntityMessage receivedSignal = await CreateReceivedReceiptMessage(); var receivedMessageEntity = (MessageEntity)receivedSignal.Entity; // Act MessagingContext result = await ExerciseTransform(receivedSignal); // Assert Assert.NotNull(result.NotifyMessage); Assert.Equal(receivedMessageEntity.EbmsMessageId, result.NotifyMessage.MessageInfo.MessageId); Assert.Equal(receivedMessageEntity.EbmsRefToMessageId, result.NotifyMessage.MessageInfo.RefToMessageId); }
private MessagingContext ContextWithReferencedToBeForwardMessage() { ReceivedEntityMessage receivedMessage; using (DatastoreContext db = GetDataStoreContext()) { InMessage inMessage = db.InMessages.First(m => m.Operation == Operation.ToBeForwarded); receivedMessage = new ReceivedEntityMessage(inMessage, Stream.Null, ""); } return(new MessagingContext(receivedMessage, MessagingContextMode.Forward) { SendingPMode = CreateSendingPMode() }); }
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); }); }