public void SetupResponseExpectationAgainstInvoking()
        {
            _soapStub.As <IWork>()
            .Setup(s => s.Perform(It.IsAny <System.ServiceModel.Channels.Message>()))
            .Returns(new StringStream("<response />"));

            var client = SoapClient <IWork> .For(_soapStubHost.Endpoint);

            try
            {
                var result = client.Perform(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:perform:request",
                        XmlReader.Create(new StringReader("<request />"))));

                var reader = result.GetReaderAtBodyContents();
                reader.MoveToContent();
                var outerXml = reader.ReadOuterXml();
                outerXml.Should().Be("<response />");

                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
        public void SetupResponseExpectationAgainstSpecificMessageType()
        {
            _soapStub.As <ISolicitResponse>()
            .Setup(s => s.Request(SchemaMetadata.For <btf2_services_header>().DocumentSpec))
            .Returns(new StringStream("<response />"));

            var client = SoapClient <IMessageService> .For(_soapStubHost.Endpoint);

            try
            {
                var response = client.Invoke(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:request",
                        XmlReader.Create(new StringReader(MessageBodyFactory.Create <btf2_services_header>().OuterXml))));

                var reader = response !.GetReaderAtBodyContents();
                reader.MoveToContent();
                var outerXml = reader.ReadOuterXml();
                outerXml.Should().Be("<response />");

                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
예제 #3
0
        public void RelayAsyncMessageThroughXslt()
        {
            _soapStub.As <ITranslatingCalculatorService>()
            .Setup(
                s => s.BeginDivide(
                    It.IsAny <XLangCalculatorRequest>(),
                    It.IsAny <AsyncCallback>(),
                    It.IsAny <object>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));

            ITranslatingCalculatorService client = null;

            try
            {
                client = SoapClient <ITranslatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

                var calculatorResult = Task <XLangCalculatorResponse> .Factory
                                       .FromAsync(client.BeginDivide, client.EndDivide, new XLangCalculatorRequest(CALCULATOR_REQUEST_XML), null)
                                       .Result;

                Assert.That(calculatorResult.RawXmlBody, Is.EqualTo(string.Format(CALCULATOR_RESPONSE_XML, 2)));
                client.Close();
            }
            catch (Exception)
            {
                client?.Abort();
                throw;
            }
        }
예제 #4
0
        public void RelayCompositeMessage()
        {
            const string responseXml = "<CalculatorResponse xmlns=\"urn:services.stateless.be:unit:calculator\">" +
                                       "<s0:Result xmlns:s0=\"urn:services.stateless.be:unit:calculator\">one</s0:Result>" +
                                       "<s0:Result xmlns:s0=\"urn:services.stateless.be:unit:calculator\">two</s0:Result>" +
                                       "</CalculatorResponse>";

            _soapStub.As <ICalculatorService>()
            .Setup(s => s.Add(It.IsAny <XmlCalculatorRequest>()))
            .Returns(new StringStream(responseXml));

            ICalculatorService client = null;

            try
            {
                client = SoapClient <ICalculatorService> .For(_calculatorServiceHost.Endpoint);

                var calculatorResult = client.Add(new(CALCULATOR_REQUEST_XML));
                Assert.That(calculatorResult.RawXmlBody, Is.EqualTo(responseXml));
                client.Close();
            }
            catch (Exception)
            {
                client?.Abort();
                throw;
            }
        }
예제 #5
0
        public void RelayAsyncMessage()
        {
            _soapStub.As <IValidatingCalculatorService>()
            .Setup(
                s => s.BeginMultiply(
                    It.IsAny <XLangCalculatorRequest>(),
                    It.IsAny <AsyncCallback>(),
                    It.IsAny <object>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));

            IValidatingCalculatorService client = null;

            try
            {
                client = SoapClient <IValidatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

                var calculatorResult = Task <XLangCalculatorResponse> .Factory
                                       .FromAsync(client.BeginMultiply, client.EndMultiply, new XLangCalculatorRequest(CALCULATOR_REQUEST_XML), null)
                                       .Result;

                calculatorResult.RawXmlBody.Should().Be(string.Format(CALCULATOR_RESPONSE_XML, 2));
                client.Close();
            }
            catch (Exception)
            {
                client?.Abort();
                throw;
            }
        }
        public void CleanAsyncSucceeds()
        {
            _soapStub.As <ICalculatorStateServiceSync>()
            .Setup(s => s.Clean(It.IsAny <XLangCalculatorRequest>()));

            var client = SoapClient <ICalculatorStateServiceSync> .For(_calculatorServiceHost.Endpoint);

            Action(() => client.Clean(new XLangCalculatorRequest(CALCULATOR_REQUEST_XML))).Should().NotThrow();
            client.Close();
        }
예제 #7
0
        public void ResetSyncSucceeds()
        {
            _soapStub.As <ICalculatorStateService>()
            .Setup(s => s.Reset(It.IsAny <XLangCalculatorRequest>()));

            var client = SoapClient <ICalculatorStateService> .For(_calculatorServiceHost.Endpoint);

            Assert.That(() => client.Reset(new(CALCULATOR_REQUEST_XML)), Throws.Nothing);
            client.Close();
        }
예제 #8
0
        public void RelaySyncInvalidMessageFails()
        {
            var client = SoapClient <IValidatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

            Invoking(() => client.Add(new(INVALID_CALCULATOR_REQUEST_XML)))
            .Should().Throw <FaultException <ExceptionDetail> >()
            .Which.Detail.InnerException.InnerException.Message.Should().Contain(
                "The element 'Arguments' in namespace 'urn:services.stateless.be:unit:calculator' has invalid child element 'Operand' in namespace 'urn:services.stateless.be:unit:calculator'. "
                + "List of possible elements expected: 'Term' in namespace 'urn:services.stateless.be:unit:calculator'");
            client.Close();
        }
        public void RelaySyncInvalidMessageFails()
        {
            var client = SoapClient <IValidatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

            Assert.That(
                () => client.Add(new(INVALID_CALCULATOR_REQUEST_XML)),
                Throws.TypeOf <FaultException <ExceptionDetail> >()
                .With.Property("Detail")
                .With.InnerException.InnerException.Message.Contains(
                    "The element 'Arguments' in namespace 'urn:services.stateless.be:unit:calculator' has invalid child element 'Operand' in namespace 'urn:services.stateless.be:unit:calculator'. "
                    + "List of possible elements expected: 'Term' in namespace 'urn:services.stateless.be:unit:calculator'"));
            client.Close();
        }
        public void ResetSyncFails()
        {
            _soapStub.As <ICalculatorStateServiceSync>()
            .Setup(s => s.Clean(It.IsAny <XLangCalculatorRequest>()))
            .Callback(() => throw new InvalidOperationException("Cannot process this request."));

            var client = SoapClient <ICalculatorStateService> .For(_calculatorServiceHost.Endpoint);

            Action(() => client.Reset(new XLangCalculatorRequest(CALCULATOR_REQUEST_XML)))
            .Should().Throw <FaultException <ExceptionDetail> >()
            .WithMessage("Cannot process this request.");
            client.Abort();
        }
        public void RelaySyncMessageTimesOut()
        {
            _soapStub.As <ICalculatorService>()
            .Setup(s => s.Subtract(It.IsAny <XmlCalculatorRequest>()))
            .Callback(() => Thread.Sleep(3000))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 1)));

            var client = SoapClient <ICalculatorService> .For(_calculatorServiceHost.Endpoint);

            Invoking(() => client.Subtract(new(CALCULATOR_REQUEST_XML)))
            .Should().Throw <FaultException <ExceptionDetail> >()
            .WithMessage("The request channel timed out while waiting for a reply*");
            client.Close();
        }
예제 #12
0
        public void CleanAsyncFails()
        {
            _soapStub.As <ICalculatorStateServiceSync>()
            .Setup(s => s.Clean(It.IsAny <XLangCalculatorRequest>()))
            .Callback(() => throw new InvalidOperationException("Cannot process this request."));

            var client = SoapClient <ICalculatorStateServiceSync> .For(_calculatorServiceHost.Endpoint);

            Assert.That(
                () => client.Clean(new(CALCULATOR_REQUEST_XML)),
                Throws.InstanceOf <FaultException <ExceptionDetail> >()
                .With.InnerException.Message.Contains("Cannot process this request."));
            client.Abort();
        }
예제 #13
0
        public void RelayAsyncInvalidMessageFails()
        {
            var client = SoapClient <IValidatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

            Invoking(
                () => Task <XLangCalculatorResponse> .Factory
                .FromAsync(client.BeginMultiply, client.EndMultiply, new XLangCalculatorRequest(INVALID_CALCULATOR_REQUEST_XML), null)
                .Result)
            .Should().Throw <AggregateException>()
            .WithInnerException <FaultException <ExceptionDetail> >()
            .Which.Detail.InnerException.InnerException.Message.Should().Contain(
                "The element 'Arguments' in namespace 'urn:services.stateless.be:unit:calculator' has invalid child element 'Operand' in namespace 'urn:services.stateless.be:unit:calculator'. "
                + "List of possible elements expected: 'Term' in namespace 'urn:services.stateless.be:unit:calculator'");
            client.Close();
        }
        public void SetupFailureExpectationAgainstMessageType()
        {
            _soapStub.As <ISolicitResponse>()
            .Setup(s => s.Request(SchemaMetadata.For <btf2_services_header>().DocumentSpec))
            .Aborts();

            var client = SoapClient <IMessageService> .For(_soapStubHost.Endpoint);

            Invoking(
                () => client.Invoke(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:request",
                        XmlReader.Create(new StringReader(MessageBodyFactory.Create <btf2_services_header>().OuterXml)))))
            .Should().Throw <CommunicationException>();
            client.Abort();
        }
        public void RelayAsyncMessageTimesOut()
        {
            _soapStub.As <ICalculatorService>()
            .Setup(s => s.BeginDivide(It.IsAny <XmlCalculatorRequest>(), It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Callback(() => Thread.Sleep(3000))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));
            var client = SoapClient <ICalculatorService> .For(_calculatorServiceHost.Endpoint);

            Invoking(
                () => Task <XmlCalculatorResponse> .Factory
                .FromAsync(client.BeginDivide, client.EndDivide, new XmlCalculatorRequest(CALCULATOR_REQUEST_XML), null)
                .Result)
            .Should().Throw <AggregateException>()
            .WithInnerException <FaultException <ExceptionDetail> >()
            .WithMessage("*has exceeded the allotted timeout*");
            client.Close();
        }
        public void SetupFailureExpectationAgainstVoidOperation()
        {
            _soapStub.As <IWork>()
            .Setup(s => s.Execute(It.IsAny <System.ServiceModel.Channels.Message>()))
            .Aborts();

            var client = SoapClient <IWork> .For(_soapStubHost.Endpoint);

            Invoking(
                () => client.Execute(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:execute:request",
                        XmlReader.Create(new StringReader("<request />")))))
            .Should().Throw <CommunicationException>();
            client.Abort();
        }
예제 #17
0
        public void SetupConsecutiveResponseExpectationsAgainstAction()
        {
            _soapStub.As <IWork>()
            .Setup(s => s.Perform(It.IsAny <System.ServiceModel.Channels.Message>()))
            .Callback(
                () => _soapStub.As <IWork>()
                .Setup(s => s.Perform(It.IsAny <System.ServiceModel.Channels.Message>()))
                .Returns(new StringStream("<response2 />"))
                )
            .Returns(new StringStream("<response1 />"));

            var message1 = System.ServiceModel.Channels.Message.CreateMessage(
                MessageVersion.Soap11,
                "urn:services.stateless.be:unit:work:perform:request",
                XmlReader.Create(new StringReader("<request />")));
            var message2 = System.ServiceModel.Channels.Message.CreateMessage(
                MessageVersion.Soap11,
                "urn:services.stateless.be:unit:work:perform:request",
                XmlReader.Create(new StringReader("<request />")));

            var client = SoapClient <IWork> .For(_soapStubHost.Endpoint);

            try
            {
                var result1 = client.Perform(message1);

                var reader1 = result1.GetReaderAtBodyContents();
                reader1.MoveToContent();
                var outerXml1 = reader1.ReadOuterXml();
                outerXml1.Should().Be("<response1 />");

                var result2 = client.Perform(message2);
                var reader2 = result2.GetReaderAtBodyContents();
                reader2.MoveToContent();
                var outerXml2 = reader2.ReadOuterXml();
                outerXml2.Should().Be("<response2 />");

                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
        public void SetupCallbackExpectationAgainstVoidOperation()
        {
            var calledBack = false;

            _soapStub.As <IWork>()
            .Setup(s => s.Execute(It.IsAny <System.ServiceModel.Channels.Message>()))
            .Callback(() => calledBack = true);

            var client = SoapClient <IWork> .For(_soapStubHost.Endpoint);

            Invoking(
                () => client.Execute(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:execute:request",
                        XmlReader.Create(new StringReader("<request />"))))).Should().NotThrow();
            client.Close();
            calledBack.Should().BeTrue();
        }
예제 #19
0
        public void RelaySyncMessage()
        {
            _soapStub.As <IValidatingCalculatorService>()
            .Setup(s => s.Add(It.IsAny <XLangCalculatorRequest>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 3)));

            IValidatingCalculatorService client = null;

            try
            {
                client = SoapClient <IValidatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

                var calculatorResult = client.Add(new(CALCULATOR_REQUEST_XML));
                calculatorResult.RawXmlBody.Should().Be(string.Format(CALCULATOR_RESPONSE_XML, 3));
                client.Close();
            }
            catch (Exception)
            {
                client?.Abort();
                throw;
            }
        }
예제 #20
0
        public void RelaySyncMessageThroughXslt()
        {
            _soapStub.As <ITranslatingCalculatorService>()
            .Setup(s => s.Subtract(It.IsAny <XLangCalculatorRequest>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 3)));

            ITranslatingCalculatorService client = null;

            try
            {
                client = SoapClient <ITranslatingCalculatorService> .For(_calculatorServiceHost.Endpoint);

                var calculatorResult = client.Subtract(new(CALCULATOR_REQUEST_XML));
                Assert.That(calculatorResult.RawXmlBody, Is.EqualTo(string.Format(CALCULATOR_RESPONSE_XML, 3)));
                client.Close();
            }
            catch (Exception)
            {
                client?.Abort();
                throw;
            }
        }