public async Task ThenTransformFailsWithInvalidUserMessageWithSoapAS4StreamAsync() { // Arrange AS4Message as4Message = CreateAS4MessageWithoutAttachments(); as4Message.AddMessageUnit(new UserMessage("message-id")); MemoryStream memoryStream = as4Message.ToStream(); var receivedMessage = new ReceivedMessage(memoryStream, Constants.ContentTypes.Mime); // Act / Assert await Assert.ThrowsAnyAsync <Exception>(() => Transform(receivedMessage)); }
public void Throws_InvalidMessage_When_Receiving_SignalMessage_While_Having_A_ReceivingPMode_Configured(SignalMessage s) { // Arrange AS4Message receipt = AS4Message.Create(s); var incoming = new ReceivedMessage(receipt.ToStream(), Constants.ContentTypes.Soap); var sut = new ReceiveMessageTransformer(StubConfig.Default); sut.Configure( new Dictionary <string, string> { [ReceiveMessageTransformer.ReceivingPModeKey] = "pmode-id" }); // Act / Assert Assert.Throws <InvalidMessageException>( () => sut.TransformAsync(incoming).GetAwaiter().GetResult()); }
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 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 Create_DeliverMessages_From_UserMessages() { // Arrange string partId1 = $"part-{Guid.NewGuid()}"; var userMessage1 = new UserMessage( $"user-{Guid.NewGuid()}", new CollaborationInfo( new Service($"service-{Guid.NewGuid()}"), $"action-{Guid.NewGuid()}"), new Party("Sender", new PartyId($"id-{Guid.NewGuid()}")), new Party("Receiver", new PartyId($"id-{Guid.NewGuid()}")), new[] { new PartInfo($"cid:{partId1}") }, new MessageProperty[0]); string partId2 = $"part-{Guid.NewGuid()}"; var userMessage2 = new UserMessage( $"user-{Guid.NewGuid()}", new CollaborationInfo( new Service($"service-{Guid.NewGuid()}"), $"action-{Guid.NewGuid()}"), new Party("Sender", new PartyId($"id-{Guid.NewGuid()}")), new Party("Receiver", new PartyId($"id-{Guid.NewGuid()}")), new[] { new PartInfo($"cid:{partId2}") }, new MessageProperty[0]); AS4Message as4Message = AS4Message.Create(new [] { userMessage1, userMessage2 }); as4Message.AddAttachment(new Attachment(partId1)); as4Message.AddAttachment(new Attachment(partId2)); var receivingPMode = new ReceivingProcessingMode { Id = "deliver-pmode" }; var entity1 = new InMessage(userMessage1.MessageId); entity1.SetPModeInformation(receivingPMode); var entity2 = new InMessage(userMessage2.MessageId); entity2.SetPModeInformation(receivingPMode); var sut = new DeliverMessageTransformer(); // Act MessagingContext result1 = await sut.TransformAsync(new ReceivedEntityMessage(entity1, as4Message.ToStream(), as4Message.ContentType)); MessagingContext result2 = await sut.TransformAsync(new ReceivedEntityMessage(entity2, as4Message.ToStream(), as4Message.ContentType)); // Assert IEnumerable <string> mappingFailures1 = DeliverMessageOriginateFrom( userMessage1, receivingPMode, result1.DeliverMessage.Message); Assert.Empty(mappingFailures1); IEnumerable <string> mappingFailures2 = DeliverMessageOriginateFrom( userMessage2, receivingPMode, result2.DeliverMessage.Message); Assert.Empty(mappingFailures2); }
private static ReceivedEntityMessage CreateReceivedMessage(string receivedInMessageId, AS4Message as4Message) { var inMessage = new InMessage(receivedInMessageId); return(new ReceivedEntityMessage(inMessage, as4Message.ToStream(), as4Message.ContentType)); }
private static async Task <MessagingContext> PrepareAS4MessageForDeliveryAsync(AS4Message msg, ReceivingProcessingMode pmode) { var transformer = new DeliverMessageTransformer(); var entity = new InMessage(msg.GetPrimaryMessageId()); entity.SetPModeInformation(pmode); return(await transformer.TransformAsync(new ReceivedEntityMessage(entity, msg.ToStream(), msg.ContentType))); }