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_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 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 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 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 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"); }