private async Task TestExecutionException( Operation expected, MessagingContext context, Func <IAgentExceptionHandler, Func <Exception, MessagingContext, Task <MessagingContext> > > getExercise) { // Arrange var inMessage = new InMessage(ebmsMessageId: _expectedId); inMessage.SetStatus(InStatus.Received); GetDataStoreContext.InsertInMessage(inMessage); IAgentExceptionHandler sut = CreateInboundExceptionHandler(); var exercise = getExercise(sut); // Act await exercise(new Exception(), context); // Assert GetDataStoreContext.AssertInMessage(_expectedId, m => Assert.Equal(InStatus.Exception, m.Status.ToEnum <InStatus>())); GetDataStoreContext.AssertInException( _expectedId, ex => { Assert.Equal(expected, ex.Operation); Assert.Null(ex.MessageLocation); }); }
public async Task ThenExecuteStepWithReceivingPModeAsync() { // Arrange var entity = new InMessage($"error-{Guid.NewGuid()}"); entity.InitializeIdFromDatabase(1); var fixture = new MessagingContext( EmptyNotifyMessageEnvelope(Status.Error), new ReceivedEntityMessage(entity)) { SendingPMode = new SendingProcessingMode { ErrorHandling = { NotifyMethod = new LocationMethod("not-empty-location") } } }; GetDataStoreContext.InsertInMessage(new InMessage($"entity-{Guid.NewGuid()}")); var spySender = new SpySender(); IStep sut = CreateSendNotifyStepWithSender(spySender); // Act await sut.ExecuteAsync(fixture); // Assert Assert.True(spySender.IsNotified); }
public async Task SignalMessage_Gets_Saved_As_Duplicate_When_InMessage_Exists_With_Same_EbmsRefToMessageId() { // Arrange string ebmsMessageId = $"receipt-{Guid.NewGuid()}"; string ebmsRefToMessageId = $"user-{Guid.NewGuid()}"; GetDataStoreContext.InsertInMessage( new InMessage(ebmsMessageId) { EbmsRefToMessageId = ebmsRefToMessageId }); var receipt = new Receipt(ebmsMessageId, ebmsRefToMessageId); var context = new MessagingContext( AS4Message.Create(receipt), new ReceivedMessage(Stream.Null), MessagingContextMode.Receive); // Act await Step.ExecuteAsync(context); // Assert InMessage actual = GetDataStoreContext.GetInMessage( m => m.EbmsMessageId == ebmsMessageId && m.EbmsRefToMessageId == ebmsRefToMessageId && m.IsDuplicate); Assert.True(actual != null, "Saved Receipt should be marked as duplicate"); }
public Property Updates_Bundled_MessageUnits_For_Forwarding() { return(Prop.ForAll( CreateUserReceiptArb(), messageUnits => { // Before Assert.All( messageUnits, u => GetDataStoreContext.InsertInMessage(new InMessage(u.MessageId))); // Arrange AS4Message received = AS4Message.Create(messageUnits); // Act ExerciseUpdateReceivedMessage( received, CreateNotifyAllSendingPMode(), CreateForwardingReceivingPMode()) .GetAwaiter() .GetResult(); // Assert IEnumerable <InMessage> updates = GetDataStoreContext.GetInMessages( m => received.MessageIds.Contains(m.EbmsMessageId)); Assert.All(updates, u => Assert.True(u.Intermediary)); InMessage primaryUpdate = updates.First(u => u.EbmsMessageId == received.GetPrimaryMessageId()); Assert.Equal(Operation.ToBeForwarded, primaryUpdate.Operation); })); }
public async Task Fails_To_Store_SignalMessage_When_ReplyPattern_Response_For_Pulled_UserMessage() { // Arrange string userMessageId = $"user-{Guid.NewGuid()}"; GetDataStoreContext.InsertInMessage( new InMessage(userMessageId) { MEP = MessageExchangePattern.Pull }); var receipt = new Receipt($"receipt-{Guid.NewGuid()}", userMessageId); var context = new MessagingContext( AS4Message.Create(receipt), MessagingContextMode.Receive) { SendingPMode = new SendingProcessingMode { Id = "shortcut-send-pmode-retrieval" }, ReceivingPMode = new ReceivingProcessingMode { ReplyHandling = { ReplyPattern = ReplyPattern.Response } } }; // Act / Assert await Assert.ThrowsAsync <InvalidOperationException>( () => ExerciseStoreSignalMessageAsync(context)); }
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 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); }
private void InsertRefInMessage(string refToEbmsMessageId) { GetDataStoreContext.InsertInMessage(new InMessage(Guid.NewGuid().ToString()) { EbmsRefToMessageId = refToEbmsMessageId }); }
private void InsertInMessage(string messageId, Action <InMessage> arrangeMessage) { var message = new InMessage(ebmsMessageId: messageId); arrangeMessage(message); GetDataStoreContext.InsertInMessage(message); }
public void ThenInsertInMessageSucceedsAsync(string sharedId) { // Arrange InsertInMessageWithOperation(sharedId); // Assert GetDataStoreContext.AssertInMessage(sharedId, Assert.NotNull); }
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 InMessage InsertInMessage(string id) { var inMsg = new InMessage(id); inMsg.SetStatus(InStatus.Received); inMsg.Operation = Operation.Delivering; return(GetDataStoreContext.InsertInMessage(inMsg)); }
public void Stores_Retry_Information_For_ToBePiggyBacked_SignalMessages(bool isEnabled, int maxRetryCount, TimeSpan retryInterval) { // Arrange string userMessageId = $"user-{Guid.NewGuid()}"; GetDataStoreContext.InsertInMessage( new InMessage(userMessageId) { MEP = MessageExchangePattern.Pull }); var receipt = new Receipt($"receipt-{Guid.NewGuid()}", userMessageId); var context = new MessagingContext( AS4Message.Create(receipt), MessagingContextMode.Receive) { SendingPMode = new SendingProcessingMode { Id = "shortcut-send-pmode-retrieval" }, ReceivingPMode = new ReceivingProcessingMode { ReplyHandling = { ReplyPattern = ReplyPattern.PiggyBack, PiggyBackReliability = new AS4.Model.PMode.RetryReliability { IsEnabled = isEnabled, RetryCount = maxRetryCount, RetryInterval = retryInterval.ToString() } } } }; // Act ExerciseStoreSignalMessageAsync(context) .GetAwaiter() .GetResult(); // Assert GetDataStoreContext.AssertOutMessage( receipt.MessageId, m => GetDataStoreContext.AssertRetryRelatedOutMessage( m.Id, r => { Assert.True( isEnabled == (0 == r?.CurrentRetryCount), $"Enabling PiggyBack Reliability should result in 0 = {r?.CurrentRetryCount}"); Assert.True( isEnabled == (maxRetryCount == r?.MaxRetryCount), $"Enabling PiggyBack Reliability should result in {maxRetryCount} = {r?.MaxRetryCount}"); Assert.True( isEnabled == (retryInterval == r?.RetryInterval), $"Enabling PiggyBack Reliability should result in {retryInterval} = {r?.RetryInterval}"); })); }
private InMessage GetUserInMessageForEbmsMessageId(MessageUnit userMessage) { InMessage inMessage = GetDataStoreContext .GetInMessage(m => m.EbmsMessageId.Equals(userMessage.MessageId)); Assert.NotNull(inMessage); Assert.Equal(MessageType.UserMessage, inMessage.EbmsMessageType); return(inMessage); }
private void InsertUserMessage(UserMessage user) { GetDataStoreContext.InsertInMessage( new InMessage(user.MessageId) { Mpc = user.Mpc, EbmsMessageType = MessageType.UserMessage, ContentType = Constants.ContentTypes.Soap }); }
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); }
public async Task NoExceptionGetsLogged_IfNoErrorResultIsPresent() { // Arrange string id = Guid.NewGuid().ToString(); AS4Message as4Message = AS4Message.Create(new Error($"error-{Guid.NewGuid()}", id)); // Act await ExerciseLog(as4Message, error : null); // Assert GetDataStoreContext.AssertInException(id, Assert.Null); }
public Property Updates_Bundled_MessageUnits_For_Delivery() { return(Prop.ForAll( CreateUserReceiptArb(), messageUnits => { // Before Assert.All( messageUnits, u => GetDataStoreContext.InsertInMessage( new InMessage(u.MessageId) { EbmsMessageType = u is UserMessage ? MessageType.UserMessage : MessageType.Receipt })); // Arrange var sut = new UpdateReceivedAS4MessageBodyStep( StubConfig.Default, GetDataStoreContext, _messageBodyStore); var ctx = new MessagingContext( AS4Message.Create(messageUnits), MessagingContextMode.Receive) { SendingPMode = CreateNotifyAllSendingPMode(), ReceivingPMode = CreateDeliveryReceivingPMode() }; // Act sut.ExecuteAsync(ctx) .GetAwaiter() .GetResult(); // Assert Operation UpdatedOperationOf(MessageType t) => t == MessageType.UserMessage ? Operation.ToBeDelivered : Operation.ToBeNotified; IEnumerable <InMessage> updates = GetDataStoreContext.GetInMessages( m => ctx.AS4Message.MessageIds.Contains(m.EbmsMessageId)); Assert.All( updates, u => Assert.Equal(UpdatedOperationOf(u.EbmsMessageType), u.Operation)); })); }
public Property Bundle_Receipt_With_PullRequest() { Gen <Operation> genOperation = Gen.Frequency( Tuple.Create(4, Gen.Constant(Operation.ToBePiggyBacked)), Tuple.Create(1, Arb.Generate <Operation>())); return(Prop.ForAll( genOperation.ToArbitrary(), EqualAndDiffer(() => $"mpc-{Guid.NewGuid()}").ToArbitrary(), EqualAndDiffer(() => $"http://localhost/{Guid.NewGuid()}").ToArbitrary(), (operation, urls, mpcs) => { // Arrange var user = new UserMessage($"user-{Guid.NewGuid()}", mpcs.Item1); var receipt = new Receipt($"receipt-{Guid.NewGuid()}", user.MessageId); InsertUserMessage(user); InsertReceipt(receipt, operation, urls.Item1); var pr = new PullRequest($"pr-{Guid.NewGuid()}", mpcs.Item2); // Act StepResult result = ExerciseBundleWithPullRequest(pr, urls.Item2); // Assert AS4Message bundled = result.MessagingContext.AS4Message; bool bundledWithReceipt = bundled.MessageIds.SequenceEqual(new[] { pr.MessageId, receipt.MessageId }) && IsPullRequestBundledWithOneReceipt(result); bool isOperationPiggyBacked = operation == Operation.ToBePiggyBacked; bool isMatchedByMpc = mpcs.Item1 == mpcs.Item2; bool isMatchedByUrl = urls.Item1 == urls.Item2; bool operationBecomesSending = GetDataStoreContext .GetInMessages(m => m.EbmsMessageId == receipt.MessageId) .All(m => m.Operation == Operation.Sending); return (isOperationPiggyBacked && isMatchedByMpc && isMatchedByUrl) .Equals(bundledWithReceipt && operationBecomesSending) .Label( "PullRequest isn't bundled with Receipt when the Operation of the " + $"stored Receipt is {operation} and the MPC of the " + $"UserMessage {(isMatchedByMpc ? "matches" : "differs")} from the PullRequest MPC " + $"and Receipt {(isMatchedByUrl ? "matches" : "differs")} from the PullRequest Url"); })); }
public async Task During_Saving_The_Deserialized_AS4Message_Is_Used_Instead_Of_Deserializing_Incoming_Stream() { // Arrange var receipt = new Receipt($"receipt-{Guid.NewGuid()}", $"reftoid-{Guid.NewGuid()}"); var ctx = new MessagingContext( AS4Message.Create(receipt), new ReceivedMessage(Stream.Null, Constants.ContentTypes.Soap), MessagingContextMode.Receive); // Act await Step.ExecuteAsync(ctx); // Assert GetDataStoreContext.AssertInMessage(receipt.MessageId, Assert.NotNull); }
public async Task ThenInsertInExceptionSucceeds() { // Arrange var inException = InException.ForEbmsMessageId($"inex-{Guid.NewGuid()}", "error"); // Act using (DatastoreContext context = GetDataStoreContext()) { new DatastoreRepository(context).InsertInException(inException); await context.SaveChangesAsync(); } GetDataStoreContext.AssertInException(inException.EbmsRefToMessageId, Assert.NotNull); }
public async Task InExceptionGetsInserted_IfErrorResultAndAS4MessageArePresent() { // Arrange string id = Guid.NewGuid().ToString(), expected = Guid.NewGuid().ToString(); AS4Message as4Message = AS4Message.Create(new Error($"error-{Guid.NewGuid()}", id)); var error = new ErrorResult(expected, default(ErrorAlias)); // Act await ExerciseLog(as4Message, error); // Assert GetDataStoreContext.AssertInException(id, ex => Assert.Equal(expected, ex.Exception)); }
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 Only_Unsigned_Signals_Are_PiggyBacked_For_SendingPModes_Where_Signing_Is_Not_Configured() { // Arrange const string url = "http://localhost:8081/msh"; string mpc = $"mpc-{Guid.NewGuid()}"; var user = new UserMessage($"user-{Guid.NewGuid()}", mpc); var unsignedReceipt = new Receipt($"receipt-{Guid.NewGuid()}", user.MessageId); var signedReceipt = new Receipt($"receipt-{Guid.NewGuid()}", user.MessageId); InsertUserMessage(user); InsertReceipt(unsignedReceipt, Operation.ToBePiggyBacked, url, signed: false); InsertReceipt(signedReceipt, Operation.ToBePiggyBacked, url, signed: true); var pr = new PullRequest($"pr-{Guid.NewGuid()}", mpc); var ctx = new MessagingContext(AS4Message.Create(pr), MessagingContextMode.PullReceive) { SendingPMode = new SendingProcessingMode { PushConfiguration = new PushConfiguration { Protocol = { Url = url } }, Security = { Signing = { IsEnabled = false } } } }; var sut = new BundleSignalMessageToPullRequestStep(GetDataStoreContext, _bodyStore); // Act StepResult result = await sut.ExecuteAsync(ctx); // Assert Assert.True(result.Succeeded); Assert.Collection( result.MessagingContext.AS4Message.MessageUnits, u => Assert.IsType <PullRequest>(u), u => Assert.Equal(unsignedReceipt.MessageId, Assert.IsType <Receipt>(u).MessageId)); GetDataStoreContext.AssertOutMessage( signedReceipt.MessageId, m => Assert.Equal(Operation.ToBePiggyBacked, m.Operation)); GetDataStoreContext.AssertOutMessage( unsignedReceipt.MessageId, m => Assert.Equal(Operation.Sending, m.Operation)); }
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"); }); }