예제 #1
0
        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);
            }));
        }
예제 #2
0
        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));
            }));
        }
예제 #3
0
        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");
            }));
        }
예제 #4
0
        public Property Saves_Bundled_MessageUnits_As_InMessages(MessagingContextMode mode)
        {
            return(Prop.ForAll(
                       GenMessageUnits().ToArbitrary(),
                       messageUnits =>
            {
                // Arrange
                AS4Message fixture = AS4Message.Create(messageUnits);
                var stub = new ReceivedMessage(Stream.Null, Constants.ContentTypes.Soap);
                var ctx = new MessagingContext(fixture, stub, mode);

                // Act
                Step.ExecuteAsync(ctx).GetAwaiter().GetResult();

                // Assert
                IEnumerable <InMessage> inserts =
                    GetDataStoreContext.GetInMessages(m => fixture.MessageIds.Contains(m.EbmsMessageId));

                IEnumerable <string> expected = fixture.MessageIds.OrderBy(x => x);
                IEnumerable <string> actual = inserts.Select(i => i.EbmsMessageId).OrderBy(x => x);
                Assert.True(
                    expected.SequenceEqual(actual),
                    $"{String.Join(", ", expected)} != {String.Join(", ", actual)}");

                Assert.All(
                    inserts, m =>
                {
                    bool pushForNonPullReceive = m.MEP == MessageExchangePattern.Push && mode != MessagingContextMode.PullReceive;
                    bool pullForPullReceive = m.MEP == MessageExchangePattern.Pull && mode == MessagingContextMode.PullReceive;

                    Assert.True(
                        pushForNonPullReceive || pullForPullReceive,
                        mode == MessagingContextMode.PullReceive
                                    ? "MEP Binding should be Pull"
                                    : "MEP Binding should be Push");
                });
            }));
        }