public void CaptureMessageBody() { var trackingStream = new TrackingStream(FakeTextStream.Create(1024 * 1024)); var messageMock = new Unit.Message.Mock <IBaseMessage> { DefaultValue = DefaultValue.Mock }; messageMock.Object.BodyPart.Data = trackingStream; SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_IN_DIRECTORY_PROPERTY_NAME)) .Returns(Path.GetTempPath()); SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_OUT_DIRECTORY_PROPERTY_NAME)) .Returns(@"\\network\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; Assert.That(captureDescriptor.CaptureMode, Is.EqualTo(MessageBodyCaptureMode.Claimed)); Assert.That(captureDescriptor.Data, Does.StartWith(DateTime.Today.ToString(@"yyyyMMdd\\"))); Assert.That(File.Exists(Path.Combine(Path.GetTempPath(), captureDescriptor.Data.Replace("\\", "") + ".trk")), Is.True); }
public void CaptureMessageBodyWillHaveMessageClaimed() { SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_IN_DIRECTORY_PROPERTY_NAME)) .Returns(Path.GetTempPath()); SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_OUT_DIRECTORY_PROPERTY_NAME)) .Returns(@"\\network\share"); var trackingStreamMock = new Mock <TrackingStream>(FakeTextStream.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 <Stream>()), Times.Once()); }
public void CompressAboveThreshold() { using (var stream = FakeTextStream.Create(1024 * 100)) { string encoded; Assert.That(stream.TryCompressToBase64String(16, out encoded), Is.False); } }
public void ValidateCompressedData() { using (var clearStream = FakeTextStream.Create(1024 * 64)) using (var compressedStream = new ZipOutputStream(clearStream, "entry-name")) using (var validator = new ZipFile(new ReadOnlySeekableStream(compressedStream))) { validator.TestArchive(true, TestStrategy.FindFirstError, null); } }
public void ZipUnzipLargePayloadUsingSmallBuffer() { using (var memoryStream = new MemoryStream()) using (var clearStream = new ReplicatingReadStream(FakeTextStream.Create(1024 * 64), memoryStream)) using (var compressedStream = new ZipOutputStream(clearStream, "entry-name", 256)) using (var uncompressedStream = new ZipInputStream(compressedStream)) { uncompressedStream.GetNextEntry(); using (var reader = new StreamReader(uncompressedStream)) { Assert.That(reader.ReadToEnd(), Is.EqualTo(Encoding.UTF8.GetString(memoryStream.ToArray()))); } } }
public void CaptureMessageBodyWillHaveMessageClaimedButSsoApplicationDoesNotExist() { // setup a mock's 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 SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_IN_DIRECTORY_PROPERTY_NAME)) .Callback(() => _ssoSettingsReaderInstance.ReadString("NONEXISTENT_APPLICATION", BizTalkFactorySettings.CLAIM_STORE_CHECK_IN_DIRECTORY_PROPERTY_NAME)) .Returns(Path.GetTempPath()); var trackingStreamMock = new Mock <TrackingStream>(FakeTextStream.Create(1024 * 1024)) { CallBase = true }; Assert.That( () => ClaimStore.Instance.SetupMessageBodyCapture(trackingStreamMock.Object, ActivityTrackingModes.Claim, null), Throws.TypeOf <COMException>().With.Message.EqualTo("The application does not exist.\r\n")); }
public void CaptureMessageBodyWillHaveMessageUnclaimed() { var trackingStreamMock = new Mock <TrackingStream>(FakeTextStream.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 <Stream>()), Times.Never()); trackingStreamMock.Verify( ts => ts.SetupCapture(It.Is <MessageBodyCaptureDescriptor>(cd => cd.CaptureMode == MessageBodyCaptureMode.Unclaimed), It.IsAny <Stream>()), Times.Never()); }
public void ClaimMessageBody() { SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_IN_DIRECTORY_PROPERTY_NAME)) .Returns(Path.GetTempPath()); SsoSettingsReaderMock .Setup(ssr => ssr.ReadString(BizTalkFactorySettings.APPLICATION_NAME, BizTalkFactorySettings.CLAIM_STORE_CHECK_OUT_DIRECTORY_PROPERTY_NAME)) .Returns(@"\\network\share"); using (var contentStream = FakeTextStream.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) Assert.That(contentStream.Position, Is.EqualTo(contentStream.Length)); // message's body stream is replaced by a token message using (var reader = new StreamReader(MessageMock.Object.BodyPart.Data)) { Assert.That(reader.ReadToEnd(), Is.EqualTo(MessageFactory.CreateClaimCheckIn(trackingStream.CaptureDescriptor.Data).OuterXml)); } // MessageType of token message is promoted in message context var schemaMetadata = typeof(Claim.CheckIn).GetMetadata(); 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; Assert.That(captureDescriptor.CaptureMode, Is.EqualTo(MessageBodyCaptureMode.Claimed)); Assert.That(captureDescriptor.Data, Does.StartWith(DateTime.Today.ToString(@"yyyyMMdd\\"))); Assert.That(File.Exists(Path.Combine(Path.GetTempPath(), captureDescriptor.Data.Replace("\\", "") + ".chk")), Is.True); } }