Exemplo n.º 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));
        }
        public void SimpleExpectationSetUp_BindingInputWithMultipleParametersToReturnValue_InvocationValuesAreAccessibleWhenStubbingMessage()
        {
            MsmqHelpers.Purge("shippingservice");
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

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

            proxy.Setup(s => s.IHaveMultipleInputParameters(Parameter.Any <string>(), Parameter.Equals <string>(str => str == "snappy"), Parameter.Any <bool>())).Returns <string, string, bool>((param1, param2, param3) => param1)
            .Send <IOrderWasPlaced, string>((msg, product) => { msg.OrderedProduct = product; }, "shippingservice");

            service.Start();

            string firstRequestReturnValue;

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

                firstRequestReturnValue = channel.IHaveMultipleInputParameters("hello", "snappy", false);
            }

            service.Dispose();

            Assert.That(MsmqHelpers.PickMessageBody("shippingservice"), Is.StringContaining("hello"));
            Assert.That(firstRequestReturnValue, Is.EqualTo("hello"));
        }
        public void VoidServiceMethod_InvokeAndSend_MessageIsSent()
        {
            MsmqHelpers.Purge("shippingservice");
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

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

            proxy.Setup(s => s.AVoidServiceMethod()).Send <IOrderWasPlaced>(msg => { msg.OrderedProduct = "abbazz"; }, "shippingservice");

            service.Start();

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

                channel.AVoidServiceMethod();
            }

            service.Dispose();

            Assert.That(MsmqHelpers.PickMessageBody("shippingservice"), Contains.Substring("abbazz"));
        }
Exemplo n.º 4
0
        public void Get_SimpleExpectationSetUpInHeader_HeaderParameterPassedDownTheInheritanceChain()
        {
            MsmqHelpers.Purge("shippingservice");

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

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

            IRouteTemplate <bool> get = restEndpoint.AddGet <bool>("/list");

            restEndpoint.Configure(get).With(Parameter.HeaderParameter <DateTime>("Today").Equals(dt => dt.Day == 3)).Returns(true)
            .Send <IOrderWasPlaced, DateTime>((msg, today) => msg.OrderedProduct = today.ToString(), "shippingservice");

            service.Start();

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

            client.DefaultRequestHeaders.Add("Today", new DateTime(2000, 1, 3).ToString());

            Task <string> getAsync = client.GetStringAsync("list");

            string result = WaitVerifyNoExceptionsAndGetResult(getAsync);

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

            do
            {
                Thread.Sleep(100);
            } while (MsmqHelpers.GetMessageCount("shippingservice") == 0);

            Assert.That(result, Is.EqualTo("true"));
            Assert.That(MsmqHelpers.PickMessageBody("shippingservice"), Is.StringContaining(new DateTime(2000, 1, 3).ToString()), "shipping service recieved events");
        }