public void TestReceiveSmallMessages_Debatch50_XML() { //Setting up the ILogger moq var loggerMock = TestMockReceiveStep.CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockRequestResponseStep step = new MockRequestResponseStep(); step.Url = connectionUri.Uri.OriginalString; step.Encoding = "UTF-8"; step.ResponsePath = "TestResponse.xml"; step.Timeout = 30; step.DebatchedMessageCount = 50; //Calling Validate in order to start the step.Validate(context); //Setting up a manual reset event System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false); //here we queue up the step.Execute method in a separate thread as the execution model would actually be System.Threading.ThreadPool.QueueUserWorkItem((state) => { step.Execute(context); manualEvent.Set(); }); var responseMessageList = new List <Message>(3); string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; for (int i = 0; i < 50; i++) { Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8); msg.Properties.Add("http://schemas.microsoft.com/BizTalk/2003/system-properties#IsSolicitResponse", true); var responseMsg = outboundHandler.Execute(msg, TimeSpan.FromSeconds(10)); responseMessageList.Add(responseMsg); } //Waiting for the manual event to be set manualEvent.WaitOne(3000); //string expected = ReadResponseFileContent("TestResponse.xml").Trim().Replace("\r\n", string.Empty).Replace("\t", string.Empty); //string actual = GeneralTestHelper.GetBodyAsString(responseMsg, Encoding.UTF8).Trim().Replace("\r\n", string.Empty).Replace("\t", string.Empty); //Assert.AreEqual(expected, actual, // "Response message is not matching the expected content"); Assert.AreEqual(50, responseMessageList.Count, "The number of response messages is incorrect."); loggerMock.Verify(l => l.LogData( It.Is <string>(s => !string.IsNullOrEmpty(s)), It.Is <string>(s => !string.IsNullOrEmpty(s))), Times.Exactly(100), "The LogData method was not called"); }
public void TestReceiveSmallMessage_ResponseSelector_XML() { //Setting up the ILogger moq var loggerMock = TestMockReceiveStep.CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockRequestResponseStep step = new MockRequestResponseStep(); step.Url = connectionUri.Uri.OriginalString; step.Encoding = "UTF-8"; step.ResponseSelector = (request, index) => SelectStaticResponse(request, index); step.Timeout = 30; //Calling Validate in order to start the server step.Validate(context); //Setting up a manual reset event System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false); //here we queue up the step.Execute method in a separate thread as the execution model would actually be System.Threading.ThreadPool.QueueUserWorkItem((state) => { step.Execute(context); manualEvent.Set(); }); string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>"; Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8); msg.Properties.Add("http://schemas.microsoft.com/BizTalk/2003/system-properties#IsSolicitResponse", true); Message responseMsg = outboundHandler.Execute(msg, TimeSpan.FromSeconds(10)); //Waiting for the manual event to be set manualEvent.WaitOne(1000); loggerMock.Verify(l => l.LogData( It.Is <string>(s => !string.IsNullOrEmpty(s)), It.Is <string>(s => !string.IsNullOrEmpty(s))), Times.Exactly(2), "The LogData method was not called"); byte[] responseBytes = GeneralTestHelper.GetBodyAsBytes(responseMsg); Assert.AreEqual( GeneralTestHelper.CalculateFileHash("TestResponse.xml"), GeneralTestHelper.CalculateBytesHash(responseBytes), "The second response is not as expected"); }
public void TestValidateMethod_ValidStep() { var loggerMock = TestMockReceiveStep.CreateLoggerMock(); Context context = new Context(loggerMock.Object); MockRequestResponseStep step = new MockRequestResponseStep(); step.Url = connectionUri.Uri.OriginalString; step.Encoding = "UTF-8"; step.ResponsePath = "TestResponse.xml"; //Calling Validate in order to start the step.Validate(context); // Cleaning up the step step.Cleanup(); step = null; }