public void SetupCallbackExpectationAgainstVoidOperation()
        {
            var calledBack = false;

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

            var client = StubServiceClient <IWork> .Create();

            try
            {
                client.Execute(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:execute:request",
                        XmlReader.Create(new StringReader("<request />"))));
                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
            Assert.That(calledBack, Is.True);
        }
        public void SetupResponseExpectationAgainstSpecificMessageType()
        {
            StubServiceHost.DefaultService
            .Setup(s => s.Request(new SchemaMetadata <btf2_services_header>().DocumentSpec))
            .Returns(new StringStream("<response />"));

            var client = StubServiceClient.Create();

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

                // ReSharper disable PossibleNullReferenceException
                var reader = response.GetReaderAtBodyContents();
                // ReSharper restore PossibleNullReferenceException
                reader.MoveToContent();
                var outerXml = reader.ReadOuterXml();
                Assert.That(outerXml, Is.EqualTo("<response />"));

                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
        public void SetupResponseExpectationAgainstAction()
        {
            StubServiceHost.FindDefaultService <IWork>()
            .Setup(s => s.Perform(It.IsAny <System.ServiceModel.Channels.Message>()))
            .Returns(new StringStream("<response />"));

            var client = StubServiceClient <IWork> .Create();

            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();
                Assert.That(outerXml, Is.EqualTo("<response />"));

                client.Close();
            }
            catch (Exception)
            {
                client.Abort();
                throw;
            }
        }
        public void SetupFailureExpectationAgainstVoidOperation()
        {
            StubServiceHost.FindDefaultService <IWork>()
            .Setup(s => s.Execute(It.IsAny <System.ServiceModel.Channels.Message>()))
            .Aborts();

            var client = StubServiceClient <IWork> .Create();

            Assert.That(
                () => client.Execute(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:execute:request",
                        XmlReader.Create(new StringReader("<request />")))),
                Throws.TypeOf <CommunicationException>());
            client.Abort();
        }
        public void SetupFailureExpectationAgainstMessageType()
        {
            StubServiceHost.DefaultService
            .Setup(s => s.Request(new SchemaMetadata <btf2_services_header>().DocumentSpec))
            .Aborts();

            var client = StubServiceClient.Create();

            Assert.That(
                () => client.Request(
                    System.ServiceModel.Channels.Message.CreateMessage(
                        MessageVersion.Soap11,
                        "urn:services.stateless.be:unit:work:request",
                        XmlReader.Create(new StringReader(MessageFactory.CreateMessage <btf2_services_header>().OuterXml)))),
                Throws.TypeOf <CommunicationException>());
            client.Abort();
        }
示例#6
0
 public static IRequestChannel Create()
 {
     return(StubServiceClient <IRequestChannel> .Create());
 }