public void CaptureMessageBodyWillHaveMessageClaimed()
        {
            using (var configurationReaderMockInjectionScope = new SsoConfigurationReaderMockInjectionScope())
            {
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckInDirectory)))
                .Returns(Path.GetTempPath());
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckOutDirectory)))
                .Returns(@"\\server\share");

                var trackingStreamMock = new Mock <TrackingStream>(TextStreamDummy.Create(1024 * 1024))
                {
                    CallBase = true
                };

                ClaimStore.Instance.SetupMessageBodyCapture(trackingStreamMock.Object, ActivityTrackingModes.Body, null);

                trackingStreamMock.Verify(
                    ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Claimed)),
                    Times.Never());
                trackingStreamMock.Verify(
                    ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Unclaimed)),
                    Times.Never());
                trackingStreamMock.Verify(
                    ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Claimed), It.IsAny <System.IO.Stream>()),
                    Times.Once());
            }
        }
        public void CaptureMessageBody()
        {
            var trackingStream = new TrackingStream(TextStreamDummy.Create(1024 * 1024));

            var messageMock = new Unit.Message.Mock <IBaseMessage> {
                DefaultValue = DefaultValue.Mock
            };

            messageMock.Object.BodyPart.Data = trackingStream;

            using (var configurationReaderMockInjectionScope = new SsoConfigurationReaderMockInjectionScope())
            {
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckInDirectory)))
                .Returns(Path.GetTempPath());
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckOutDirectory)))
                .Returns(@"\\server\share");

                ClaimStore.Instance.SetupMessageBodyCapture(trackingStream, ActivityTrackingModes.Body, null);

                messageMock.Object.BodyPart.Data.Drain();

                // payload is claimed to disk and file extension is .trk
                var captureDescriptor = trackingStream.CaptureDescriptor;
                captureDescriptor.CaptureMode.Should().Be(MessageBodyCaptureMode.Claimed);
                captureDescriptor.Data.Should().StartWith(DateTime.Today.ToString(@"yyyyMMdd\\"));
                File.Exists(Path.Combine(Path.GetTempPath(), captureDescriptor.Data.Replace("\\", "") + ".trk")).Should().BeTrue();
            }
        }
コード例 #3
0
 public void CompressAboveThreshold()
 {
     using (var stream = TextStreamDummy.Create(1024 * 120))
     {
         stream.TryCompressToBase64String(16, out _).Should().BeFalse();
     }
 }
コード例 #4
0
        public void CaptureMessageBodyWillHaveMessageClaimed()
        {
            using (var configurationReaderMockInjectionScope = new SsoConfigurationReaderMockInjectionScope())
            {
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_IN_DIRECTORY_PROPERTY_NAME))
                .Returns(Path.GetTempPath());
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_OUT_DIRECTORY_PROPERTY_NAME))
                .Returns(@"\\server\share");

                var trackingStreamMock = new Mock <TrackingStream>(TextStreamDummy.Create(1024 * 1024))
                {
                    CallBase = true
                };

                ClaimStore.Instance.SetupMessageBodyCapture(trackingStreamMock.Object, ActivityTrackingModes.Body, null);

                trackingStreamMock.Verify(
                    ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Claimed)),
                    Times.Never());
                trackingStreamMock.Verify(
                    ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Unclaimed)),
                    Times.Never());
                trackingStreamMock.Verify(
                    ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Claimed), It.IsAny <System.IO.Stream>()),
                    Times.Once());
            }
        }
 public void ValidateCompressedData()
 {
     using (var clearStream = TextStreamDummy.Create(1024 * 64))
         using (var compressedStream = new ZipOutputStream(clearStream, "entry-name"))
         {
             compressedStream.IsValidZipArchive().Should().BeTrue();
         }
 }
 public void ZipUnzipLargePayloadUsingSmallBuffer()
 {
     using (var memoryStream = new MemoryStream())
         using (var clearStream = new ReplicatingReadStream(TextStreamDummy.Create(1024 * 64), memoryStream))
             using (var compressedStream = new ZipOutputStream(clearStream, "entry-name", 256))
                 using (var decompressedStream = new ZipInputStream(compressedStream))
                 {
                     using (var reader = new StreamReader(decompressedStream))
                     {
                         var output = reader.ReadToEnd();
                         output.Should().Be(Encoding.UTF8.GetString(memoryStream.ToArray()));
                     }
                 }
 }
        public void CaptureMessageBodyWillHaveMessageUnclaimed()
        {
            var trackingStreamMock = new Mock <TrackingStream>(TextStreamDummy.Create(1024))
            {
                CallBase = true
            };

            ClaimStore.Instance.SetupMessageBodyCapture(trackingStreamMock.Object, ActivityTrackingModes.Claim, null);

            trackingStreamMock.Verify(
                ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Unclaimed)),
                Times.Once());
            trackingStreamMock.Verify(
                ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Claimed), It.IsAny <System.IO.Stream>()),
                Times.Never());
            trackingStreamMock.Verify(
                ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Unclaimed), It.IsAny <System.IO.Stream>()),
                Times.Never());
        }
        public void ClaimMessageBody()
        {
            using (var configurationReaderMockInjectionScope = new SsoConfigurationReaderMockInjectionScope())
            {
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckInDirectory)))
                .Returns(Path.GetTempPath());
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckOutDirectory)))
                .Returns(@"\\server\share");

                using (var contentStream = TextStreamDummy.Create(1024 * 1024))
                    using (var trackingStream = new TrackingStream(contentStream))
                    {
                        MessageMock.Object.BodyPart.Data = trackingStream;

                        ClaimStore.Instance.SetupMessageBodyCapture(trackingStream, ActivityTrackingModes.Claim, null);
                        ClaimStore.Instance.Claim(MessageMock.Object, ResourceTrackerMock.Object);

                        // message's actual body stream has been exhausted (i.e. saved to disk)
                        contentStream.Position.Should().Be(contentStream.Length);

                        // message's body stream is replaced by a token message
                        using (var reader = new StreamReader(MessageMock.Object.BodyPart.Data))
                        {
                            reader.ReadToEnd().Should().Be(ClaimFactory.CreateCheckIn(trackingStream.CaptureDescriptor.Data).OuterXml);
                        }

                        // MessageType of token message is promoted in message context
                        var schemaMetadata = SchemaMetadata.For <Claim.CheckIn>();
                        MessageMock.Verify(m => m.Promote(BtsProperties.MessageType, schemaMetadata.MessageType), Times.Once());
                        MessageMock.Verify(m => m.Promote(BtsProperties.SchemaStrongName, schemaMetadata.DocumentSpec.DocSpecStrongName), Times.Once());

                        // payload is claimed to disk and file extension is .chk
                        var captureDescriptor = trackingStream.CaptureDescriptor;
                        captureDescriptor.CaptureMode.Should().Be(MessageBodyCaptureMode.Claimed);
                        captureDescriptor.Data.Should().StartWith(DateTime.Today.ToString(@"yyyyMMdd\\"));
                        File.Exists(Path.Combine(Path.GetTempPath(), captureDescriptor.Data.Replace("\\", "") + ".chk")).Should().BeTrue();
                    }
            }
        }
        public void CaptureMessageBodyWillHaveMessageClaimedButSsoApplicationDoesNotExist()
        {
            Skip.IfNot(BizTalkServerGroup.IsConfigured);

            var actualSsoConfigurationReader = SsoConfigurationReader.Instance;

            // setup a mock callback to ensure that, even if the BizTalk.Factory SSO store is deployed, the call will look for an SSO store that does not exist
            using (var configurationReaderMockInjectionScope = new SsoConfigurationReaderMockInjectionScope())
            {
                configurationReaderMockInjectionScope.Mock
                .Setup(ssr => ssr.Read(ClaimStoreSsoSettings.AFFILIATE_APPLICATION_NAME, nameof(ClaimStoreSsoSettings.ClaimStoreCheckInDirectory)))
                .Callback(() => actualSsoConfigurationReader.Read("NONEXISTENT_APPLICATION", nameof(ClaimStoreSsoSettings.ClaimStoreCheckInDirectory)))
                .Returns(Path.GetTempPath());

                var trackingStreamMock = new Mock <TrackingStream>(TextStreamDummy.Create(1024 * 1024))
                {
                    CallBase = true
                };

                Invoking(() => ClaimStore.Instance.SetupMessageBodyCapture(trackingStreamMock.Object, ActivityTrackingModes.Claim, null))
                .Should().Throw <InvalidOperationException>()
                .WithMessage("AffiliateApplication 'NONEXISTENT_APPLICATION' does not exist.");
            }
        }