public void TestHappyPath_OneWay()
        {
            var testCase = new BizUnit.Core.TestBuilder.TestCase();

            var inMsgStep = new MockSendStep()
            {
                Url         = "mock://localhost/BTS.OneWayReceive_FILE",
                RequestPath = "StartMessage.xml",
                Encoding    = "UTF-8"
            };

            testCase.ExecutionSteps.Add(inMsgStep);

            var outMsgStep = new MockReceiveStep()
            {
                Url      = "mock://localhost/DynamicPortOut",
                Encoding = "UTF-8",
                Timeout  = 10
            };

            testCase.ExecutionSteps.Add(outMsgStep);

            BizUnit.Core.TestRunner testRunner = new BizUnit.Core.TestRunner(testCase);

            testRunner.Run();
        }
        public void TestHappyPath_OneWay_HelperClass()
        {
            var testCase = new BizUnit.Core.TestBuilder.TestCase();

            var inMsgStep = new MockSendStep()
            {
                Url         = BizTalkTests.Test.BizTalkTestsMockAddresses.BTS_OneWayReceive_FILE,
                RequestPath = "StartMessage.xml",
                Encoding    = "UTF-8"
            };

            testCase.ExecutionSteps.Add(inMsgStep);

            var outMsgStep = new MockReceiveStep()
            {
                Url      = BizTalkTests.Test.BizTalkTestsMockAddresses.DynamicPortOut,
                Encoding = "UTF-8",
                Timeout  = 10
            };

            testCase.ExecutionSteps.Add(outMsgStep);

            BizUnit.Core.TestRunner testRunner = new BizUnit.Core.TestRunner(testCase);

            testRunner.Run();
        }
Beispiel #3
0
        public void TestOneWay_HappyPath()
        {
            var testCase = new BizUnit.Core.TestBuilder.TestCase();

            var inMsgStep = new MockSendStep()
            {
                Url         = BizTalkTestsMockAddresses.BTS_OneWayStaticReceive_FILE,
                RequestPath = "StartMessage.xml",
                Encoding    = "UTF-8"
            };

            testCase.ExecutionSteps.Add(inMsgStep);

            var outMsgStep = new MockReceiveStep()
            {
                Url      = BizTalkTestsMockAddresses.BTS_OneWaySendFILE,
                Encoding = "UTF-8",
                Timeout  = 10
            };

            var outMsgValidationStep = new TransMock.Integration.BizUnit.Validation.LambdaValidationStep()
            {
                MessageValidationCallback = (message) => ValidateOutMessage(message)
            };

            outMsgStep.SubSteps.Add(outMsgValidationStep);
            testCase.ExecutionSteps.Add(outMsgStep);

            BizUnit.Core.TestRunner testRunner = new BizUnit.Core.TestRunner(testCase);

            testRunner.Run();
        }
        public void TestReceiveSmallMessage_XML_LambdaValidation()
        {
            //Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            MockReceiveStep step = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            step.Timeout  = 10;

            string xml = @"<SomeTestMessage>
                <Element1 attribute1=""attributeValue"">
                </Element1>
                <Element2>Some element content</Element2>
            </SomeTestMessage>";

            // Calling Validate in order to start the pipe server
            step.Validate(context);

            // Setting up a manual reset event
            System.Threading.ManualResetEvent manualEvent = new System.Threading.ManualResetEvent(false);

            // Creating the validation step
            var validationStep = new LambdaValidationStep()
            {
                MessageValidationCallback = (m) =>
                {
                    Assert.AreEqual(xml, m.Body,
                                    "Validation of received message failed");

                    return(true);
                }
            };

            step.SubSteps.Add(validationStep);
            // 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();
            });

            Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8);

            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.AtLeastOnce(), "The LogData message was not called");
        }
        public void TestReceiveSmallMessages_Debatch2_Expect3_XML()
        {
            //Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            MockReceiveStep step = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            step.Timeout  = 1;
            step.DebatchedMessageCount = 3;
            //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

            bool timeoutExceptionThrown = false;

            System.Threading.ThreadPool.QueueUserWorkItem((state) =>
            {
                try
                {
                    step.Execute(context);
                    manualEvent.Set();
                }
                catch (TimeoutException)
                {
                    timeoutExceptionThrown = true;
                }
            });

            string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>";

            for (int i = 0; i < 2; i++)
            {
                Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8);

                outboundHandler.Execute(msg, TimeSpan.FromSeconds(10));
            }

            // Waiting for the manual event to be set
            // The wait time is slightly longer than the step's timeout in order to
            // to be able to capture the TimeoutException correctly
            manualEvent.WaitOne(2000);

            Assert.IsTrue(timeoutExceptionThrown, "The expected exception was not thrown");

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s)),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s))),
                              Times.Exactly(2), "The LogData message was not called");
        }
        public void TestReceiveSmallMessages_Debatch3_SerialValidationSingleStep_XML()
        {
            // Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            BizUnit.
            MockReceiveStep step = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            step.Timeout  = 30;
            step.DebatchedMessageCount = 3;

            // Setting up a validation step mock
            var validationStepMock = CreateSubStepMock();

            step.SubSteps.Add(validationStepMock.Object);

            // 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();
            });

            string xml = "<SomeTestMessage><Element1 attribute1=\"attributeValue\"></Element1><Element2>Some element content</Element2></SomeTestMessage>";

            for (int i = 0; i < 3; i++)
            {
                Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(xml, Encoding.UTF8);

                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.AtLeastOnce(), "The LogData message was not called");

            validationStepMock.Verify(vs => vs.Execute(
                                          It.Is <Stream>(s => s != null),
                                          It.Is <Context>(c => c != null)),
                                      Times.Exactly(3),
                                      "The SubStep mock was not called the expected number of times");
        }
        public void TestValidateMethod_ValidStep()
        {
            var loggerMock = CreateLoggerMock();

            Context         context = new Context(loggerMock.Object);
            MockReceiveStep step    = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            //Colling Validate in order to start the
            step.Validate(context);
            //Cleaning up the step
            step.Cleanup();
        }
        public void TestOneWay_XML()
        {
            //Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            MockSendStep sendDtep = new MockSendStep()
            {
                Url         = "mock://localhost/OneWayReceive",
                RequestPath = "TestRequest.xml",
                Encoding    = "UTF-8",
                Timeout     = 30
            };

            //Validated the step
            sendDtep.Validate(context);
            //Executing the step
            sendDtep.Execute(context);

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s) &&
                                                 s == "Reading request content from path TestRequest.xml"),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s) &&
                                                 s == File.ReadAllText("TestRequest.xml"))),
                              Times.AtLeastOnce(),
                              "The LogData message was not called");

            //Now we receive the message
            MockReceiveStep receiveStep = new MockReceiveStep()
            {
                Url      = "mock://localhost/OneWaySend",
                Encoding = "UTF-8"
            };

            // Calling Validate to start the receive server
            receiveStep.Validate(context);

            // Executing the step
            receiveStep.Execute(context);

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s) &&
                                                 s == "MockReceiveStep received a message with content"),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s) &&
                                                 s == File.ReadAllText("TestRequest.xml"))),
                              Times.AtLeastOnce(),
                              "The LogData message was not called");
        }
        public void TestReceiveSmallMessages_Debatch50_XML()
        {
            //Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            MockReceiveStep step = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            step.Timeout  = 10;
            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();
            });

            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);

                outboundHandler.Execute(msg, TimeSpan.FromSeconds(10));
            }

            //Waiting for the manual event to be set
            if (!manualEvent.WaitOne(1000))
            {
                manualEvent.WaitOne(5000);
            }

            loggerMock.Verify(l => l.LogData(
                                  It.Is <string>(s => !string.IsNullOrEmpty(s)),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s))),
                              Times.Exactly(50),
                              "The LogData method was not called");
        }
        public void TestReceiveSmallMessage_FlatFile()
        {
            //Setting up the ILogger moq
            var loggerMock = CreateLoggerMock();

            Context context = new Context(loggerMock.Object);

            MockReceiveStep step = new MockReceiveStep();

            step.Url      = connectionUri.Uri.OriginalString;
            step.Encoding = "UTF-8";
            step.Timeout  = 30;
            //Colling 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();
            });

            string ffContent = "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;";

            Message msg = GeneralTestHelper.CreateMessageWithBase64EncodedBody(ffContent, Encoding.UTF8);

            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) &&
                                                 s == "MockReceiveStep received a message with content"),
                                  It.Is <string>(s => !string.IsNullOrEmpty(s) &&
                                                 s == "303330123333777;ABCD;00001;00002;2014-01-15;21:21:33.444;EFGH;")),
                              Times.AtLeastOnce(),
                              "The LogData method was not called");
        }
Beispiel #11
0
        public void TestOneWay_InboundMessageProperties_HappyPath()
        {
            var testCase = new BizUnit.Core.TestBuilder.TestCase();

            var inMsgStep = new MockSendStep()
            {
                Url         = BizTalkTestsOldMockAddresses.BTS_OneWayReceive2_FILE.ToString(),
                RequestPath = "StartMessage.xml",
                Encoding    = "UTF-8"
            };

            inMsgStep.MessageProperties
            .Add(
                TransMock.Wcf.Adapter.Utils.BizTalkProperties.BTS.Operation,
                "SomeTestOperation");

            testCase.ExecutionSteps.Add(inMsgStep);

            var outMsgStep = new MockReceiveStep()
            {
                Url      = BizTalkTestsOldMockAddresses.BTS_OneWaySendFILE.ToString(),
                Encoding = "UTF-8",
                Timeout  = 10
            };

            var outMsgValidationStep = new TransMock.Integration.BizUnit.Validation.LambdaValidationStep()
            {
                MessageValidationCallback = (message) => ValidateOutMessage(message)
            };

            outMsgStep.SubSteps.Add(outMsgValidationStep);
            testCase.ExecutionSteps.Add(outMsgStep);

            BizUnit.Core.TestRunner testRunner = new BizUnit.Core.TestRunner(testCase);

            testRunner.Run();
        }