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

            var messagePackOptions = new MessagePackHubProtocolOptions();

            var jsonOptions = new JsonHubProtocolOptions();

            jsonOptions.PayloadSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            var backplane1Harness = RegisterBusEndpoint("receiveEndpoint1");
            var 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())
                    {
                        var manager1 = backplane1Harness.HubLifetimeManager;
                        var manager2 = backplane2Harness.HubLifetimeManager;

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

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

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

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

                        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();
            }
        }
예제 #2
0
        public async Task Send_command_to_parse_valid_cif_should_publish_one_RecordParsed_and_one_FileParsed_event([Frozen] FileParsedEvent expectedEvent)
        {
            try
            {
                await _harness.Start();

                var blobId = await _blobStorage.AddFileAsync("1100110.cif", Resource._1100110, "chemical/x-cif", BUCKET);

                await _harness.InputQueueSendEndpoint.Send <ParseFile>(new
                {
                    expectedEvent.Id,
                    Bucket = BUCKET,
                    BlobId = blobId,
                    expectedEvent.CorrelationId,
                    expectedEvent.UserId
                });

                _consumer.Consumed.Select <ParseFile>().Any();
                _harness.Published.Select <FileParsed>().Any();

                var allEvents = _harness.Published.ToList();

                var parsed = allEvents.Select <RecordParsed>().FirstOrDefault();
                parsed.Should().NotBeNull();
                parsed.ShouldBeEquivalentTo(new
                {
                    FileId = expectedEvent.Id,
                    Bucket = BUCKET,
                    Index  = 0L,
                    expectedEvent.UserId
                },
                                            options => options.ExcludingMissingMembers()
                                            );
                parsed.Fields.Count().Should().Be(22);
            }
            finally
            {
                await _harness.Stop();
            }
        }
예제 #3
0
        public async Task Send_command_to_parse_valid_rdf_should_publish_75_RecordParsed_one_FileParsed_event([Frozen] FileParsedEvent expectedEvent)
        {
            try
            {
                await _harness.Start();

                var blobId = await _blobStorage.AddFileAsync("ccr0401.rdf", Resource.ccr0401, "chemical/x-mdl-rdfile", BUCKET);

                await _harness.InputQueueSendEndpoint.Send <ParseFile>(new
                {
                    expectedEvent.Id,
                    Bucket = BUCKET,
                    BlobId = blobId,
                    expectedEvent.CorrelationId,
                    expectedEvent.UserId
                });

                var res = _consumer.Consumed.Select <ParseFile>().Any();
                res.Should().BeTrue();

                var allEvents = _harness.Published.ToList();

                allEvents.Where(e => e.MessageType == typeof(RecordParsed)).Count().Should().Be(75);

                var parsed = allEvents.Select <FileParsed>().FirstOrDefault();
                parsed.Should().NotBeNull();
                parsed.Should().BeEquivalentTo(expectedEvent,
                                               options => options
                                               .Excluding(p => p.TimeStamp)
                                               .Excluding(p => p.Fields)
                                               .Excluding(p => p.TotalRecords)
                                               );
                parsed.TotalRecords.Should().Be(75);
                parsed.Fields.Count().Should().Be(6);
            }
            finally
            {
                await _harness.Stop();
            }
        }
예제 #4
0
 public void Dispose()
 {
     _harness.Stop().Wait();
 }
예제 #5
0
        public virtual void Dispose()
        {
            _harness.Stop().Wait();

            MongoDb.Client.DropDatabase(MongoDatabaseName);
        }
예제 #6
0
        async Task StopTestHarness()
        {
            using var source = new CancellationTokenSource(TimeSpan.FromSeconds(30));

            await Harness.Stop();
        }