コード例 #1
0
        public void RelayAsyncMessage()
        {
            _soapStub.As <ICalculatorService>()
            .Setup(s => s.BeginMultiply(It.IsAny <XmlCalculatorRequest>(), It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));

            ICalculatorService client = null;

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

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

                Assert.That(calculatorResult.RawXmlBody, Is.EqualTo(string.Format(CALCULATOR_RESPONSE_XML, 2)));
                client.Close();
            }
            catch (Exception)
            {
                client?.Abort();
                throw;
            }
        }
コード例 #2
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;
            }
        }
コード例 #3
0
        public void RelayAsyncMessage()
        {
            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.BeginMultiply(It.IsAny <XmlCalculatorRequest>(), It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 2)));

            ICalculatorService client = null;

            try
            {
                client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

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

                Assert.AreEqual(string.Format(CALCULATOR_RESPONSE_XML, 2), calculatorResult.RawXmlBody);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
コード例 #4
0
        public void RelaySyncMessage()
        {
            StubServiceHost.FindDefaultService <ICalculatorService>()
            .Setup(s => s.Add(It.IsAny <XmlCalculatorRequest>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 3)));

            ICalculatorService client = null;

            try
            {
                client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

                var calculatorResult = client.Add(new XmlCalculatorRequest(CALCULATOR_REQUEST_XML));
                Assert.AreEqual(string.Format(CALCULATOR_RESPONSE_XML, 3), calculatorResult.RawXmlBody);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
コード例 #5
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>";

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

            ICalculatorService client = null;

            try
            {
                client = SimpleServiceClient <CalculatorService, ICalculatorService> .Create();

                var calculatorResult = client.Add(new XmlCalculatorRequest(CALCULATOR_REQUEST_XML));
                Assert.AreEqual(responseXml, calculatorResult.RawXmlBody);
                client.Close();
            }
            catch (Exception)
            {
                if (client != null)
                {
                    client.Abort();
                }
                throw;
            }
        }
コード例 #6
0
        public void RelaySyncMessage()
        {
            _soapStub.As <ICalculatorService>()
            .Setup(s => s.Add(It.IsAny <XmlCalculatorRequest>()))
            .Returns(new StringStream(string.Format(CALCULATOR_RESPONSE_XML, 3)));

            ICalculatorService client = null;

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

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