public void Get_SimpleExpectationSetUpInHeader_HeaderParameterUsableInReturnStatement() { MsmqHelpers.Purge("shippingservice"); ServiceStub service = Configure.Stub().NServiceBusSerializers().Restful().Create(@".\Private$\orderservice"); const string BaseUrl = "http://localhost:9101/"; RestApi restEndpoint = service.RestEndpoint(BaseUrl); IRouteTemplate <SomeTupleReturnValue> get = restEndpoint.AddGet <SomeTupleReturnValue>("/list/{id}"); restEndpoint.Configure(get).With(Parameter.HeaderParameter <DateTime>("Today").Equals(dt => dt.Day == 3).And(Parameter.RouteParameter <int>("id").Any())).Returns <DateTime, int>((today, id) => new SomeTupleReturnValue { One = today, Two = id }); 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/1"); string result = WaitVerifyNoExceptionsAndGetResult(getAsync); client.Dispose(); service.Dispose(); Assert.That(result, Is.EqualTo("{\"One\":\"2000-01-03T00:00:00\",\"Two\":1}")); }
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 Get_SimpleExpectationSetUpInHeaderHeaderVariableIsMissing_ReturnsDefaultValue() { 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>(msg => msg.OrderedProduct = "stockings", "shippingservice"); service.Start(); var client = new HttpClient { BaseAddress = new Uri(BaseUrl) }; Task <string> getAsync = client.GetStringAsync("list"); string result = WaitVerifyNoExceptionsAndGetResult(getAsync); client.Dispose(); service.Dispose(); Assert.That(result, Is.EqualTo("null")); Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(0), "shipping service recieved events"); }
public void Post_JustASimplePostWithNoBody_MessagesAreSent() { // Arrange 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/{id}/shares"); api.Configure(post).With(Parameter.RouteParameter <int>("id").Equals(1)).Send <IOrderWasPlaced>(msg => { msg.OrderNumber = 1; }, "shippingservice"); service.Start(); var client = new HttpClient { BaseAddress = new Uri(BaseUrl) }; Task <HttpResponseMessage> postAsync = client.PostAsync("/order/1/shares", new StringContent("")); HttpResponseMessage message = WaitVerifyNoExceptionsAndGetResult(postAsync); client.Dispose(); service.Dispose(); do { Thread.Sleep(100); } while (MsmqHelpers.GetMessageCount("shippingservice") == 0); Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1)); }
public void Post_PostWitBodyAndRouteParameters_BodyAndParametersFromRequestAreBound() { // Arrange 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/{id}"); api.Configure(post).With(Body.AsDynamic().IsEqualTo(body => body.orderId == 1).And(Parameter.RouteParameter <int>("id").Equals(2))).Returns(3); service.Start(); var client = new HttpClient { BaseAddress = new Uri(BaseUrl) }; Task <HttpResponseMessage> postAsync = client.PostAsync("/order/2", new StringContent("{\"orderId\":\"1\"}", Encoding.UTF8, "application/json")); HttpResponseMessage message = WaitVerifyNoExceptionsAndGetResult(postAsync); Task <string> readAsStringAsync = message.Content.ReadAsStringAsync(); readAsStringAsync.Wait(); client.Dispose(); service.Dispose(); Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(readAsStringAsync.Result, Is.EqualTo("3")); }
public void Get_InvokingEndpointAndExpectationMet_MessageIsSentToQueue() { 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.Any()).Returns(true) .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice"); service.Start(); var client = new HttpClient { BaseAddress = new Uri(BaseUrl) }; Task <string> getAsync = client.GetStringAsync("list"); string result = WaitVerifyNoExceptionsAndGetResult(getAsync); do { Thread.Sleep(100); } while (MsmqHelpers.GetMessageCount("shippingservice") == 0); client.Dispose(); service.Dispose(); Assert.That(result, Is.EqualTo("true")); Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1), "shipping service did not recieve send"); }
public void Post_DoesNotMatchSetup_DoesNotSendMessages() { // Arrange 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/{id}/shares"); api.Configure(post).With(Parameter.RouteParameter <int>("id").Equals(1)).Send <IOrderWasPlaced>(msg => { msg.OrderNumber = 1; }, "shippingservice"); service.Start(); var client = new HttpClient { BaseAddress = new Uri(BaseUrl) }; Task <HttpResponseMessage> postAsync = client.PostAsync("/order/2/shares", new StringContent("")); WaitVerifyNoExceptions(postAsync); client.Dispose(); service.Dispose(); Thread.Sleep(2000); Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(0), "shipping service recieved events"); }
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 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"); }
public void SimpleExpectationSetUp_InvokingWebServiceTwiceAndExpectationMetOnce_MessageIsSentToQueue() { 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.PlaceOrder(Parameter.Equals <string>(str => str == "dope"))).Returns(() => true) .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice"); service.Start(); bool firstRequestReturnValue; bool secondRequestReturnValue; using (var factory = new ChannelFactory <IOrderService>(new BasicHttpBinding(), "http://localhost:9101/orderservice")) { IOrderService channel = factory.CreateChannel(); firstRequestReturnValue = channel.PlaceOrder("dope"); secondRequestReturnValue = channel.PlaceOrder("bar"); } do { Thread.Sleep(100); } while (MsmqHelpers.GetMessageCount("shippingservice") == 0); service.Dispose(); Assert.That(firstRequestReturnValue, Is.True); Assert.That(secondRequestReturnValue, Is.False); Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1), "shipping service did not recieve send"); }
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")); }
public void Fallback_IAlreadyHaveAServiceImplementation_CallingImplementation() { MsmqHelpers.Purge("shippingservice"); var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice"); var existingImpl = new Mock <ISomeService>(); service.WcfEndPoint("http://localhost:9101/boo", existingImpl.Object); service.Start(); using (var factory = new ChannelFactory <ISomeService>(new BasicHttpBinding(), "http://localhost:9101/boo")) { ISomeService channel = factory.CreateChannel(); channel.AVoidServiceMethod(); } service.Dispose(); existingImpl.Verify(m => m.AVoidServiceMethod()); }
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"); }
public void SimpleExpectationSetUp_UsingServiceKnownTypeAndInvokedWithWrongSignature_DoesNotHandleMessage() { 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.Any <DeleteOrder>())) .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()); } service.Dispose(); Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(0), "shipping service recieved message"); }