public void MessageBodyIsTracked()
        {
            var message = new MessageMock();

            message.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");

            var eventStream = new Mock <EventStream>();

            var pipelineContext = new Mock <IPipelineContext> {
                DefaultValue = DefaultValue.Mock
            };

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

            var sut = new MessagingStep(pipelineContext.Object, message.Object);

            using (var trackingStream = new TrackingStream(new MemoryStream(_content), new MessageBodyCaptureDescriptor("data", MessageBodyCaptureMode.Claimed)))
            {
                // TrackActivity is supposed to occur at stream's end
                trackingStream.Drain();
                sut.TrackActivity(ActivityTrackingModes.Body, trackingStream);
            }

            eventStream.Verify(
                es => es.AddReference(
                    MessagingStep.ActivityName,
                    sut.ActivityId,
                    MessageBodyCaptureMode.Claimed.ToString(),
                    MessagingStep.MESSAGE_BODY_REFERENCE_NAME,
                    It.IsAny <string>(),
                    It.IsAny <string>()),
                Times.Once());
        }
Example #2
0
 public override void AddStep(MessagingStep messagingStep)
 {
     // A ProcessReference denotes an ongoing *non* messaging-only process; whereas a MessagingStepReference denotes
     // the initiating message of a messaging-only flow...
     if (messagingStep is MessagingStepReference)
     {
         throw new NotSupportedException();
     }
     base.AddStep(messagingStep);
 }
        public void InboundSuccessfulPropertiesForSolicitResponsePortAreTracked()
        {
            var message = new MessageMock();

            SetupCommonProperties(message);
            // no ReceiveLocationName on the inbound of a solicit-response port but a ReceivePortName
            message.Setup(m => m.GetProperty(BtsProperties.ReceivePortName)).Returns("receive-port-name");
            message.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");
            message.Setup(m => m.GetProperty(BtsProperties.InboundTransportType)).Returns("inbound-transport-type");

            var activityId = string.Empty;
            Dictionary <string, object> data = null;
            var eventStream = new Mock <EventStream>();

            eventStream
            // ReSharper disable AccessToModifiedClosure
            .Setup(es => es.UpdateActivity(MessagingStep.ActivityName, It.Is <string>(id => id == activityId), It.IsAny <object[]>()))
            // ReSharper restore AccessToModifiedClosure
            .Callback <string, string, object[]>((n, id, d) => data = ToDictionary(d))
            .Verifiable();

            var pipelineContext = new Mock <IPipelineContext> {
                DefaultValue = DefaultValue.Mock
            };

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

            var sut = new MessagingStep(pipelineContext.Object, message.Object);

            activityId = sut.ActivityId;
            using (var trackingStream = new TrackingStream(new MemoryStream(_content)))
            {
                // TrackActivity is supposed to occur at stream's end
                trackingStream.Drain();
                sut.TrackActivity(ActivityTrackingModes.Step, trackingStream);
            }

            eventStream.Verify();

            var expectedData = new Dictionary <string, object> {
                { MessagingStep.MessageIDFieldName, _messageId.AsNormalizedActivityId() },
                { MessagingStep.MessageTypeFieldName, "message-type" },
                { MessagingStep.PortNameFieldName, "receive-port-name" },
                { MessagingStep.TransportLocationFieldName, "inbound-transport-location" },
                { MessagingStep.TransportTypeFieldName, "inbound-transport-type" },
                { MessagingStep.StatusFieldName, TrackingStatus.Received },
                { MessagingStep.MachineNameFieldName, Environment.MachineName },
                { MessagingStep.TimeFieldName, sut.Time }
            }
            .Union(ExpectedCommonData, new LambdaComparer <KeyValuePair <string, object> >((kvp1, kvp2) => kvp1.Key == kvp2.Key))
            .OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            Assert.That(data, Is.EquivalentTo(expectedData));
        }
        public void OutboundSuccessfulPropertiesAreTrackedAtStreamExhaustion()
        {
            var message = new MessageMock();

            SetupCommonProperties(message);
            SetupInboundSuccessfulProperties(message);
            SetupOutboundSuccessfulProperties(message);

            var activityId = string.Empty;
            Dictionary <string, object> data = null;
            var eventStream = new Mock <EventStream>();

            eventStream
            // ReSharper disable AccessToModifiedClosure
            .Setup(es => es.UpdateActivity(MessagingStep.ActivityName, It.Is <string>(id => id == activityId), It.IsAny <object[]>()))
            // ReSharper restore AccessToModifiedClosure
            .Callback <string, string, object[]>((n, id, d) => data = ToDictionary(d))
            .Verifiable();

            var pipelineContext = new Mock <IPipelineContext> {
                DefaultValue = DefaultValue.Mock
            };

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

            var sut = new MessagingStep(pipelineContext.Object, message.Object);

            activityId = sut.ActivityId;
            using (var trackingStream = new TrackingStream(new MemoryStream(_content)))
            {
                // TrackActivity is supposed to occur at stream's end
                trackingStream.Drain();
                sut.TrackActivity(ActivityTrackingModes.Step, trackingStream);
            }

            eventStream.Verify();

            var expectedData = new Dictionary <string, object> {
                { MessagingStep.MessageIDFieldName, _messageId.AsNormalizedActivityId() },
                { MessagingStep.PortNameFieldName, "send-port-name" },
                { MessagingStep.TransportLocationFieldName, "outbound-transport-location" },
                { MessagingStep.TransportTypeFieldName, "outbound-transport-type" },
                { MessagingStep.StatusFieldName, TrackingStatus.Sent },
                { MessagingStep.MachineNameFieldName, Environment.MachineName },
                { MessagingStep.TimeFieldName, sut.Time }
            }
            .Union(ExpectedCommonData)
            .OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            Assert.That(data, Is.EquivalentTo(expectedData));
            Assert.That(sut.MessageType, Is.EqualTo("message-type"));
        }
        public void OutboundFailedPropertiesAreTracked()
        {
            var message = new MessageMock();

            SetupCommonProperties(message);
            SetupInboundSuccessfulProperties(message);
            SetupOutboundSuccessfulProperties(message);
            SetupCommonFailedProperties(message);
            message.Setup(m => m.GetProperty(ErrorReportProperties.SendPortName)).Returns("failed-send-port-name");
            message.Setup(m => m.GetProperty(ErrorReportProperties.OutboundTransportLocation)).Returns("failed-outbound-transport-location");

            var activityId = string.Empty;
            Dictionary <string, object> data = null;
            var eventStream = new Mock <EventStream>();

            eventStream
            // ReSharper disable AccessToModifiedClosure
            .Setup(es => es.UpdateActivity(MessagingStep.ActivityName, It.Is <string>(id => id == activityId), It.IsAny <object[]>()))
            // ReSharper restore AccessToModifiedClosure
            .Callback <string, string, object[]>((n, id, d) => data = ToDictionary(d))
            .Verifiable();

            var pipelineContext = new Mock <IPipelineContext> {
                DefaultValue = DefaultValue.Mock
            };

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

            var sut = new MessagingStep(pipelineContext.Object, message.Object);

            activityId = sut.ActivityId;
            using (var trackingStream = new TrackingStream(new MemoryStream(_content)))
            {
                // TrackActivity is supposed to occur at stream's end
                trackingStream.Drain();
                sut.TrackActivity(ActivityTrackingModes.Step, trackingStream);
            }

            eventStream.Verify();

            var expectedData = new Dictionary <string, object> {
                { MessagingStep.TransportTypeFieldName, "outbound-transport-type" },
                { MessagingStep.PortNameFieldName, "failed-send-port-name" },
                { MessagingStep.TransportLocationFieldName, "failed-outbound-transport-location" }
            }
            .Union(ExpectedCommonFailedData, new LambdaComparer <KeyValuePair <string, object> >((kvp1, kvp2) => kvp1.Key == kvp2.Key))
            .Union(ExpectedCommonData, new LambdaComparer <KeyValuePair <string, object> >((kvp1, kvp2) => kvp1.Key == kvp2.Key))
            .OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            Assert.That(data, Is.EquivalentTo(expectedData));
            Assert.That(sut.MessageType, Is.EqualTo("failed-message-type"));
        }
        public void ActivityIsBegunAndActivityIdWrittenInMessageContext()
        {
            var eventStream     = new Mock <EventStream>();
            var pipelineContext = new Mock <IPipelineContext>();

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

            var message = new MessageMock();

            message.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");

            var sut        = new MessagingStep(pipelineContext.Object, message.Object);
            var activityId = sut.ActivityId;

            message.Verify(m => m.SetProperty(TrackingProperties.MessagingStepActivityId, activityId), Times.Once());
            eventStream.Verify(s => s.BeginActivity(MessagingStep.ActivityName, activityId), Times.Once());
        }
        public void MessagingStepIsAffiliatedToProcess()
        {
            Dictionary <string, object> data   = null;
            var processMessagingStepActivityId = string.Empty;
            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]))
            .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(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, messagingStepActivityId },
                // capture of Status is what distinguishes affiliation of a MessagingStep from affiliation of a MessagingStepReference
                { ProcessMessagingStep.MessagingStepStatusFieldName, TrackingStatus.FailedMessage },
                { ProcessMessagingStep.ProcessActivityIDFieldName, processActivityId }
            };

            Assert.That(data, Is.EquivalentTo(expectedData));
        }
        public void MessageContextIsTracked()
        {
            var ns   = BtsProperties.MessageType.Namespace;
            var name = BtsProperties.MessageType.Name;

            var message = new MessageMock();

            message.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");
            message.Setup(m => m.Context.CountProperties).Returns(1);
            message.Setup(m => m.Context.ReadAt(0, out name, out ns)).Returns("message-type");
            message.Setup(m => m.Context.IsPromoted(name, ns)).Returns(false);

            var eventStream = new Mock <EventStream>();

            var pipelineContext = new Mock <IPipelineContext> {
                DefaultValue = DefaultValue.Mock
            };

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

            var sut = new MessagingStep(pipelineContext.Object, message.Object);

            using (var trackingStream = new TrackingStream(new MemoryStream(_content)))
            {
                // TrackActivity is supposed to occur at stream's end
                trackingStream.Drain();
                sut.TrackActivity(ActivityTrackingModes.Context, trackingStream);
            }

            eventStream.Verify(
                es => es.AddReference(
                    MessagingStep.ActivityName,
                    sut.ActivityId,
                    MessagingStep.MESSAGE_CONTEXT_REFERENCE_TYPE,
                    MessagingStep.MESSAGE_CONTEXT_REFERENCE_NAME,
                    It.IsAny <string>(),
                    message.Object.Context.ToXml()),
                Times.Once());
        }
        public void ActivityIsCommittedAndEnded()
        {
            var eventStream     = new Mock <EventStream>();
            var pipelineContext = new Mock <IPipelineContext>();

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

            var message = new MessageMock();

            message.Setup(m => m.GetProperty(BtsProperties.InboundTransportLocation)).Returns("inbound-transport-location");

            var sut = new MessagingStep(pipelineContext.Object, message.Object);

            using (var trackingStream = new TrackingStream(new MemoryStream(_content)))
            {
                // TrackActivity is supposed to occur at stream's end
                trackingStream.Drain();
                sut.TrackActivity(ActivityTrackingModes.Step, trackingStream);
            }

            eventStream.Verify(s => s.UpdateActivity(MessagingStep.ActivityName, sut.ActivityId, It.IsAny <object[]>()), Times.Once());
            eventStream.Verify(s => s.Flush(), Times.Once());
            eventStream.Verify(s => s.EndActivity(MessagingStep.ActivityName, sut.ActivityId), Times.Once());
        }
Example #10
0
        public virtual void AddStep(MessagingStep messagingStep)
        {
            if (messagingStep == null)
            {
                throw new ArgumentNullException("messagingStep");
            }

            var processMessagingStep = new ProcessMessagingStep(Tracking.ActivityId.NewActivityId(), _eventStream);

            processMessagingStep.BeginProcessMessagingStepActivity();
            processMessagingStep.MessagingStepActivityID = messagingStep.ActivityId;
            // A MessagingStepReference denotes the initiating message of a messaging-only flow. Adding this step to a
            // process will only occur when we are tracking the outbound message of this messaging-only flow; it's
            // therefore too late to capture the initiating message status since the only message context at hand is the
            // one of the outgoing message.
            if (!(messagingStep is MessagingStepReference))
            {
                // don't bother to duplicate status other than failure
                processMessagingStep.MessagingStepStatus = messagingStep.Message.GetProperty(ErrorReportProperties.ErrorType);
            }
            processMessagingStep.ProcessActivityID = ActivityId;
            processMessagingStep.CommitProcessMessagingStepActivity();
            processMessagingStep.EndProcessMessagingStepActivity();
        }
Example #11
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 override void AddStep(MessagingStep messagingStep)
 {
     throw new NotSupportedException();
 }