예제 #1
0
        public async Task CamelCasedJsonIsPreservedAcrossMassTransitBoundary()
        {
            Harness = new InMemoryTestHarness();

            var messagePackOptions = new MessagePackHubProtocolOptions();

            var jsonOptions = new JsonHubProtocolOptions();

            jsonOptions.PayloadSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            SignalRBackplaneConsumersTestHarness <MyHub> backplane1Harness = RegisterBusEndpoint("receiveEndpoint1");
            SignalRBackplaneConsumersTestHarness <MyHub> backplane2Harness = RegisterBusEndpoint("receiveEndpoint2");

            await Harness.Start();

            try
            {
                backplane1Harness.SetHubLifetimeManager(CreateLifetimeManager(messagePackOptions, jsonOptions));
                backplane2Harness.SetHubLifetimeManager(CreateLifetimeManager());
                using (var client1 = new TestClient())
                    using (var client2 = new TestClient())
                    {
                        MassTransitHubLifetimeManager <MyHub> manager1 = backplane1Harness.HubLifetimeManager;
                        MassTransitHubLifetimeManager <MyHub> manager2 = backplane2Harness.HubLifetimeManager;

                        var connection1 = HubConnectionContextUtils.Create(client1.Connection);
                        var connection2 = HubConnectionContextUtils.Create(client2.Connection);

                        await manager1.OnConnectedAsync(connection1).OrTimeout(Harness.TestTimeout);

                        await manager2.OnConnectedAsync(connection2).OrTimeout(Harness.TestTimeout);

                        await manager1.SendAllAsync("Hello", new object[] { new TestObject {
                                                                                TestProperty = "Foo"
                                                                            } }).OrTimeout(Harness.TestTimeout);

                        Assert.IsTrue(backplane2Harness.All.Consumed.Select <All <MyHub> >().Any());

                        var message = await client2.ReadAsync().OrTimeout() as InvocationMessage;

                        Assert.NotNull(message);
                        Assert.AreEqual("Hello", message.Target);
                        CollectionAssert.AllItemsAreInstancesOfType(message.Arguments, typeof(JObject));
                        var jObject = message.Arguments[0] as JObject;
                        Assert.NotNull(jObject);
                        var firstProperty = jObject.Properties().First();
                        Assert.AreEqual("testProperty", firstProperty.Name);
                        Assert.AreEqual("Foo", firstProperty.Value.Value <string>());
                    }
            }
            finally
            {
                await Harness.Stop();
            }
        }
        protected SignalRBackplaneConsumersTestHarness <THub> RegisterBusEndpoint(string queueName = "receiveEndpoint")
        {
            var consumersTestHarness = new SignalRBackplaneConsumersTestHarness <THub>(Harness, queueName);

            consumersTestHarness.AddAllConsumer(new HubLifetimeManagerConsumerFactory <AllConsumer <THub>, THub>(hubMgr => new AllConsumer <THub>(hubMgr)));
            consumersTestHarness.AddConnectionConsumer(new HubLifetimeManagerConsumerFactory <ConnectionConsumer <THub>, THub>(hubMgr => new ConnectionConsumer <THub>(hubMgr)));
            consumersTestHarness.AddGroupConsumer(new HubLifetimeManagerConsumerFactory <GroupConsumer <THub>, THub>(hubMgr => new GroupConsumer <THub>(hubMgr)));
            consumersTestHarness.AddGroupManagementConsumer(new HubLifetimeManagerConsumerFactory <GroupManagementConsumer <THub>, THub>(hubMgr => new GroupManagementConsumer <THub>(hubMgr)));
            consumersTestHarness.AddUserConsumer(new HubLifetimeManagerConsumerFactory <UserConsumer <THub>, THub>(hubMgr => new UserConsumer <THub>(hubMgr)));

            return(consumersTestHarness);
        }
예제 #3
0
        public async Task Setup()
        {
            Harness = new InMemoryTestHarness();

            Backplane1Harness = RegisterBusEndpoint("receiveEndpoint1");
            Backplane2Harness = RegisterBusEndpoint("receiveEndpoint2");

            await Harness.Start();

            // Need the bus to be started before we can set the manager for our Consumer Factory (so it can be injected into the consumers on creation);
            Backplane1Harness.SetHubLifetimeManager(CreateLifetimeManager());
            Backplane2Harness.SetHubLifetimeManager(CreateLifetimeManager());
        }
        public async Task Setup()
        {
            Harness = new InMemoryTestHarness();

            BackplaneHarness = RegisterBusEndpoint();

            await Harness.Start();

            // Need the bus to be started before we can set the manager for our Consumer Factory (so it can be injected into the consumers on creation);
            MassTransitHubLifetimeManager <THub> hubLifetimeManager = CreateLifetimeManager();

            BackplaneHarness.SetHubLifetimeManager(hubLifetimeManager);
        }