public void FindProcessAndCreateMessagingStepBeforeStreamFirstReadEvent()
        {
            var trackingContext = new TrackingContext {
                ProcessActivityId = ActivityId.NewActivityId(),
            };

            using (var stream = new TrackingStream(new StringStream("some-content")))
            {
                MessageMock.Object.BodyPart.Data = stream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
                MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(trackingContext.ProcessActivityId);
                MessageMock.Setup(m => m.GetProperty(TrackingProperties.MessagingStepActivityId)).Returns(trackingContext.MessagingStepActivityId);

                var sut = ActivityTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Step));
                sut.TrackActivity();

                ActivityFactory.Verify(
                    af => af.CreateProcess(It.IsAny <IBaseMessage>(), It.IsAny <string>()),
                    Times.Never());
                ActivityFactory.Verify(
                    af => af.FindProcess(It.Is <TrackingContext>(c => c.ProcessActivityId == trackingContext.ProcessActivityId)),
                    Times.Once());
                ActivityFactory.Verify(
                    af => af.CreateMessagingStep(It.IsAny <IBaseMessage>()),
                    Times.Once());
                ActivityFactory.Verify(
                    af => af.FindMessagingStep(It.IsAny <TrackingContext>()),
                    Times.Never());
            }
        }
        public void TrackingContextIsCachedForSolicitResponseOutboundMessage()
        {
            var transmitWorkId = Guid.NewGuid().ToString();

            var trackingContext = new TrackingContext {
                ProcessActivityId        = ActivityId.NewActivityId(),
                ProcessingStepActivityId = ActivityId.NewActivityId(),
                MessagingStepActivityId  = ActivityId.NewActivityId()
            };

            MessageMock.Setup(m => m.GetProperty(BtsProperties.IsSolicitResponse)).Returns(true);
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
            MessageMock.Setup(m => m.GetProperty(BtsProperties.TransmitWorkId)).Returns(transmitWorkId);
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(trackingContext.ProcessActivityId);
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessingStepActivityId)).Returns(trackingContext.ProcessingStepActivityId);
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.MessagingStepActivityId)).Returns(trackingContext.MessagingStepActivityId);

            CacheMock.Setup(c => c.Set(transmitWorkId, trackingContext, 60 + 1));

            var sut = CreateActivityTracker();

            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

            CacheMock.VerifyAll();
        }
Exemplo n.º 3
0
        public void ControlReleaseSkippedWhenBatchIsDisabled()
        {
            // register the batch again so as to disable it
            BatchAdapter.RegisterBatch(_envelopeSpecName, null, false, 3);

            BatchAdapter.AddPart(_envelopeSpecName, null, ActivityId.NewActivityId(), "<data>some-value</data>");
            BatchAdapter.CreateReleaseMessage(_envelopeSpecName, null).DropToFolder(DropFolders.INPUT_FOLDER, "release_batch.xml");

            // batch controlled release process
            var process = TrackingRepository.SingleProcess(
                p => p.Name == Factory.Areas.Batch.Processes.Release &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed);

            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.ReceiveLocation <UnitTestInputMessageReceiveLocation>().Name &&
                s.MessageType == new SchemaMetadata <Schemas.Xml.Batch.Release>().MessageType &&
                s.Status == TrackingStatus.Received &&
                _envelopeSpecName.StartsWith(s.Value1));
            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.SendPort <BatchQueueControlledReleaseSendPort>().Name &&
                s.MessageType == new SchemaMetadata <Schemas.Xml.Batch.Release>().MessageType &&
                s.Status == TrackingStatus.Sent &&
                _envelopeSpecName.StartsWith(s.Value1));

            Assert.That(BatchAdapter.QueuedControlledReleases.Count(), Is.EqualTo(0));
        }
        public void MessagingStepReferenceIsAffiliatedToProcess()
        {
            Dictionary <string, object> data   = null;
            var processMessagingStepActivityId = string.Empty;
            var eventStream = new Mock <EventStream>();

            eventStream
            .Setup(e => e.BeginActivity(nameof(ProcessMessagingStep), It.IsAny <string>()))
            .Callback <string, string>((n, i) => processMessagingStepActivityId = i);
            eventStream
            .Setup(es => es.UpdateActivity(nameof(ProcessMessagingStep), It.Is <string>(id => id == processMessagingStepActivityId), It.IsAny <object[]>()))
            .Callback <string, string, object[]>((n, id, d) => data = Enumerable.Range(0, d.Length / 2).ToDictionary(i => (string)d[i * 2], i => d[i * 2 + 1]))
            .Verifiable();

            var processActivityId       = ActivityId.NewActivityId();
            var messagingStepActivityId = ActivityId.NewActivityId();

            var sut = new Process(processActivityId, eventStream.Object);

            sut.AddStep(new MessagingStepReference(messagingStepActivityId, eventStream.Object));

            eventStream.Verify();
            eventStream.Verify(s => s.BeginActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId), Times.Once());
            eventStream.Verify(s => s.UpdateActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId, It.IsAny <object[]>()), Times.Once());
            eventStream.Verify(s => s.Flush(), Times.Once());
            eventStream.Verify(s => s.EndActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId), Times.Once());

            var expectedData = new Dictionary <string, object> {
                { nameof(ProcessMessagingStep.MessagingStepActivityID), messagingStepActivityId },
                { nameof(ProcessMessagingStep.ProcessActivityID), processActivityId }
            };

            data.Should().BeEquivalentTo(expectedData);
        }
Exemplo n.º 5
0
        public void TrackActivityWithAmbientProcessActivity()
        {
            var batchTrackingContext = new BatchTrackingContext {
                MessagingStepActivityIdList = new[] { ActivityId.NewActivityId(), ActivityId.NewActivityId(), ActivityId.NewActivityId() },
                ProcessActivityId           = ActivityId.NewActivityId()
            };

            var sut = BatchReleaseProcessActivityTracker.Create(PipelineContextMock.Object, MessageMock.Object);

            sut.TrackActivity(batchTrackingContext);

            ActivityFactory.Verify(af => af.CreateProcess(It.IsAny <IBaseMessage>(), It.IsAny <string>()), Times.Never());
            // ReSharper disable once ImplicitlyCapturedClosure
            ActivityFactory.Verify(af => af.FindProcess(batchTrackingContext.ProcessActivityId), Times.Once());

            ProcessMock.Verify(p => p.TrackActivity(), Times.Once());
            ProcessMock.Verify(
                p =>
                p.AddSteps(
                    It.Is <IEnumerable <string> >(
                        list =>
                        list.SequenceEqual(
                            batchTrackingContext.MessagingStepActivityIdList
                            .Concat(new[] { MessageMock.Object.GetProperty(TrackingProperties.MessagingStepActivityId) })))),
                Times.Once());
        }
        public void TrackingContextIsRestoredForSolicitResponseInboundMessageUnlessNegativeCacheDuration()
        {
            var transmitWorkId = Guid.NewGuid().ToString();

            var trackingContext = new TrackingContext {
                ProcessActivityId        = ActivityId.NewActivityId(),
                ProcessingStepActivityId = ActivityId.NewActivityId(),
                MessagingStepActivityId  = ActivityId.NewActivityId()
            };

            MessageMock.Setup(m => m.GetProperty(BtsProperties.IsSolicitResponse)).Returns(true);
            MessageMock.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");
            MessageMock.Setup(m => m.GetProperty(BtsProperties.TransmitWorkId)).Returns(transmitWorkId);

            var sut = CreateActivityTracker();

            sut.TrackingContextCacheDuration = TimeSpan.FromSeconds(-1);

            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

            CacheMock.VerifyAll();

            // verifies that TrackingContext fields have been restored in message.Context
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.ProcessActivityId, trackingContext.ProcessActivityId), Times.Never());
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.ProcessingStepActivityId, trackingContext.ProcessingStepActivityId), Times.Never());
            MessageMock.Verify(m => m.SetProperty(TrackingProperties.MessagingStepActivityId, trackingContext.MessagingStepActivityId), Times.Never());
        }
Exemplo n.º 7
0
        public void BatchReleaseIsRuledBySpecificPartitionPolicy()
        {
            // insert parts for an envelope that does have a partition-specific release policy
            BatchAdapter.AddPart(_envelopeSpecName, "p-one", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "p-one", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");

            var sut = BatchAdapter.ReleasePolicies.Single();

            Assert.That(sut.EnvelopeId, Is.EqualTo(BatchAdapter.Envelopes.Single(e => e.SpecName == _envelopeSpecName).Id));
            Assert.That(sut.Partition, Is.EqualTo("p-one"));
            Assert.That(sut.Enabled, Is.False);
            Assert.That(sut.ReleaseOnItemCount, Is.EqualTo(7));
        }
Exemplo n.º 8
0
        public void ControlReleaseOneEnvelopeAndOnePartition()
        {
            BatchAdapter.AddPart(_envelopeSpecName, "partition-z", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.CreateReleaseMessage(_envelopeSpecName, "partition-z").DropToFolder(DropFolders.INPUT_FOLDER, "release_batch.xml");

            // batch controlled release process
            var process = TrackingRepository.SingleProcess(
                p => p.Name == Factory.Areas.Batch.Processes.Release &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "partition-z");

            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.ReceiveLocation <UnitTestInputMessageReceiveLocation>().Name &&
                s.MessageType == new SchemaMetadata <Schemas.Xml.Batch.Release>().MessageType &&
                s.Status == TrackingStatus.Received &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "partition-z");
            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.SendPort <BatchQueueControlledReleaseSendPort>().Name &&
                s.MessageType == new SchemaMetadata <Schemas.Xml.Batch.Release>().MessageType &&
                s.Status == TrackingStatus.Sent &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "partition-z");

            Assert.That(BatchAdapter.QueuedControlledReleases.Count(), Is.EqualTo(1));
            BatchReleasePort.Enable();

            // batch content handling process
            process = TrackingRepository.SingleProcess(
                p => p.Name == Default.Processes.Unidentified &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "partition-z");
            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.ReceiveLocation <BatchReceiveLocation>().Name
                // TODO && s.MessageType == new SchemaMetadata<BatchContent>().MessageType
                && s.Status == TrackingStatus.Received);
            var envelopeMessagingStep = process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.SendPort <UnitTestBatchReleaseSendPort>().Name &&
                s.Status == TrackingStatus.Sent &&
                s.MessageType == new SchemaMetadata <Envelope>().MessageType &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "partition-z");

            Assert.That(
                envelopeMessagingStep.Message.Body,
                Is.EqualTo("<ns0:Envelope xmlns:ns0=\"urn:schemas.stateless.be:biztalk:envelope:2013:07\"><data>some-partitioned-value</data></ns0:Envelope>"));
        }
Exemplo n.º 9
0
        public void ControlReleaseOneEnvelopeAndAllPartitions()
        {
            BatchAdapter.AddPart(_envelopeSpecName, null, ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "p-one", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "p-two", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "p-six", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");

            BatchAdapter.AddPart("e-one", null, ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart("e-one", "p-one", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart("e-one", "p-two", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");
            BatchAdapter.AddPart("e-one", "p-six", ActivityId.NewActivityId(), "<data>some-partitioned-value</data>");

            BatchAdapter.CreateReleaseMessage(_envelopeSpecName, "*").DropToFolder(DropFolders.INPUT_FOLDER, "release_batch.xml");

            // batch controlled release process
            var process = TrackingRepository.SingleProcess(
                p => p.Name == Factory.Areas.Batch.Processes.Release &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "*");

            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.ReceiveLocation <UnitTestInputMessageReceiveLocation>().Name &&
                s.MessageType == new SchemaMetadata <Schemas.Xml.Batch.Release>().MessageType &&
                s.Status == TrackingStatus.Received &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "*");
            process.SingleMessagingStep(
                s => s.Name == BizTalkFactoryApplication.SendPort <BatchQueueControlledReleaseSendPort>().Name &&
                s.MessageType == new SchemaMetadata <Schemas.Xml.Batch.Release>().MessageType &&
                s.Status == TrackingStatus.Sent &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "*");

            var queuedControlledReleases = BatchAdapter.QueuedControlledReleases.ToArray();

            Assert.That(
                queuedControlledReleases.Count(),
                Is.EqualTo(4));
            Assert.That(
                queuedControlledReleases.Select(qcr => qcr.EnvelopeId).Distinct().Single(),
                Is.EqualTo(BatchAdapter.Envelopes.Single(e => e.SpecName == _envelopeSpecName).Id));
            Assert.That(
                queuedControlledReleases.Select(qcr => qcr.Partition),
                Is.EquivalentTo(new[] { "0", "p-one", "p-two", "p-six" }));
        }
Exemplo n.º 10
0
        public void TrackActivityWhenBatchTrackingContextOnlyHasProcessActivityId()
        {
            var batchTrackingContext = new BatchTrackingContext {
                ProcessActivityId = ActivityId.NewActivityId()
            };

            var sut = BatchReleaseProcessActivityTracker.Create(PipelineContextMock.Object, MessageMock.Object);

            sut.TrackActivity(batchTrackingContext);

            ActivityFactory.Verify(af => af.CreateProcess(It.IsAny <IBaseMessage>(), It.IsAny <string>()), Times.Never());
            ActivityFactory.Verify(af => af.FindProcess(It.IsAny <string>()), Times.Never());

            ProcessMock.Verify(p => p.TrackActivity(), Times.Never());
            ProcessMock.Verify(p => p.AddSteps(It.IsAny <IEnumerable <string> >()), Times.Never());
        }
Exemplo n.º 11
0
        public void PollForAvailableBatchesWithItemCountSizeLimit()
        {
            // drop more items than twice the item count limit, which is 3, so as to release two batches
            for (var i = 0; i < 8; i++)
            {
                BatchAdapter.AddPart(_envelopeSpecName, "p-count-limit", ActivityId.NewActivityId(), string.Format("<data>count-limit-value-{0}</data>", i));
            }

            BatchReleasePort.Enable();

            // batch content handling processes
            var processesQuery = TrackingRepository.Processes.Where(
                p => p.Name == Default.Processes.Unidentified &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "p-count-limit");

            // 2 processes have been tracked as more items than twice the item count limit have been accumulated
            Assert.That(() => processesQuery.Count(), Is.EqualTo(2).After(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1)));
            var processes = processesQuery.ToArray();

            // ensure the 2 processes are issued from the same polling, thereby validating that all available batches are
            // released in one shot (i.e., in DEV, one within one second of the other, when polling every 5 seconds)
            Assert.That(processes[0].BeginTime, Is.EqualTo(processes[1].BeginTime).Within(TimeSpan.FromSeconds(1)));

            // each batch is made of 3 parts
            var envelopeMessage1 = processes[0].MessagingSteps.Single(
                s => s.Name == BizTalkFactoryApplication.SendPort <UnitTestBatchReleaseSendPort>().Name &&
                s.MessageType == new SchemaMetadata <Envelope>().MessageType &&
                s.Status == TrackingStatus.Sent &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "p-count-limit");

            Assert.That(Regex.Matches(envelopeMessage1.Message.Body, @"<data>count-limit-value-\d</data>").Count, Is.EqualTo(3));
            var envelopeMessage2 = processes[1].MessagingSteps.Single(
                s => s.Name == BizTalkFactoryApplication.SendPort <UnitTestBatchReleaseSendPort>().Name &&
                s.MessageType == new SchemaMetadata <Envelope>().MessageType &&
                s.Status == TrackingStatus.Sent &&
                _envelopeSpecName.StartsWith(s.Value1) &&
                s.Value3 == "p-count-limit");

            Assert.That(Regex.Matches(envelopeMessage2.Message.Body, @"<data>count-limit-value-\d</data>").Count, Is.EqualTo(3));

            // 2 parts have been left in the database
            Assert.That(BatchAdapter.Parts.Count(), Is.EqualTo(2));
        }
        public void MessagingStepIsAffiliatedToProcess()
        {
            Dictionary <string, object> data   = null;
            var processMessagingStepActivityId = string.Empty;
            var eventStream = new Mock <EventStream>();

            eventStream
            .Setup(e => e.BeginActivity(nameof(ProcessMessagingStep), It.IsAny <string>()))
            .Callback <string, string>((n, i) => processMessagingStepActivityId = i);
            eventStream
            .Setup(es => es.UpdateActivity(nameof(ProcessMessagingStep), It.Is <string>(id => id == processMessagingStepActivityId), It.IsAny <object[]>()))
            .Callback <string, string, object[]>((n, id, d) => data = Enumerable.Range(0, d.Length / 2).ToDictionary(i => (string)d[i * 2], i => d[i * 2 + 1]))
            .Verifiable();

            var pipelineContext = new Mock <IPipelineContext>();

            pipelineContext.Setup(pc => pc.GetEventStream()).Returns(eventStream.Object);

            var message = new Unit.Message.Mock <IBaseMessage>();

            message.Setup(m => m.GetProperty(ErrorReportProperties.ErrorType)).Returns(TrackingStatus.FailedMessage);

            var processActivityId = ActivityId.NewActivityId();
            var sut                     = new Process(processActivityId, eventStream.Object);
            var messagingStep           = new MessagingStep(pipelineContext.Object, message.Object);
            var messagingStepActivityId = messagingStep.ActivityId;

            sut.AddStep(messagingStep);

            eventStream.Verify();
            eventStream.Verify(s => s.BeginActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId), Times.Once());
            eventStream.Verify(s => s.UpdateActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId, It.IsAny <object[]>()), Times.Once());
            eventStream.Verify(s => s.Flush(), Times.Once());
            eventStream.Verify(s => s.EndActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId), Times.Once());

            var expectedData = new Dictionary <string, object> {
                { nameof(ProcessMessagingStep.MessagingStepActivityID), messagingStepActivityId },
                // capture of Status is what distinguishes affiliation of a MessagingStep from affiliation of a MessagingStepReference
                { nameof(ProcessMessagingStep.MessagingStepStatus), TrackingStatus.FailedMessage },
                { nameof(ProcessMessagingStep.ProcessActivityID), processActivityId }
            };

            data.Should().BeEquivalentTo(expectedData);
        }
Exemplo n.º 13
0
        public void TrackActivityWithoutAmbientProcessActivity()
        {
            var batchTrackingContext = new BatchTrackingContext {
                MessagingStepActivityIdList = new[] { ActivityId.NewActivityId(), ActivityId.NewActivityId(), ActivityId.NewActivityId() }
            };

            var sut = BatchReleaseProcessActivityTracker.Create(PipelineContextMock.Object, MessageMock.Object);

            sut.TrackActivity(batchTrackingContext);

            ActivityFactory.Verify(af => af.CreateProcess(MessageMock.Object, It.IsAny <string>()), Times.Once);
            ActivityFactory.Verify(af => af.FindProcess(It.IsAny <string>()), Times.Never);

            ProcessMock.Verify(p => p.TrackActivity(), Times.Once);
            ProcessMock.Verify(
                p => p.AddSteps(
                    It.Is <IEnumerable <string> >(
                        list => list.SequenceEqual(
                            batchTrackingContext.MessagingStepActivityIdList.Append(MessageMock.Object.GetProperty(TrackingProperties.MessagingStepActivityId))))),
                Times.Once);
        }
Exemplo n.º 14
0
        public void PollForAvailableBatchesToRelease()
        {
            // create three-item partitioned batches, so as to trigger an automatic release via polling receive-location
            BatchAdapter.AddPart(_envelopeSpecName, "one", ActivityId.NewActivityId(), "<data>some-one-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "one", ActivityId.NewActivityId(), "<data>some-one-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "one", ActivityId.NewActivityId(), "<data>some-one-partitioned-value</data>");

            BatchAdapter.AddPart(_envelopeSpecName, "two", ActivityId.NewActivityId(), "<data>some-two-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "two", ActivityId.NewActivityId(), "<data>some-two-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "two", ActivityId.NewActivityId(), "<data>some-two-partitioned-value</data>");

            BatchAdapter.AddPart(_envelopeSpecName, "six", ActivityId.NewActivityId(), "<data>some-six-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "six", ActivityId.NewActivityId(), "<data>some-six-partitioned-value</data>");
            BatchAdapter.AddPart(_envelopeSpecName, "six", ActivityId.NewActivityId(), "<data>some-six-partitioned-value</data>");

            BatchReleasePort.Enable();

            // batch content handling processes
            TrackingRepository.SingleProcess(
                p => p.Name == Default.Processes.Unidentified &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "one");
            TrackingRepository.SingleProcess(
                p => p.Name == Default.Processes.Unidentified &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "two");
            TrackingRepository.SingleProcess(
                p => p.Name == Default.Processes.Unidentified &&
                p.BeginTime > StartTime &&
                p.Status == TrackingStatus.Completed &&
                _envelopeSpecName.StartsWith(p.Value1) &&
                p.Value3 == "six");
        }
Exemplo n.º 15
0
        public void MessagingStepIsAffiliatedToProcess()
        {
            var processMessagingStepActivityId = string.Empty;
            Dictionary <string, object> data   = null;
            var eventStream = new Mock <EventStream>();

            eventStream
            .Setup(e => e.BeginActivity(ProcessMessagingStep.ActivityName, It.IsAny <string>()))
            .Callback <string, string>((n, i) => processMessagingStepActivityId = i);
            eventStream
            .Setup(es => es.UpdateActivity(ProcessMessagingStep.ActivityName, It.Is <string>(id => id == processMessagingStepActivityId), It.IsAny <object[]>()))
            .Callback <string, string, object[]>((n, id, d) => data = Enumerable.Range(0, d.Length / 2).ToDictionary(i => (string)d[i * 2], i => d[i * 2 + 1]));

            var pipelineContext = new Mock <IPipelineContext>();

            pipelineContext.Setup(pc => pc.GetEventStream()).Returns(eventStream.Object);
            var message       = new MessageMock();
            var messagingStep = new MessagingStep(pipelineContext.Object, message.Object);

            var processActivityId = ActivityId.NewActivityId();
            var sut = new ProcessReference(processActivityId, eventStream.Object);

            sut.AddStep(messagingStep);

            eventStream.Verify(s => s.BeginActivity(ProcessMessagingStep.ActivityName, processMessagingStepActivityId), Times.Once());
            eventStream.Verify(s => s.UpdateActivity(ProcessMessagingStep.ActivityName, processMessagingStepActivityId, It.IsAny <object[]>()), Times.Once());
            eventStream.Verify(s => s.Flush(), Times.Once());
            eventStream.Verify(s => s.EndActivity(ProcessMessagingStep.ActivityName, processMessagingStepActivityId), Times.Once());

            var expectedData = new Dictionary <string, object> {
                { ProcessMessagingStep.MessagingStepActivityIDFieldName, messagingStep.ActivityId },
                { ProcessMessagingStep.ProcessActivityIDFieldName, processActivityId }
            };

            Assert.That(data, Is.EquivalentTo(expectedData));
        }
        public void TrackingContextIsCachedForSolicitResponseOutboundMessageUnlessNegativeCacheDuration()
        {
            MessageMock.Setup(m => m.GetProperty(BtsProperties.IsSolicitResponse)).Returns(true);
            MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(ActivityId.NewActivityId());

            var sut = CreateActivityTracker();

            sut.TrackingContextCacheDuration = TimeSpan.FromSeconds(-1);

            sut.Execute(PipelineContextMock.Object, MessageMock.Object);

            CacheMock.VerifyAll();
        }
Exemplo n.º 17
0
        public void SetUp()
        {
            MessageMock = new Unit.Message.Mock <IBaseMessage>();
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.MessagingStepActivityId)).Returns(ActivityId.NewActivityId());

            PipelineContextMock = new Mock <IPipelineContext>();

            ProcessMock = new Mock <BatchReleaseProcess>("pseudo-process-activity-id", new Mock <EventStream>().Object);

            ActivityFactory = new Mock <IBatchProcessActivityFactory>();
            ActivityFactory.Setup(af => af.CreateProcess(It.IsAny <IBaseMessage>(), It.IsAny <string>())).Returns(ProcessMock.Object);
            ActivityFactory.Setup(af => af.FindProcess(It.IsAny <string>())).Returns(ProcessMock.Object);

            _activityFactoryFactory = PipelineContextExtensions.ActivityFactoryFactory;
            PipelineContextExtensions.ActivityFactoryFactory = pipelineContext => ActivityFactory.As <IActivityFactory>().Object;
        }
        public BatchReleaseProcessActivityTrackerFixture()
        {
            MessageMock = new();
            MessageMock.Setup(m => m.GetProperty(TrackingProperties.MessagingStepActivityId)).Returns(ActivityId.NewActivityId());

            PipelineContextMock = new();

            ProcessMock = new("pseudo-process-activity-id", new Mock <EventStream>().Object);

            ActivityFactory = new();
            ActivityFactory.Setup(af => af.CreateProcess(It.IsAny <IBaseMessage>(), It.IsAny <string>())).Returns(ProcessMock.Object);
            ActivityFactory.Setup(af => af.FindProcess(It.IsAny <string>())).Returns(ProcessMock.Object);

            _activityFactoryFactory = PipelineContextBatchActivityTrackingExtensions.ActivityFactoryFactory;
            PipelineContextBatchActivityTrackingExtensions.ActivityFactoryFactory = _ => ActivityFactory.Object;
        }
        public void CompleteTrackingOfOutboundMessageWithProcessAffiliationAfterStreamLastReadEvent()
        {
            using (var stream = new TrackingStream(new StringStream("some-content")))
            {
                MessageMock.Object.BodyPart.Data = stream;
                MessageMock.Setup(m => m.GetProperty(BtsProperties.OutboundTransportLocation)).Returns("outbound-transport-location");
                MessageMock.Setup(m => m.GetProperty(TrackingProperties.ProcessActivityId)).Returns(ActivityId.NewActivityId());

                var sut = ActivityTracker.Create(new MicroComponent.ActivityTracker.Context(PipelineContextMock.Object, MessageMock.Object, ActivityTrackingModes.Step));
                sut.TrackActivity();
                MessageMock.Object.BodyPart.Data.Drain();

                ProcessMock.Verify(
                    p => p.TrackActivity(),
                    Times.Never());
                InitiatingMessagingStepMock.Verify(
                    ms => ms.TrackActivity(It.IsAny <ActivityTrackingModes>(), It.IsAny <TrackingStream>()),
                    Times.Never());
                ProcessMock.Verify(
                    p => p.AddStep(InitiatingMessagingStepMock.Object),
                    Times.Never());
                MessagingStepMock.Verify(
                    ms => ms.TrackActivity(It.IsAny <ActivityTrackingModes>(), It.IsAny <TrackingStream>()),
                    Times.Once());
                ProcessMock.Verify(
                    p => p.AddStep(MessagingStepMock.Object),
                    Times.Once());
            }
        }