コード例 #1
0
        public void Post_PostWitBody_BodyIsPassedDownTheChain()
        {
            MsmqHelpers.Purge("shippingservice");

            ServiceStub service = Configure.Stub().NServiceBusSerializers().Restful().Create(@".\Private$\orderservice");

            const string BaseUrl = "http://localhost:9101/";
            RestApi      api     = service.RestEndpoint(BaseUrl);

            IRouteTemplate post = api.AddPost("/order");

            api.Configure(post).With(Body.AsDynamic().IsEqualTo(body => body.orderId == 1))
            .Send <IOrderWasPlaced, dynamic>((msg, body) =>
            {
                msg.OrderNumber = body.orderId;
            }, "shippingservice");

            service.Start();

            var client = new HttpClient {
                BaseAddress = new Uri(BaseUrl)
            };

            Task <HttpResponseMessage> postAsync = client.PostAsync("/order", new StringContent("{\"orderId\":\"1\"}", Encoding.UTF8, "application/json"));

            HttpResponseMessage message = WaitVerifyNoExceptionsAndGetResult(postAsync);

            MsmqHelpers.WaitForMessages("shippingservice");

            client.Dispose();
            service.Dispose();

            Assert.That(MsmqHelpers.PickMessageBody("shippingservice"), Is.StringContaining("1"));
            Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        }
コード例 #2
0
        public void SimpleExpectationSetUp_UsingServiceKnownType2_HandledAndMessageIsSentToQueue()
        {
            MsmqHelpers.Purge("shippingservice");

            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

            var proxy = service.WcfEndPoint <IOrderService>("http://localhost:9101/orderservice");

            proxy.Setup(s => s.ExecuteCommand(Parameter.Equals <DeleteOrder>(command => command.OrderNumber == 1)))
            .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice");

            service.Start();

            using (var factory = new ChannelFactory <IOrderService>(new BasicHttpBinding(), "http://localhost:9101/orderservice"))
            {
                IOrderService channel = factory.CreateChannel();

                channel.ExecuteCommand(new DoSomethingWithOrder());
                channel.ExecuteCommand(new DeleteOrder());
                channel.ExecuteCommand(new DeleteOrder {
                    OrderNumber = 1
                });
            }

            MsmqHelpers.WaitForMessages("shippingservice");

            service.Dispose();

            Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1), "shipping service did not recieve send");
        }