Beispiel #1
0
        public void PublishEventsAsync_WhenDisposed_ThrowObjectDisposedException()
        {
            // Arrange
            var fakeEvents = fixture.CreateMany <FakeEvent1>();

            sut.Dispose();

            // Act
            Action act = () => sut.PublishEventsAsync(fakeEvents).Wait();

            // Assert
            act.Should().Throw <ObjectDisposedException>()
            .WithMessage("Cannot access a disposed object.\r\nObject name: 'topicClients'.");
        }
Beispiel #2
0
        internal void Test_can_publish_events()
        {
            // Arrange
            const string testAddress = "tcp://127.0.0.1:56601";

            var publisher = new EventPublisher(
                this.container,
                new MsgPackEventSerializer(),
                new BypassCompressor(),
                EncryptionSettings.None(),
                new Label("test-publisher"),
                new Port(56601));

            publisher.Start().Wait();

            var subscriber = new SubscriberSocket(testAddress);

            subscriber.Connect(testAddress);
            subscriber.Subscribe("Event:Trade:TESTER-001");

            Task.Delay(100).Wait(); // Allow socket to subscribe

            var serializer = new MsgPackEventSerializer();
            var order      = new StubOrderBuilder().BuildMarketOrder();
            var rejected   = StubEventMessageProvider.OrderRejectedEvent(order);
            var tradeEvent = new TradeEvent(TraderId.FromString("TESTER-001"), rejected);

            // Act
            publisher.Endpoint.Send(tradeEvent);
            this.Output.WriteLine("Waiting for published events...");

            var topic   = subscriber.ReceiveFrameBytes();
            var message = subscriber.ReceiveFrameBytes();
            var @event  = serializer.Deserialize(message);

            // Assert
            Assert.Equal("Event:Trade:TESTER-001", Encoding.UTF8.GetString(topic));
            Assert.Equal(typeof(OrderRejected), @event.GetType());

            // Tear Down
            subscriber.Disconnect(testAddress);
            subscriber.Dispose();
            publisher.Stop().Wait();
            publisher.Dispose();
        }