Exemplo n.º 1
0
        public void Start_FirstMessageOnQueueDoesNotMeetExpectations_DropsUninterestingMessageAndMovesOn()
        {
            // Arrange
            MsmqHelpers.Purge("orderservice");
            MsmqHelpers.Purge("shippingservice");

            UnicastBus  bus     = InternalBusCreator.CreateBus();
            var         stuffer = new MessageStuffer(bus);
            ServiceStub service = Configure.Stub().NServiceBusSerializers().Create(@".\Private$\orderservice");

            service.Setup()
            .Expect <IPlaceAnOrder>(msg => msg.Product == "stockings")
            .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice");

            stuffer.PutMessageOnQueue <IPlaceAnOrder>(msg => { msg.Product = "somethingelse"; }, @"orderservice");
            stuffer.PutMessageOnQueue <IPlaceAnOrder>(msg => { msg.Product = "stockings"; }, @"orderservice");

            // Act
            service.Start();
            while (MsmqHelpers.GetMessageCount("shippingservice") == 0)
            {
            }
            StopService(service);


            // Assert
            Assert.That(MsmqHelpers.GetMessageCount("orderservice"), Is.EqualTo(0), "meesage which did not meet the expectations was left behind");
            Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1), "shipping service did not recieve send");
        }
Exemplo n.º 2
0
        public void Start_ExpectationsAreMet_SendsMessages()
        {
            // Arrange
            MsmqHelpers.Purge("orderservice");
            MsmqHelpers.Purge("shippingservice");
            MsmqHelpers.Purge("testclient");

            UnicastBus  bus     = InternalBusCreator.CreateBus();
            var         stuffer = new MessageStuffer(bus);
            ServiceStub service = Configure.Stub().NServiceBusSerializers().Create(@".\Private$\orderservice");

            service.Setup()
            .Expect <IPlaceAnOrder>(msg => msg.Product == "stockings")
            .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice")
            .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "testclient");

            stuffer.PutMessageOnQueue <IPlaceAnOrder>(msg => { msg.Product = "stockings"; }, @"orderservice");

            // Act
            service.Start();

            while (MsmqHelpers.GetMessageCount("shippingservice") == 0)
            {
            }
            StopService(service);

            // Assert
            Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1));
            Assert.That(MsmqHelpers.GetMessageCount("testclient"), Is.EqualTo(1));
        }
Exemplo n.º 3
0
        public void Pick_NoMessageOnQueue_ReturnsNull()
        {
            // Arrange
            var bus    = InternalBusCreator.CreateBus();
            var picker = new MessagePicker(bus);

            // Act
            object[] nextMessage = picker.PickMessage(@".\Private$\orderservice");

            // Assert
            Assert.That(nextMessage, Is.Null);
        }
Exemplo n.º 4
0
        public void Pick_MessageOnQueue_MessageIsDeserialized()
        {
            // Arrange
            object[] message;

            var bus = InternalBusCreator.CreateBus();

            var picker  = new MessagePicker(bus);
            var stuffer = new MessageStuffer(bus);

            stuffer.PutMessageOnQueue <IPlaceAnOrder>(msg => { msg.Product = "a"; }, "orderservice");

            // Act
            message = picker.PickMessage(@".\Private$\orderservice");

            // Assert
            Assert.That(message.Length, Is.EqualTo(1));
        }